Skip to content
Snippets Groups Projects
Commit 6e0e63c3 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

CMake: add static/shared library build options

Add -DOPENDHT_STATIC=Off to disable static library build,
add -DOPENDHT_SHARED=Off to disable shared library build.
parent 08c21069
No related branches found
No related tags found
No related merge requests found
...@@ -15,6 +15,8 @@ set (includedir "\${prefix}/include") ...@@ -15,6 +15,8 @@ set (includedir "\${prefix}/include")
option (OPENDHT_PYTHON "Build Python bindings" OFF) option (OPENDHT_PYTHON "Build Python bindings" OFF)
option (OPENDHT_TOOLS "Build DHT tools" ON) option (OPENDHT_TOOLS "Build DHT tools" ON)
option (OPENDHT_DEBUG "Build with debug flags" OFF) option (OPENDHT_DEBUG "Build with debug flags" OFF)
option (OPENDHT_STATIC "Build static library" ON)
option (OPENDHT_SHARED "Build shared library" ON)
set (CMAKE_CXX_FLAGS "-pthread -std=c++11 -Wno-return-type -Wall -Wextra -Wnon-virtual-dtor ${CMAKE_CXX_FLAGS}") set (CMAKE_CXX_FLAGS "-pthread -std=c++11 -Wno-return-type -Wall -Wextra -Wnon-virtual-dtor ${CMAKE_CXX_FLAGS}")
set (CMAKE_CXX_FLAGS "-DMSGPACK_DISABLE_LEGACY_NIL -DMSGPACK_DISABLE_LEGACY_CONVERT ${CMAKE_CXX_FLAGS}") set (CMAKE_CXX_FLAGS "-DMSGPACK_DISABLE_LEGACY_NIL -DMSGPACK_DISABLE_LEGACY_CONVERT ${CMAKE_CXX_FLAGS}")
...@@ -74,25 +76,30 @@ else () ...@@ -74,25 +76,30 @@ else ()
set(CMAKE_BUILD_TYPE Release) set(CMAKE_BUILD_TYPE Release)
endif () endif ()
add_library (opendht SHARED if (NOT DEFINED CMAKE_INSTALL_LIBDIR)
${opendht_SOURCES} set(CMAKE_INSTALL_LIBDIR lib)
${opendht_HEADERS} endif ()
)
set_target_properties (opendht PROPERTIES IMPORT_SUFFIX "_import.lib")
#set_target_properties (opendht PROPERTIES SOVERSION 1 VERSION 1.0.0)
if (OPENDHT_STATIC)
add_library (opendht-static STATIC add_library (opendht-static STATIC
${opendht_SOURCES} ${opendht_SOURCES}
${opendht_HEADERS} ${opendht_HEADERS}
) )
set_target_properties (opendht-static PROPERTIES OUTPUT_NAME "opendht") set_target_properties (opendht-static PROPERTIES OUTPUT_NAME "opendht")
target_link_libraries(opendht-static gnutls nettle)
if (NOT DEFINED CMAKE_INSTALL_LIBDIR) install (TARGETS opendht-static DESTINATION ${CMAKE_INSTALL_LIBDIR})
set(CMAKE_INSTALL_LIBDIR lib)
endif () endif ()
target_link_libraries(opendht-static gnutls nettle) if (OPENDHT_SHARED)
add_library (opendht SHARED
${opendht_SOURCES}
${opendht_HEADERS}
)
set_target_properties (opendht PROPERTIES IMPORT_SUFFIX "_import.lib")
#set_target_properties (opendht PROPERTIES SOVERSION 1 VERSION 1.0.0)
target_link_libraries(opendht gnutls nettle) target_link_libraries(opendht gnutls nettle)
install (TARGETS opendht DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif ()
if (OPENDHT_TOOLS) if (OPENDHT_TOOLS)
add_subdirectory(tools) add_subdirectory(tools)
...@@ -102,6 +109,5 @@ if (OPENDHT_PYTHON) ...@@ -102,6 +109,5 @@ if (OPENDHT_PYTHON)
add_subdirectory(python) add_subdirectory(python)
endif () endif ()
install (TARGETS opendht opendht-static DESTINATION ${CMAKE_INSTALL_LIBDIR})
install (DIRECTORY include DESTINATION ${CMAKE_INSTALL_PREFIX}) install (DIRECTORY include DESTINATION ${CMAKE_INSTALL_PREFIX})
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/opendht.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/opendht.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
...@@ -3,9 +3,19 @@ add_executable (dhtnode dhtnode.cpp tools_common.h) ...@@ -3,9 +3,19 @@ add_executable (dhtnode dhtnode.cpp tools_common.h)
add_executable (dhtscanner dhtscanner.cpp tools_common.h) add_executable (dhtscanner dhtscanner.cpp tools_common.h)
add_executable (dhtchat dhtchat.cpp tools_common.h) add_executable (dhtchat dhtchat.cpp tools_common.h)
target_link_libraries (dhtnode LINK_PUBLIC opendht gnutls readline) target_link_libraries (dhtnode LINK_PUBLIC gnutls readline)
target_link_libraries (dhtscanner LINK_PUBLIC opendht gnutls readline) target_link_libraries (dhtscanner LINK_PUBLIC gnutls readline)
target_link_libraries (dhtchat LINK_PUBLIC opendht gnutls readline) target_link_libraries (dhtchat LINK_PUBLIC gnutls readline)
if (OPENDHT_SHARED)
target_link_libraries (dhtnode LINK_PUBLIC opendht)
target_link_libraries (dhtscanner LINK_PUBLIC opendht)
target_link_libraries (dhtchat LINK_PUBLIC opendht)
else ()
target_link_libraries (dhtnode LINK_PUBLIC opendht-static)
target_link_libraries (dhtscanner LINK_PUBLIC opendht-static)
target_link_libraries (dhtchat LINK_PUBLIC opendht-static)
endif ()
if (NOT DEFINED CMAKE_INSTALL_BINDIR) if (NOT DEFINED CMAKE_INSTALL_BINDIR)
set(CMAKE_INSTALL_BINDIR bin) set(CMAKE_INSTALL_BINDIR bin)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment