UDPConnection/CMakeLists.txt

87 lines
3 KiB
Text
Raw Normal View History

2019-06-06 07:02:48 +00:00
cmake_minimum_required(VERSION 3.7)
2020-01-09 07:57:01 +00:00
project(UDPC)
2019-06-06 07:02:48 +00:00
set(UDPC_VERSION 1.1)
set(UDPC_SOVERSION 1)
2019-06-06 07:02:48 +00:00
2020-01-09 07:57:01 +00:00
set(UDPC_SOURCES
2019-06-06 07:02:48 +00:00
src/UDPConnection.cpp
src/CXX11_shared_spin_lock.cpp
2019-06-06 07:02:48 +00:00
)
add_compile_options(
-Wall -Wextra -Wpedantic -Wno-missing-braces
$<$<COMPILE_LANGUAGE:CXX>:-Weffc++>
2024-01-11 12:05:02 +00:00
$<$<CONFIG:DEBUG>:-Og>
)
2019-06-06 07:02:48 +00:00
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Debug', none was specified.")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif()
2020-01-09 07:57:01 +00:00
add_library(UDPC ${UDPC_SOURCES})
2019-06-06 07:02:48 +00:00
set_target_properties(UDPC PROPERTIES VERSION ${UDPC_VERSION} SOVERSION ${UDPC_SOVERSION})
2019-06-06 07:02:48 +00:00
2020-01-09 07:57:01 +00:00
target_compile_features(UDPC PUBLIC cxx_std_11)
target_link_libraries(UDPC PUBLIC pthread)
2019-09-19 03:23:15 +00:00
if(WIN32)
2019-09-21 03:15:49 +00:00
if(MINGW)
2020-01-09 07:57:01 +00:00
target_compile_definitions(UDPC PUBLIC UDPC_PLATFORM_MINGW)
target_link_libraries(UDPC PUBLIC ws2_32)
target_link_libraries(UDPC PUBLIC iphlpapi)
2019-09-21 03:15:49 +00:00
else()
2020-01-09 07:57:01 +00:00
target_link_libraries(UDPC PUBLIC Ws2_32)
target_link_libraries(UDPC PUBLIC Iphlpapi)
2019-09-21 03:15:49 +00:00
endif()
2019-09-19 03:23:15 +00:00
endif()
2019-06-06 07:02:48 +00:00
if(UDPC_DISABLE_LIBSODIUM)
message(STATUS "libsodium disabled")
elseif(DEFINED M_LIBSODIUM_LIBRARIES AND DEFINED M_LIBSODIUM_INCLUDE_DIRS)
message(STATUS "libsodium manual paths detected, using them")
target_compile_definitions(UDPC PUBLIC UDPC_LIBSODIUM_ENABLED)
target_link_libraries(UDPC PUBLIC ${M_LIBSODIUM_LIBRARIES})
target_include_directories(UDPC PUBLIC ${M_LIBSODIUM_INCLUDE_DIRS})
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBSODIUM QUIET libsodium)
if(LIBSODIUM_FOUND)
2020-01-09 07:57:01 +00:00
target_compile_definitions(UDPC PUBLIC UDPC_LIBSODIUM_ENABLED)
target_link_libraries(UDPC PUBLIC ${LIBSODIUM_LIBRARIES})
target_include_directories(UDPC PUBLIC ${LIBSODIUM_INCLUDE_DIRS})
target_compile_options(UDPC PUBLIC ${LIBSODIUM_CFLAGS_OTHER})
message(STATUS "libsodium enabled")
else()
message(STATUS "libsodium not found, UDPC will be compiled without libsodium support")
endif()
endif()
2019-06-06 07:02:48 +00:00
if(CMAKE_BUILD_TYPE MATCHES "Debug")
2024-07-12 06:52:53 +00:00
set(UDPC_UnitTest_SOURCES
src/CXX11_shared_spin_lock.cpp
src/test/UDPC_UnitTest.cpp
src/test/TestTSLQueue.cpp
src/test/TestUDPC.cpp
src/test/TestSharedSpinLock.cpp
)
add_executable(UnitTest ${UDPC_UnitTest_SOURCES})
target_compile_features(UnitTest PUBLIC cxx_std_11)
target_link_libraries(UnitTest PUBLIC UDPC)
target_include_directories(UnitTest PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_compile_options(UnitTest PRIVATE "-Wno-sign-compare")
2019-06-06 07:02:48 +00:00
set(UDPC_NetworkTest_SOURCES
2019-11-13 02:47:53 +00:00
src/test/UDPC_NetworkTest.c)
2019-06-06 07:02:48 +00:00
add_executable(NetworkTest ${UDPC_NetworkTest_SOURCES})
2020-01-09 07:57:01 +00:00
target_link_libraries(NetworkTest PUBLIC UDPC)
2019-06-06 07:02:48 +00:00
target_include_directories(NetworkTest PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
endif()
2020-01-09 07:57:01 +00:00
install(TARGETS UDPC DESTINATION lib)
2019-06-06 07:02:48 +00:00
install(FILES
2020-01-09 07:57:01 +00:00
${CMAKE_CURRENT_SOURCE_DIR}/src/UDPC.h
2019-06-06 07:02:48 +00:00
DESTINATION include)