1- CMAKE_MINIMUM_REQUIRED (VERSION 2.8.1 )
2- PROJECT (libtins)
1+ # pre-test discovery mode for gtest_discover_tests was added in 3.18
2+ cmake_minimum_required (VERSION 3.12...3.18 )
3+
4+ if (POLICY CMP0167)
5+ cmake_policy (SET CMP0167 NEW )
6+ endif ()
7+
8+ if (POLICY CMP0135)
9+ cmake_policy (SET CMP0135 NEW )
10+ endif ()
11+
12+ # Add cmake modules of this project to the module path
13+ list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} /cmake/Modules)
314
415OPTION (LIBTINS_BUILD_EXAMPLES "Build examples" ON )
516OPTION (LIBTINS_BUILD_TESTS "Build tests" ON )
@@ -12,6 +23,21 @@ ELSE(NOT CMAKE_BUILD_TYPE)
1223 MESSAGE (STATUS "Using specified '${CMAKE_BUILD_TYPE} ' build type." )
1324ENDIF (NOT CMAKE_BUILD_TYPE )
1425
26+ project (
27+ libtins
28+ LANGUAGES CXX
29+ )
30+
31+ # Check the thread library info early as setting compiler flags seems to
32+ # interfere with the detection and causes CMAKE_THREAD_LIBS_INIT to not
33+ # include -lpthread when it should.
34+ if (LIBTINS_BUILD_TESTS)
35+ if (NOT TARGET Threads::Threads)
36+ find_package (Threads REQUIRED )
37+ endif ()
38+ set (LINK_LIBS ${LINK_LIBS} Threads::Threads)
39+ endif ()
40+
1541# Compilation flags.
1642IF (MSVC )
1743 # Don't always use Wall, since VC's /Wall is ridiculously verbose.
@@ -50,8 +76,14 @@ SET(TINS_VERSION_MINOR 6)
5076SET (TINS_VERSION_PATCH 0)
5177SET (LIBTINS_VERSION "${TINS_VERSION_MAJOR} .${TINS_VERSION_MINOR} " )
5278
53- # Required Packages
54- SET (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR} /cmake/Modules/" )
79+ set (CMAKE_CXX_STANDARD 14)
80+ set (CMAKE_CXX_STANDARD_REQUIRED ON )
81+ set (CMAKE_CXX_EXTENSIONS ON )
82+
83+ if (CMAKE_CXX_COMPILER_ID STREQUAL Clang)
84+ set (CLANG_DEFAULT_CXX_STDLIB libc++)
85+ set (CLANG_DEFAULT_RTLIB compiler-rt)
86+ endif ()
5587
5688# Allow disabling packet capture mechanism
5789OPTION (LIBTINS_ENABLE_PCAP "Enable capturing packets via libpcap" ON )
@@ -87,7 +119,9 @@ IF(WIN32)
87119
88120ENDIF (WIN32 )
89121
90- INCLUDE (ExternalProject )
122+ INCLUDE (CTest )
123+ INCLUDE (GNUInstallDirs )
124+ #INCLUDE(ExternalProject)
91125
92126# *******************
93127# Compilation options
@@ -155,7 +189,7 @@ ELSE()
155189ENDIF ()
156190
157191# Search for libboost
158- FIND_PACKAGE (Boost )
192+ FIND_PACKAGE (Boost, CONFIG )
159193
160194# Optionally enable the ACK tracker (on by default)
161195OPTION (LIBTINS_ENABLE_ACK_TRACKER "Enable TCP ACK tracking support" ON )
@@ -279,38 +313,29 @@ IF(LIBTINS_BUILD_EXAMPLES)
279313ENDIF ()
280314
281315IF (LIBTINS_BUILD_TESTS)
282- # Only include googletest if the git submodule has been fetched
283- IF (EXISTS "${CMAKE_CURRENT_SOURCE_DIR} /googletest/CMakeLists.txt" )
284- # Enable tests and add the test directory
285- MESSAGE (STATUS "Tests have been enabled" )
286- SET (GOOGLETEST_ROOT ${CMAKE_CURRENT_SOURCE_DIR} /googletest)
287- SET (GOOGLETEST_INCLUDE ${GOOGLETEST_ROOT} /googletest/include)
288- SET (GOOGLETEST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} /googletest)
289- SET (GOOGLETEST_LIBRARY ${GOOGLETEST_BINARY_DIR} /googletest)
290-
291- ExternalProject_Add (
316+ find_package (GTest )
317+ include_directories (${GTEST_INCLUDE_DIRS} )
318+ IF (NOT GTEST_FOUND)
319+ message (WARNING "Can't find system Google Test" )
320+ include (FetchContent )
321+ FetchContent_Declare (
292322 googletest
293- DOWNLOAD_COMMAND ""
294- SOURCE_DIR ${GOOGLETEST_ROOT}
295- BINARY_DIR ${GOOGLETEST_BINARY_DIR}
296- CMAKE_CACHE_ARGS "-DBUILD_GTEST:bool=ON" "-DBUILD_GMOCK:bool=OFF"
297- "-Dgtest_force_shared_crt:bool=ON"
298- "-DCMAKE_CXX_COMPILER:path=${CMAKE_CXX_COMPILER} "
299- INSTALL_COMMAND ""
323+ # Specify the commit => this is release 1.12.1
324+ URL https://github.com/google/googletest/archive/58d77fa8070e8cec2dc1ed015d66b454c8d78850.zip
300325 )
301- # Make sure we build googletest before anything else
302- ADD_DEPENDENCIES (tins googletest )
303- ENABLE_TESTING ()
304- ADD_SUBDIRECTORY (tests )
305- ELSE ()
306- FIND_PACKAGE (GTest QUIET )
307- IF (${GTest_FOUND} )
308- ENABLE_TESTING ()
309- ADD_SUBDIRECTORY (tests )
310- ELSE ()
311- MESSAGE (STATUS "googletest git submodule is absent. Run `git submodule init && git submodule update` to get it" )
312- ENDIF ()
326+ FetchContent_GetProperties (googletest)
327+ if (NOT googletest_POPULATED)
328+ # Fetch the content using previously declared details
329+ FetchContent_Populate (googletest)
330+ add_subdirectory (${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} )
331+ endif ()
332+ include_directories (${gtest_SOURCE_DIR} /include ${gtest_SOURCE_DIR} )
313333 ENDIF ()
334+ # For Windows: Prevent overriding the parent project's compiler/linker settings
335+ set (gtest_force_shared_crt ON CACHE BOOL "" FORCE )
336+ ENABLE_TESTING ()
337+ set (GTEST_LINK_LIBRARIES gtest gtest_main)
338+ ADD_SUBDIRECTORY (tests )
314339ENDIF ()
315340
316341# **********************************
0 commit comments