Skip to content

Commit

Permalink
Introduce interface target jana2_abstract_lib
Browse files Browse the repository at this point in the history
This lets us export targets without forcing us to install a pile of .o files
  • Loading branch information
nathanwbrei committed Aug 6, 2024
1 parent e7bb1bd commit 0c2953b
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions src/libraries/JANA/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,54 @@ find_package(Threads REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG ON)


# First we set up the object library (which is just a pile of .o files)
# All include directories and link libraries are inherited from here
add_library(jana2 OBJECT ${JANA2_SOURCES})
target_include_directories(jana2 PUBLIC
# Set up an "abstract library" to capture all the common include directories, link libraries, etc,
# so that they can be inherited by all the targets that link to them
add_library(jana2_abstract_lib INTERFACE)

set_target_properties(jana2_abstract_lib PROPERTIES
SKIP_BUILD_RPATH FALSE
BUILD_WITH_INSTALL_RPATH FALSE
INSTALL_RPATH_USE_LINK_PATH TRUE)

target_include_directories(jana2_abstract_lib INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
$<INSTALL_INTERFACE:include>)
target_link_libraries(jana2 PUBLIC ${CMAKE_DL_LIBS} Threads::Threads)

target_link_libraries(jana2_abstract_lib INTERFACE ${CMAKE_DL_LIBS} Threads::Threads)
if (${USE_PODIO})
target_link_libraries(jana2 PUBLIC podio::podio podio::podioRootIO)
target_link_libraries(jana2_abstract_lib INTERFACE podio::podio podio::podioRootIO)
endif()

if (${USE_ROOT})
target_include_directories(jana2 PUBLIC ${ROOT_INCLUDE_DIRS})
target_link_libraries(jana2 PUBLIC ${ROOT_LIBRARIES})
target_include_directories(jana2_abstract_lib INTERFACE ${ROOT_INCLUDE_DIRS})
target_link_libraries(jana2_abstract_lib INTERFACE ${ROOT_LIBRARIES})
endif()

if (${USE_XERCES})
target_include_directories(jana2 PUBLIC ${XercesC_INCLUDE_DIRS})
target_link_libraries(jana2 PUBLIC ${XercesC_LIBRARIES})
target_include_directories(jana2_abstract_lib INTERFACE ${XercesC_INCLUDE_DIRS})
target_link_libraries(jana2_abstract_lib INTERFACE ${XercesC_LIBRARIES})
endif()
install(TARGETS jana2 EXPORT jana2_targets DESTINATION lib)

install(TARGETS jana2_abstract_lib EXPORT jana2_targets DESTINATION lib)


# Set up the object library (which is just a pile of .o files)
# simply so we don't compile the same files twice unnecessarily
add_library(jana2 OBJECT ${JANA2_SOURCES})
target_link_libraries(jana2 jana2_abstract_lib)


# static library, always there
# Set up the static library, which is always there
add_library(jana2_static_lib STATIC $<TARGET_OBJECTS:jana2>)
target_link_libraries(jana2_static_lib PUBLIC jana2)
target_link_libraries(jana2_static_lib PUBLIC jana2_abstract_lib)
set_target_properties(jana2_static_lib PROPERTIES PREFIX "lib" OUTPUT_NAME "JANA")
install(TARGETS jana2_static_lib EXPORT jana2_targets DESTINATION lib)

# optionally build shared lib
# Set up the shared library, which is optional
if (BUILD_SHARED_LIBS)
message(STATUS "Building static and shared libraries")
add_library(jana2_shared_lib SHARED $<TARGET_OBJECTS:jana2>)
target_link_libraries(jana2_shared_lib PUBLIC jana2)
target_link_libraries(jana2_shared_lib PUBLIC jana2_abstract_lib)
set_target_properties(jana2_shared_lib PROPERTIES PREFIX "lib" OUTPUT_NAME "JANA")
install(TARGETS jana2_shared_lib EXPORT jana2_targets DESTINATION lib)
else()
Expand Down

0 comments on commit 0c2953b

Please sign in to comment.