static support lib

This commit is contained in:
Erik Frojdh 2020-09-04 11:00:34 +02:00
parent 497eff6f04
commit 514346c3ba
3 changed files with 56 additions and 34 deletions

View File

@ -63,17 +63,18 @@ find_package(ClangFormat)
check_ipo_supported(RESULT SLS_LTO_AVAILABLE) check_ipo_supported(RESULT SLS_LTO_AVAILABLE)
# Use ld.gold if it is available and isn't disabled explicitly # # Use ld.gold if it is available and isn't disabled explicitly
option(SLS_USE_LD_GOLD "Use GNU gold linker" ON) # option(SLS_USE_LD_GOLD "Use GNU gold linker" ON)
if (SLS_USE_LD_GOLD) # if (SLS_USE_LD_GOLD)
execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION) # execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
if ("${LD_VERSION}" MATCHES "GNU gold") # if ("${LD_VERSION}" MATCHES "GNU gold")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fuse-ld=gold") # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=gold") # set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
else () # set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
message(WARNING "GNU gold linker isn't available, using the default system linker.") # else ()
endif () # message(WARNING "GNU gold linker isn't available, using the default system linker.")
endif () # endif ()
# endif ()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)

View File

@ -27,7 +27,7 @@ target_include_directories(slsDetectorShared PUBLIC
target_link_libraries(slsDetectorShared target_link_libraries(slsDetectorShared
PUBLIC PUBLIC
slsSupportLib slsSupportLibStatic
pthread pthread
rt rt
slsProjectOptions slsProjectOptions

View File

@ -44,54 +44,75 @@ if(SLS_DEVEL_HEADERS)
) )
endif() endif()
add_library(slsSupportLib SHARED # Create a Object library to avoid duplicating the build
add_library(slsSupportObject OBJECT
${SOURCES} ${SOURCES}
${HEADERS} ${HEADERS}
) )
if((CMAKE_BUILD_TYPE STREQUAL "Release") AND SLS_LTO_AVAILABLE)
set_property(TARGET slsSupportLib PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
endif()
target_include_directories(slsSupportObject PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
target_include_directories(slsSupportObject PRIVATE
${ZeroMQ_INCLUDE_DIRS}
)
target_link_libraries(slsSupportObject
PUBLIC
slsProjectOptions
zmq
rapidjson
PRIVATE
slsProjectWarnings
)
if (SLS_USE_TESTS)
add_subdirectory(tests)
endif(SLS_USE_TESTS)
add_library(slsSupportLib SHARED $<TARGET_OBJECTS:slsSupportObject>)
target_include_directories(slsSupportLib PUBLIC target_include_directories(slsSupportLib PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
) )
target_include_directories(slsSupportLib PRIVATE
${ZeroMQ_INCLUDE_DIRS}
)
set_target_properties(slsSupportLib PROPERTIES set_target_properties(slsSupportLib PROPERTIES
LIBRARY_OUTPUT_NAME SlsSupport LIBRARY_OUTPUT_NAME SlsSupport
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
PUBLIC_HEADER "${PUBLICHEADERS}" PUBLIC_HEADER "${PUBLICHEADERS}"
) )
target_link_libraries(slsSupportLib add_library(slsSupportLibStatic STATIC $<TARGET_OBJECTS:slsSupportObject>)
PUBLIC
slsProjectOptions set_target_properties(slsSupportLibStatic PROPERTIES
# ${ZeroMQ_LIBRARIES} ARCHIVE_OUTPUT_NAME SlsSupportStatic
zmq ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
rapidjson PUBLIC_HEADER "${PUBLICHEADERS}"
PRIVATE
slsProjectWarnings
) )
target_include_directories(slsSupportLibStatic PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
if((CMAKE_BUILD_TYPE STREQUAL "Release") AND SLS_LTO_AVAILABLE)
if (SLS_USE_TESTS) set_property(TARGET slsSupportObject PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
add_subdirectory(tests) set_property(TARGET slsSupportLib PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
endif(SLS_USE_TESTS) set_property(TARGET slsSupportLibStatic PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
endif()
# Install the library # Install the library
install(TARGETS slsSupportLib install(TARGETS slsSupportLib slsSupportLibStatic
EXPORT "${TARGETS_EXPORT_NAME}" EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
) )