Skip to content

Commit

Permalink
CMake on Linux: Only generate either the static or the dynamic library
Browse files Browse the repository at this point in the history
In af72afb (Generate static library and fix compilation definitions
(tango-controls#17) (tango-controls#437), 2018-05-15) support was added for building a static
library next to the dynamic one.

As most users want to have only either library we use the newly
introduced option BUILD_SHARED_LIBS to build either one. This also
solves issues when cross-compiling where you might not have shared
libraries for the target architecture.
  • Loading branch information
t-b committed Sep 1, 2020
1 parent d4f823f commit 7626847
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ add_subdirectory("log4tango")
add_subdirectory("cppapi")

if(BUILD_TESTING)
if(BUILD_SHARED_LIBS)
add_subdirectory("cpp_test_suite")
else()
message(WARNING "Not building the tests, because that is currently supported only when BUILD_SHARED_LIBS is ON")
SET(BUILD_TESTING OFF)
endif()
endif()

if(WIN32)
Expand Down
42 changes: 16 additions & 26 deletions configure/cmake_linux.cmake
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
project(libtango)

add_library(tango SHARED $<TARGET_OBJECTS:log4tango_objects>
$<TARGET_OBJECTS:client_objects>
$<TARGET_OBJECTS:idl_objects>
$<TARGET_OBJECTS:jpeg_objects>
$<TARGET_OBJECTS:jpeg_mmx_objects>
$<TARGET_OBJECTS:server_objects>)
add_library(tango $<TARGET_OBJECTS:log4tango_objects>
$<TARGET_OBJECTS:client_objects>
$<TARGET_OBJECTS:idl_objects>
$<TARGET_OBJECTS:jpeg_objects>
$<TARGET_OBJECTS:jpeg_mmx_objects>
$<TARGET_OBJECTS:server_objects>)
target_link_libraries(tango PUBLIC ${ZMQ_PKG_LIBRARIES} ${OMNIORB_PKG_LIBRARIES} ${OMNICOS_PKG_LIBRARIES} ${OMNIDYN_PKG_LIBRARIES} ${CMAKE_DL_LIBS})
target_compile_options(tango PRIVATE -fPIC)
target_include_directories(tango PUBLIC ${ZMQ_PKG_INCLUDE_DIRS} ${OMNIORB_PKG_INCLUDE_DIRS} ${OMNIDYN_PKG_INCLUDE_DIRS})

target_compile_options(tango PUBLIC ${ZMQ_PKG_CFLAGS_OTHER} ${OMNIORB_PKG_CFLAGS_OTHER} ${OMNICOS_PKG_CFLAGS_OTHER} ${OMNIDYN_PKG_CFLAGS_OTHER})
target_compile_definitions(tango PUBLIC _REENTRANT)

set_target_properties(tango PROPERTIES
VERSION ${LIBRARY_VERSION}
SOVERSION ${SO_VERSION})

add_library(tango-static STATIC $<TARGET_OBJECTS:log4tango_objects>
$<TARGET_OBJECTS:client_objects>
$<TARGET_OBJECTS:idl_objects>
$<TARGET_OBJECTS:jpeg_objects>
$<TARGET_OBJECTS:jpeg_mmx_objects>
$<TARGET_OBJECTS:server_objects>)
target_link_libraries(tango-static PUBLIC ${ZMQ_PKG_LIBRARIES} ${OMNIORB_PKG_LIBRARIES} ${OMNICOS_PKG_LIBRARIES} ${OMNIDYN_PKG_LIBRARIES} ${CMAKE_DL_LIBS})
target_include_directories(tango-static PUBLIC ${ZMQ_PKG_INCLUDE_DIRS} ${OMNIORB_PKG_INCLUDE_DIRS} ${OMNIDYN_PKG_INCLUDE_DIRS})
target_compile_options(tango-static PUBLIC ${ZMQ_PKG_CFLAGS_OTHER} ${OMNIORB_PKG_CFLAGS_OTHER} ${OMNICOS_PKG_CFLAGS_OTHER} ${OMNIDYN_PKG_CFLAGS_OTHER})
set_target_properties(tango-static PROPERTIES OUTPUT_NAME tango)

install(TARGETS tango LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
install(TARGETS tango-static ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
if(BUILD_SHARED_LIBS)
target_compile_options(tango PRIVATE -fPIC)
target_compile_definitions(tango PUBLIC _REENTRANT)
set_target_properties(tango PROPERTIES
VERSION ${LIBRARY_VERSION}
SOVERSION ${SO_VERSION})
install(TARGETS tango LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
else()
install(TARGETS tango ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
endif()

configure_file(tango.pc.cmake tango.pc @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tango.pc"
Expand Down

0 comments on commit 7626847

Please sign in to comment.