UDPConnection/CMakeLists.txt

79 lines
2.8 KiB
Text
Raw Normal View History

2019-06-06 07:02:48 +00:00
cmake_minimum_required(VERSION 3.7)
project(UDPConnection)
set(UDPConnection_VERSION 1.0)
set(UDPConnection_SOURCES
src/UDPConnection.cpp
)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -Wno-missing-braces")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -D NDEBUG")
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()
add_library(UDPConnection ${UDPConnection_SOURCES})
set_target_properties(UDPConnection PROPERTIES VERSION ${UDPConnection_VERSION})
target_compile_features(UDPConnection PUBLIC cxx_std_11)
2019-06-06 07:02:48 +00:00
target_link_libraries(UDPConnection PUBLIC pthread)
2019-09-19 03:23:15 +00:00
if(WIN32)
2019-09-21 03:15:49 +00:00
if(MINGW)
target_compile_definitions(UDPConnection PUBLIC UDPC_PLATFORM_MINGW)
target_link_libraries(UDPConnection PUBLIC ws2_32)
target_link_libraries(UDPConnection PUBLIC iphlpapi)
else()
target_link_libraries(UDPConnection PUBLIC Ws2_32)
target_link_libraries(UDPConnection PUBLIC Iphlpapi)
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")
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBSODIUM QUIET libsodium)
if(LIBSODIUM_FOUND)
target_compile_definitions(UDPConnection PUBLIC UDPC_LIBSODIUM_ENABLED)
target_link_libraries(UDPConnection PUBLIC ${LIBSODIUM_LIBRARIES})
target_include_directories(UDPConnection PUBLIC ${LIBSODIUM_INCLUDE_DIRS})
target_compile_options(UDPConnection 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")
2019-06-07 02:33:44 +00:00
find_package(GTest QUIET)
if(GTEST_FOUND)
set(UDPC_UnitTest_SOURCES
src/test/UDPC_UnitTest.cpp
2019-10-24 11:25:41 +00:00
src/test/TestTSLQueue.cpp
2019-08-27 09:03:30 +00:00
src/test/TestUDPC.cpp
2019-06-07 02:33:44 +00:00
)
add_executable(UnitTest ${UDPC_UnitTest_SOURCES})
target_compile_features(UnitTest PUBLIC cxx_std_11)
2019-06-07 02:33:44 +00:00
target_link_libraries(UnitTest PUBLIC UDPConnection ${GTEST_BOTH_LIBRARIES})
target_include_directories(UnitTest PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
endif()
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})
target_link_libraries(NetworkTest PUBLIC UDPConnection)
target_include_directories(NetworkTest PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
endif()
install(TARGETS UDPConnection DESTINATION lib)
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/UDPConnection.h
DESTINATION include)