Skip to content
This repository was archived by the owner on Jul 8, 2022. It is now read-only.

Commit 0aefb31

Browse files
committed
CMake on Linux: Only generate either the static or the dynamic library
In af72afb (Generate static library and fix compilation definitions (#17) (#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.
1 parent 6d8f801 commit 0aefb31

File tree

4 files changed

+23
-26
lines changed

4 files changed

+23
-26
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ add_subdirectory("log4tango")
3333
add_subdirectory("cppapi")
3434

3535
if(BUILD_TESTING)
36+
if(BUILD_SHARED_LIBS)
3637
add_subdirectory("cpp_test_suite")
38+
else()
39+
message(WARNING "Not building the tests, because that is currently supported only when BUILD_SHARED_LIBS is ON")
40+
SET(BUILD_TESTING OFF)
41+
endif()
3742
endif()
3843

3944
if(WIN32)

INSTALL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- `-DCMAKE_VERBOSE_MAKEFILE=true`
2929
- `-DTANGO_USE_USING_NAMESPACE=<ON|OFF>` choose `OFF` for modern builds
3030
- `-DBUILD_TESTING=<ON|OFF>` Build the test suite (`ON` by default)
31+
- `-DBUILD_SHARED_LIBS=<ON|OFF>` Build tango as shared library (`ON` by default)
3132

3233
Typical output:
3334

configure/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,4 @@ include(GNUInstallDirs)
214214
include(configure/coveralls.cmake)
215215

216216
option(TANGO_JPEG_MMX "Build MMX support" ON)
217+
option(BUILD_SHARED_LIBS "Build a shared library instead of static" ON)

configure/cmake_linux.cmake

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
11
project(libtango)
22

3-
add_library(tango SHARED $<TARGET_OBJECTS:log4tango_objects>
4-
$<TARGET_OBJECTS:client_objects>
5-
$<TARGET_OBJECTS:idl_objects>
6-
$<TARGET_OBJECTS:jpeg_objects>
7-
$<TARGET_OBJECTS:jpeg_mmx_objects>
8-
$<TARGET_OBJECTS:server_objects>)
3+
add_library(tango $<TARGET_OBJECTS:log4tango_objects>
4+
$<TARGET_OBJECTS:client_objects>
5+
$<TARGET_OBJECTS:idl_objects>
6+
$<TARGET_OBJECTS:jpeg_objects>
7+
$<TARGET_OBJECTS:jpeg_mmx_objects>
8+
$<TARGET_OBJECTS:server_objects>)
99
target_link_libraries(tango PUBLIC ${ZMQ_PKG_LIBRARIES} ${OMNIORB_PKG_LIBRARIES} ${OMNICOS_PKG_LIBRARIES} ${OMNIDYN_PKG_LIBRARIES} ${CMAKE_DL_LIBS})
10-
target_compile_options(tango PRIVATE -fPIC)
1110
target_include_directories(tango PUBLIC ${ZMQ_PKG_INCLUDE_DIRS} ${OMNIORB_PKG_INCLUDE_DIRS} ${OMNIDYN_PKG_INCLUDE_DIRS})
12-
1311
target_compile_options(tango PUBLIC ${ZMQ_PKG_CFLAGS_OTHER} ${OMNIORB_PKG_CFLAGS_OTHER} ${OMNICOS_PKG_CFLAGS_OTHER} ${OMNIDYN_PKG_CFLAGS_OTHER})
14-
target_compile_definitions(tango PUBLIC _REENTRANT)
15-
16-
set_target_properties(tango PROPERTIES
17-
VERSION ${LIBRARY_VERSION}
18-
SOVERSION ${SO_VERSION})
19-
20-
add_library(tango-static STATIC $<TARGET_OBJECTS:log4tango_objects>
21-
$<TARGET_OBJECTS:client_objects>
22-
$<TARGET_OBJECTS:idl_objects>
23-
$<TARGET_OBJECTS:jpeg_objects>
24-
$<TARGET_OBJECTS:jpeg_mmx_objects>
25-
$<TARGET_OBJECTS:server_objects>)
26-
target_link_libraries(tango-static PUBLIC ${ZMQ_PKG_LIBRARIES} ${OMNIORB_PKG_LIBRARIES} ${OMNICOS_PKG_LIBRARIES} ${OMNIDYN_PKG_LIBRARIES} ${CMAKE_DL_LIBS})
27-
target_include_directories(tango-static PUBLIC ${ZMQ_PKG_INCLUDE_DIRS} ${OMNIORB_PKG_INCLUDE_DIRS} ${OMNIDYN_PKG_INCLUDE_DIRS})
28-
target_compile_options(tango-static PUBLIC ${ZMQ_PKG_CFLAGS_OTHER} ${OMNIORB_PKG_CFLAGS_OTHER} ${OMNICOS_PKG_CFLAGS_OTHER} ${OMNIDYN_PKG_CFLAGS_OTHER})
29-
set_target_properties(tango-static PROPERTIES OUTPUT_NAME tango)
3012

31-
install(TARGETS tango LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
32-
install(TARGETS tango-static ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
13+
if(BUILD_SHARED_LIBS)
14+
target_compile_options(tango PRIVATE -fPIC)
15+
target_compile_definitions(tango PUBLIC _REENTRANT)
16+
set_target_properties(tango PROPERTIES
17+
VERSION ${LIBRARY_VERSION}
18+
SOVERSION ${SO_VERSION})
19+
install(TARGETS tango LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
20+
else()
21+
install(TARGETS tango ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
22+
endif()
3323

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

0 commit comments

Comments
 (0)