diff --git a/cmake/AddJanaPlugin.cmake b/cmake/AddJanaPlugin.cmake index 36705f38d..c9fd51246 100644 --- a/cmake/AddJanaPlugin.cmake +++ b/cmake/AddJanaPlugin.cmake @@ -2,16 +2,16 @@ macro(add_jana_plugin plugin_name) # Parse remaining arguments - set(options LINK_SHARED) + set(options LINK_STATIC) set(oneValueArgs EXPORT) set(multiValueArgs SOURCES PUBLIC_HEADER TESTS) cmake_parse_arguments(PLUGIN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - if (LINK_SHARED) - set(PLUGIN_JANA_LIB jana2_shared_lib) - else() + if (LINK_STATIC) set(PLUGIN_JANA_LIB jana2_static_lib) + else() + set(PLUGIN_JANA_LIB jana2_shared_lib) endif() if (NOT PLUGIN_SOURCES AND NOT PLUGIN_PUBLIC_HEADER AND NOT PLUGIN_TESTS) diff --git a/cmake/AddJanaTest.cmake b/cmake/AddJanaTest.cmake index 633ec0b3e..bb7f43315 100644 --- a/cmake/AddJanaTest.cmake +++ b/cmake/AddJanaTest.cmake @@ -1,7 +1,8 @@ macro(add_jana_test test_target_name) - cmake_parse_arguments(JANATEST "" "" "SOURCES" ${ARGN}) + set(options LINK_STATIC) + cmake_parse_arguments(JANATEST "LINK_STATIC" "" "SOURCES" ${ARGN}) if (NOT JANATEST_SOURCES) file(GLOB JANATEST_SOURCES "*.c*") @@ -10,7 +11,21 @@ macro(add_jana_test test_target_name) # Set up target add_executable(${test_target_name} ${JANATEST_SOURCES}) - target_link_libraries(${test_target_name} PRIVATE jana2_static_lib VendoredCatch2) + if (${PROJECT_NAME} STREQUAL "jana2") + # This is an internal plugin + set(JANA_NAMESPACE "") + else() + # This is an external plugin + set(JANA_NAMESPACE "JANA::") + endif() + + if (LINK_STATIC) + set(PLUGIN_JANA_LIB jana2_static_lib) + else() + set(PLUGIN_JANA_LIB jana2_shared_lib) + endif() + + target_link_libraries(${test_target_name} PRIVATE "${JANA_NAMESPACE}${PLUGIN_JANA_LIB}" VendoredCatch2) set_target_properties(${test_target_name} PROPERTIES SKIP_BUILD_RPATH FALSE diff --git a/src/libraries/JANA/CMakeLists.txt b/src/libraries/JANA/CMakeLists.txt index e5ab86d7e..adeac3896 100644 --- a/src/libraries/JANA/CMakeLists.txt +++ b/src/libraries/JANA/CMakeLists.txt @@ -79,7 +79,7 @@ elseif (${USE_ROOT}) endif() -# static library, always there +# Build static library add_library(jana2_static_lib STATIC $ $) set_target_properties(jana2_static_lib PROPERTIES PREFIX "lib" OUTPUT_NAME "JANA") @@ -94,28 +94,24 @@ elseif (${USE_ROOT}) endif() install(TARGETS jana2_static_lib EXPORT jana2_targets DESTINATION lib) -# optionally build shared lib -if (BUILD_SHARED_LIBS) - message(STATUS "Building both shared and static libraries") - add_library(jana2_shared_lib SHARED $ $) - set_target_properties(jana2_shared_lib PROPERTIES PREFIX "lib" OUTPUT_NAME "JANA") - - target_include_directories(jana2_shared_lib PUBLIC $) - target_link_libraries(jana2_shared_lib PUBLIC ${CMAKE_DL_LIBS} Threads::Threads) - target_link_libraries(jana2_shared_lib PUBLIC VendoredTomlPlusPlus) - - if (${USE_PODIO}) - target_link_libraries(jana2_shared_lib PUBLIC podio::podio podio::podioRootIO ${ROOT_LIBRARIES}) - elseif (${USE_ROOT}) - target_link_libraries(jana2_shared_lib PUBLIC ${ROOT_LIBRARIES}) - endif() - - install(TARGETS jana2_shared_lib EXPORT jana2_targets DESTINATION lib) - set(INSTALL_RPATH_USE_LINK_PATH True) -else() - message(STATUS "Building static library only") + +# Build shared library +add_library(jana2_shared_lib SHARED $ $) +set_target_properties(jana2_shared_lib PROPERTIES PREFIX "lib" OUTPUT_NAME "JANA") + +target_include_directories(jana2_shared_lib PUBLIC $) +target_link_libraries(jana2_shared_lib PUBLIC ${CMAKE_DL_LIBS} Threads::Threads) +target_link_libraries(jana2_shared_lib PUBLIC VendoredTomlPlusPlus) + +if (${USE_PODIO}) + target_link_libraries(jana2_shared_lib PUBLIC podio::podio podio::podioRootIO ${ROOT_LIBRARIES}) +elseif (${USE_ROOT}) + target_link_libraries(jana2_shared_lib PUBLIC ${ROOT_LIBRARIES}) endif() +install(TARGETS jana2_shared_lib EXPORT jana2_targets DESTINATION lib) +set(INSTALL_RPATH_USE_LINK_PATH True) + # Install "public" header files diff --git a/src/programs/jana/CMakeLists.txt b/src/programs/jana/CMakeLists.txt index 312316e88..9ed2f11ff 100644 --- a/src/programs/jana/CMakeLists.txt +++ b/src/programs/jana/CMakeLists.txt @@ -3,7 +3,7 @@ add_executable(jana jana.cc ) find_package(Threads REQUIRED) -target_link_libraries(jana jana2_static_lib Threads::Threads) +target_link_libraries(jana jana2_shared_lib) target_link_options(jana PRIVATE -rdynamic) install(TARGETS jana DESTINATION bin)