[CMake] missing -rpath-link flag

Stephen Kelly steveire at gmail.com
Thu Jan 2 18:09:20 EST 2014


Clinton Stimpson wrote:

> I have an example (attached) 

The example becomes more readable and easier to reason about by applying 
this patch:

  diff --git a/CMakeLists.txt b/CMakeLists.txt
  index 89a415d..15bfb46 100644
  --- a/CMakeLists.txt
  +++ b/CMakeLists.txt
  @@ -1,7 +1,5 @@
  cmake_minimum_required(VERSION 2.8)
  
  -cmake_policy(SET CMP0022 OLD)
  -
  set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined -Wl,--as-needed")
  set(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
  
  @@ -10,19 +8,15 @@ set_target_properties(shareda PROPERTIES 
LIBRARY_OUTPUT_DIRECTORY "subdir")
  
  add_library(sharedb SHARED sharedb.cpp)
  set_target_properties(sharedb PROPERTIES LIBRARY_OUTPUT_DIRECTORY 
"subdir")
  -target_link_libraries(sharedb shareda)
  -set_target_properties(sharedb PROPERTIES LINK_INTERFACE_LIBRARIES "")
  +target_link_libraries(sharedb PUBLIC shareda)
  set_target_properties(sharedb PROPERTIES BUILD_WITH_INSTALL_RPATH 1 
INSTALL_RPATH "")
  
  add_library(static STATIC static.cpp)
  -target_link_libraries(static sharedb)
  +target_link_libraries(static PUBLIC sharedb)
  set_target_properties(static PROPERTIES COMPILE_FLAGS "-fPIC")
  
  add_library(shared2 SHARED shared2.cpp)
  -target_link_libraries(shared2 static)
  -set_target_properties(shared2 PROPERTIES LINK_INTERFACE_LIBRARIES "")
  +target_link_libraries(shared2 PRIVATE static)
  
  add_executable(exe exe.cpp)
  target_link_libraries(exe shared2)
  -
  -


Thanks,

Steve.




More information about the CMake mailing list