Skip to content

Instantly share code, notes, and snippets.

@robertmaynard
Created December 14, 2017 14:50
Show Gist options
  • Save robertmaynard/b4c1edaf9c8896fea877ff571e899f80 to your computer and use it in GitHub Desktop.
Save robertmaynard/b4c1edaf9c8896fea877ff571e899f80 to your computer and use it in GitHub Desktop.
CMake switch impl on fpic
add_library(I INTERFACE)
add_library(IA STATIC impl1.cpp)
set_target_properties(IA PROPERTIES POSITION_INDEPENDENT_CODE ON)
add_library(IB STATIC impl2.cpp)
set(has_iface "$<BOOL:$<TARGET_PROPERTY:POSITION_INDEPENDENT_CODE>>")
target_link_libraries(I
INTERFACE
$<${has_iface}:IA>
$<$<NOT:${has_iface}>:IB>
)
add_executable(Foo foo.cpp)
target_link_libraries(Foo PUBLIC I) #links to IB
add_library(Bar SHARED bar.cpp)
target_link_libraries(Bar PUBLIC I) #links to IA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment