From 08bdf236c62012bfd358a87334389c670eabc6db Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Fri, 22 Nov 2019 16:08:32 +0200 Subject: [PATCH 01/23] cmake: require a more recent version and refactor - Use CMAKE_CXX_STANDARD - Use PROJET_NAME - Set PROJECT_VERSION - Use CMake search paths to find ExternalProject --- CMakeLists.txt | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef461cf..955e95b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,9 +23,10 @@ ### # config ### -cmake_minimum_required(VERSION 2.8.7) +cmake_minimum_required(VERSION 3.13) set(CMAKE_MACOSX_RPATH 1) -include(${CMAKE_ROOT}/Modules/ExternalProject.cmake) +set(CMAKE_CXX_STANDARD 11) +include(ExternalProject) ### @@ -37,8 +38,7 @@ include(${CMAKE_ROOT}/Modules/ExternalProject.cmake) ### # project ### -set(PROJECT tacopie) -project(${PROJECT} CXX) +project(tacopie LANGUAGES CXX VERSION 3.2.0) ### @@ -126,39 +126,39 @@ configure_file("tacopie.pc.in" "${CMAKE_PKGCONFIG_OUTPUT_DIRECTORY}/tacopie.pc" ### # executable ### -add_library(${PROJECT} ${SOURCES}) -set_property(TARGET ${PROJECT} PROPERTY POSITION_INDEPENDENT_CODE ON) +add_library(${PROJECT_NAME} ${SOURCES}) +set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) IF (WIN32) - set_target_properties(${PROJECT} - PROPERTIES COMPILE_PDB_NAME ${PROJECT} + set_target_properties(${PROJECT_NAME} + PROPERTIES COMPILE_PDB_NAME ${PROJECT_NAME} COMPILE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) ENDIF (WIN32) IF (WIN32) - target_link_libraries(${PROJECT} ws2_32) + target_link_libraries(${PROJECT_NAME} ws2_32) ELSE () - target_link_libraries(${PROJECT} pthread) + target_link_libraries(${PROJECT_NAME} pthread) ENDIF (WIN32) # __TACOPIE_LOGGING_ENABLED IF (LOGGING_ENABLED) - set_property(TARGET ${PROJECT} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __TACOPIE_LOGGING_ENABLED=${LOGGING_ENABLED}") + set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __TACOPIE_LOGGING_ENABLED=${LOGGING_ENABLED}") ENDIF (LOGGING_ENABLED) # __TACOPIE_CONNECTION_QUEUE_SIZE IF (CONNECTION_QUEUE_SIZE) - set_property(TARGET ${PROJECT} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __TACOPIE_CONNECTION_QUEUE_SIZE=${CONNECTION_QUEUE_SIZE}") + set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __TACOPIE_CONNECTION_QUEUE_SIZE=${CONNECTION_QUEUE_SIZE}") ENDIF (CONNECTION_QUEUE_SIZE) #__TACOPIE_IO_SERVICE_NB_WORKERS IF (IO_SERVICE_NB_WORKERS) - set_property(TARGET ${PROJECT} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __TACOPIE_IO_SERVICE_NB_WORKERS=${IO_SERVICE_NB_WORKERS}") + set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __TACOPIE_IO_SERVICE_NB_WORKERS=${IO_SERVICE_NB_WORKERS}") ENDIF(IO_SERVICE_NB_WORKERS) #__TACOPIE_TIMEOUT IF (SELECT_TIMEOUT) - set_property(TARGET ${PROJECT} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __TACOPIE_TIMEOUT=${SELECT_TIMEOUT}") + set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __TACOPIE_TIMEOUT=${SELECT_TIMEOUT}") ENDIF(SELECT_TIMEOUT) From 0362fb5ccebb4351291d829c864fb913b910b4e5 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Fri, 22 Nov 2019 16:09:57 +0200 Subject: [PATCH 02/23] cmake: use lowercase syntax --- CMakeLists.txt | 58 +++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 955e95b..3295182 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,33 +44,33 @@ project(tacopie LANGUAGES CXX VERSION 3.2.0) ### # compilation options ### -IF (MSVC) +if (MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /O2 /bigobj") # was causing conflics with gtest build string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) - IF ("${MSVC_RUNTIME_LIBRARY_CONFIG}" STREQUAL "") + if ("${MSVC_RUNTIME_LIBRARY_CONFIG}" STREQUAL "") set(MSVC_RUNTIME_LIBRARY_CONFIG "/MT") - ENDIF() + endif () foreach (flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE) - IF ("${MSVC_RUNTIME_LIBRARY_CONFIG}" STREQUAL "/MT") + if ("${MSVC_RUNTIME_LIBRARY_CONFIG}" STREQUAL "/MT") string(REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") - ELSEIF ("${MSVC_RUNTIME_LIBRARY_CONFIG}" STREQUAL "/MD") + elseif ("${MSVC_RUNTIME_LIBRARY_CONFIG}" STREQUAL "/MD") string(REPLACE "/MT" "/MD" ${flag_var} "${${flag_var}}") - ELSE () + else () string(REPLACE "/MD" "${MSVC_RUNTIME_LIBRARY_CONFIG}" ${flag_var} "${${flag_var}}") string(REPLACE "/MT" "${MSVC_RUNTIME_LIBRARY_CONFIG}" ${flag_var} "${${flag_var}}") - ENDIF() + endif() endforeach() add_definitions(-D_UNICODE) add_definitions(-DUNICODE) add_definitions(-DWIN32_LEAN_AND_MEAN) -ELSE () +else () set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -W -Wall -Wextra -O3") -ENDIF (MSVC) +endif (MSVC) ### @@ -91,11 +91,11 @@ include_directories(${TACOPIE_INCLUDES}) ### set(SRC_DIRS "sources" "sources/network" "sources/network/common" "sources/utils" "includes/tacopie" "includes/tacopie/network" "includes/tacopie/utils") -IF (WIN32) +if (WIN32) set(SRC_DIRS ${SRC_DIRS} "sources/network/windows") -ELSE () +else () set(SRC_DIRS ${SRC_DIRS} "sources/network/unix") -ENDIF (WIN32) +endif (WIN32) foreach(dir ${SRC_DIRS}) # get directory sources and headers @@ -129,37 +129,37 @@ configure_file("tacopie.pc.in" "${CMAKE_PKGCONFIG_OUTPUT_DIRECTORY}/tacopie.pc" add_library(${PROJECT_NAME} ${SOURCES}) set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) -IF (WIN32) +if (WIN32) set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_PDB_NAME ${PROJECT_NAME} COMPILE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -ENDIF (WIN32) +endif (WIN32) -IF (WIN32) +if (WIN32) target_link_libraries(${PROJECT_NAME} ws2_32) -ELSE () +else () target_link_libraries(${PROJECT_NAME} pthread) -ENDIF (WIN32) +endif (WIN32) # __TACOPIE_LOGGING_ENABLED -IF (LOGGING_ENABLED) +if (LOGGING_ENABLED) set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __TACOPIE_LOGGING_ENABLED=${LOGGING_ENABLED}") -ENDIF (LOGGING_ENABLED) +endif (LOGGING_ENABLED) # __TACOPIE_CONNECTION_QUEUE_SIZE -IF (CONNECTION_QUEUE_SIZE) +if (CONNECTION_QUEUE_SIZE) set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __TACOPIE_CONNECTION_QUEUE_SIZE=${CONNECTION_QUEUE_SIZE}") -ENDIF (CONNECTION_QUEUE_SIZE) +endif (CONNECTION_QUEUE_SIZE) #__TACOPIE_IO_SERVICE_NB_WORKERS -IF (IO_SERVICE_NB_WORKERS) +if (IO_SERVICE_NB_WORKERS) set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __TACOPIE_IO_SERVICE_NB_WORKERS=${IO_SERVICE_NB_WORKERS}") -ENDIF(IO_SERVICE_NB_WORKERS) +endif (IO_SERVICE_NB_WORKERS) #__TACOPIE_TIMEOUT -IF (SELECT_TIMEOUT) +if (SELECT_TIMEOUT) set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __TACOPIE_TIMEOUT=${SELECT_TIMEOUT}") -ENDIF(SELECT_TIMEOUT) +endif (SELECT_TIMEOUT) ### @@ -177,17 +177,17 @@ install(DIRECTORY ${TACOPIE_INCLUDES}/ DESTINATION include USE_SOURCE_PERMISSION ### # examples ### -IF (BUILD_EXAMPLES) +if (BUILD_EXAMPLES) add_subdirectory(examples) -ENDIF(BUILD_EXAMPLES) +endif (BUILD_EXAMPLES) ### # tests ### -IF (BUILD_TESTS) +if (BUILD_TESTS) add_subdirectory(tests) ExternalProject_Add("googletest" GIT_REPOSITORY "https://github.com/google/googletest.git" CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${PROJECT_SOURCE_DIR}/deps") -ENDIF(BUILD_TESTS) +endif (BUILD_TESTS) From 7955feaa11af5125affee1abc70c9aae0ef702ce Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Fri, 22 Nov 2019 16:11:29 +0200 Subject: [PATCH 03/23] cmake: indent file, spaces only --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3295182..19b6572 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,9 +130,9 @@ add_library(${PROJECT_NAME} ${SOURCES}) set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) if (WIN32) - set_target_properties(${PROJECT_NAME} - PROPERTIES COMPILE_PDB_NAME ${PROJECT_NAME} - COMPILE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + set_target_properties(${PROJECT_NAME} PROPERTIES + COMPILE_PDB_NAME ${PROJECT_NAME} + COMPILE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) endif (WIN32) if (WIN32) @@ -188,6 +188,6 @@ endif (BUILD_EXAMPLES) if (BUILD_TESTS) add_subdirectory(tests) ExternalProject_Add("googletest" - GIT_REPOSITORY "https://github.com/google/googletest.git" - CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${PROJECT_SOURCE_DIR}/deps") + GIT_REPOSITORY "https://github.com/google/googletest.git" + CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${PROJECT_SOURCE_DIR}/deps") endif (BUILD_TESTS) From fafae1a2ef108e4b85f0464c941a65679a8a8262 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Fri, 22 Nov 2019 16:11:49 +0200 Subject: [PATCH 04/23] don't specify std=c++11 explicitly --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19b6572..435a7df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,7 +69,7 @@ if (MSVC) add_definitions(-DUNICODE) add_definitions(-DWIN32_LEAN_AND_MEAN) else () - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -W -Wall -Wextra -O3") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra -O3") endif (MSVC) From 523143f85f752e6e3c2bbc4a1f58515ca6479cd4 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Fri, 22 Nov 2019 16:12:37 +0200 Subject: [PATCH 05/23] cmake: use add_compile_options instead of CMAKE_CXX_FLAGS --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 435a7df..3af3396 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,7 +69,7 @@ if (MSVC) add_definitions(-DUNICODE) add_definitions(-DWIN32_LEAN_AND_MEAN) else () - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra -O3") + add_compile_options(-W -Wall -Wextra -O3) endif (MSVC) From 314f52e6bff0437433d4037e272801f8566c1a12 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Fri, 22 Nov 2019 16:13:12 +0200 Subject: [PATCH 06/23] cmake: move project definition to the top --- CMakeLists.txt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3af3396..c28217c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,11 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +### +# project +### +project(tacopie LANGUAGES CXX VERSION 3.2.0) + ### # config ### @@ -34,13 +39,6 @@ include(ExternalProject) ### # set(CMAKE_VERBOSE_MAKEFILE TRUE) - -### -# project -### -project(tacopie LANGUAGES CXX VERSION 3.2.0) - - ### # compilation options ### From 96798251b941fae494907f007de3c1f4bdefe645 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Fri, 22 Nov 2019 16:13:57 +0200 Subject: [PATCH 07/23] cmake: add project DESCRIPTION and HOMEPAGE_URL --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c28217c..c509f19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,11 @@ ### # project ### -project(tacopie LANGUAGES CXX VERSION 3.2.0) +project(tacopie + LANGUAGES CXX + VERSION 3.2.0 + DESCRIPTION "C++ TCP Library" + HOMEPAGE_URL "") ### # config From 231c3db6e9bc55b0bde10d8ed2a4c771fc0de018 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Fri, 22 Nov 2019 16:14:37 +0200 Subject: [PATCH 08/23] cmake: only include ExternalProject if required --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c509f19..6c1eb40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,8 +35,6 @@ project(tacopie cmake_minimum_required(VERSION 3.13) set(CMAKE_MACOSX_RPATH 1) set(CMAKE_CXX_STANDARD 11) -include(ExternalProject) - ### # verbose make @@ -189,6 +187,7 @@ endif (BUILD_EXAMPLES) ### if (BUILD_TESTS) add_subdirectory(tests) + include(ExternalProject) ExternalProject_Add("googletest" GIT_REPOSITORY "https://github.com/google/googletest.git" CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${PROJECT_SOURCE_DIR}/deps") From 773ac06680bf3fa12b5e953a23c8e1dda35189c2 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Fri, 22 Nov 2019 16:33:29 +0200 Subject: [PATCH 09/23] cmake: use target_compile_definitions() for custom build parameters --- CMakeLists.txt | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c1eb40..987344d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,24 +142,28 @@ else () endif (WIN32) # __TACOPIE_LOGGING_ENABLED +option(LOGGING_ENABLED "Enable logging" OFF) if (LOGGING_ENABLED) - set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __TACOPIE_LOGGING_ENABLED=${LOGGING_ENABLED}") -endif (LOGGING_ENABLED) + target_compile_definitions(${PROJECT_NAME} PRIVATE __TACOPIE_LOGGING_ENABLED=${LOGGING_ENABLED}) +endif () # __TACOPIE_CONNECTION_QUEUE_SIZE -if (CONNECTION_QUEUE_SIZE) - set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __TACOPIE_CONNECTION_QUEUE_SIZE=${CONNECTION_QUEUE_SIZE}") -endif (CONNECTION_QUEUE_SIZE) +set(CONNECTION_QUEUE_SIZE "" CACHE STRING "Custom connection queue size") +if (CONNECTION_QUEUE_SIZE MATCHES "^[0-9]+") + target_compile_definitions(${PROJECT_NAME} PRIVATE __TACOPIE_CONNECTION_QUEUE_SIZE=${CONNECTION_QUEUE_SIZE}) +endif () #__TACOPIE_IO_SERVICE_NB_WORKERS -if (IO_SERVICE_NB_WORKERS) - set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __TACOPIE_IO_SERVICE_NB_WORKERS=${IO_SERVICE_NB_WORKERS}") -endif (IO_SERVICE_NB_WORKERS) +set(IO_SERVICE_NB_WORKERS "" CACHE STRING "Number of service workers") +if (IO_SERVICE_NB_WORKERS MATCHES "^[1-9]+") + target_compile_definitions(${PROJECT_NAME} PRIVATE __TACOPIE_IO_SERVICE_NB_WORKERS=${IO_SERVICE_NB_WORKERS}) +endif () #__TACOPIE_TIMEOUT -if (SELECT_TIMEOUT) - set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __TACOPIE_TIMEOUT=${SELECT_TIMEOUT}") -endif (SELECT_TIMEOUT) +set(SELECT_TIMEOUT "" CACHE STRING "Select timeout") +if (SELECT_TIMEOUT MATCHES "^[0-9]+") + target_compile_definitions(${PROJECT_NAME} PRIVATE __TACOPIE_TIMEOUT=${SELECT_TIMEOUT}) +endif () ### From 38bfb70f96b91e76d2f2e8026afc0269d41c8768 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Fri, 22 Nov 2019 16:34:34 +0200 Subject: [PATCH 10/23] cmake: remove endif() matchers --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 987344d..7e9e1a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,7 +70,7 @@ if (MSVC) add_definitions(-DWIN32_LEAN_AND_MEAN) else () add_compile_options(-W -Wall -Wextra -O3) -endif (MSVC) +endif () ### @@ -95,7 +95,7 @@ if (WIN32) set(SRC_DIRS ${SRC_DIRS} "sources/network/windows") else () set(SRC_DIRS ${SRC_DIRS} "sources/network/unix") -endif (WIN32) +endif () foreach(dir ${SRC_DIRS}) # get directory sources and headers @@ -133,13 +133,13 @@ if (WIN32) set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_PDB_NAME ${PROJECT_NAME} COMPILE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -endif (WIN32) +endif () if (WIN32) target_link_libraries(${PROJECT_NAME} ws2_32) else () target_link_libraries(${PROJECT_NAME} pthread) -endif (WIN32) +endif () # __TACOPIE_LOGGING_ENABLED option(LOGGING_ENABLED "Enable logging" OFF) From 798d5cc05fb5d8079aef41e177c904baa41a18b5 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Fri, 22 Nov 2019 16:34:56 +0200 Subject: [PATCH 11/23] cmake: specify private linkage for dependencies --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e9e1a3..3a2fcb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,9 +136,9 @@ if (WIN32) endif () if (WIN32) - target_link_libraries(${PROJECT_NAME} ws2_32) + target_link_libraries(${PROJECT_NAME} PRIVATE ws2_32) else () - target_link_libraries(${PROJECT_NAME} pthread) + target_link_libraries(${PROJECT_NAME} PRIVATE pthread) endif () # __TACOPIE_LOGGING_ENABLED From 2465c74ba56d101bfeb5a86f2818cd19445e0fab Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Fri, 22 Nov 2019 16:35:29 +0200 Subject: [PATCH 12/23] cmake: declare library target as static --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a2fcb6..b9e3de8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,7 +126,7 @@ configure_file("tacopie.pc.in" "${CMAKE_PKGCONFIG_OUTPUT_DIRECTORY}/tacopie.pc" ### # executable ### -add_library(${PROJECT_NAME} ${SOURCES}) +add_library(${PROJECT_NAME} STATIC ${SOURCES}) set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) if (WIN32) From 931df3f986692450d66c3bb19ddb4b6f61aad539 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Fri, 22 Nov 2019 16:35:51 +0200 Subject: [PATCH 13/23] cmake: enable PROJECT_VERSION --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b9e3de8..3085db0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ ### # project ### +cmake_policy(SET CMP0048 NEW) project(tacopie LANGUAGES CXX VERSION 3.2.0 From 5561136e9aa677b978711bf205d8b3c8538ee881 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Fri, 22 Nov 2019 16:47:28 +0200 Subject: [PATCH 14/23] cmake: remove unused variables --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3085db0..88e71af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,8 +77,6 @@ endif () ### # variables ### -set(DEPS_INCLUDES ${PROJECT_SOURCE_DIR}/deps/include) -set(DEPS_LIBRARIES ${PROJECT_SOURCE_DIR}/deps/lib) set(TACOPIE_INCLUDES ${PROJECT_SOURCE_DIR}/includes) From ae52ffe98973b19bed64eaa2e06c75a15da69000 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Fri, 22 Nov 2019 16:47:41 +0200 Subject: [PATCH 15/23] cmake: use add_compile_options instead of CMAKE_CXX_FLAGS --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 88e71af..9054a9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ set(CMAKE_CXX_STANDARD 11) # compilation options ### if (MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /O2 /bigobj") + add_compile_options(/W3 /O2 /bigobj) # was causing conflics with gtest build string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) From d3763fcd95442c545192c9a0260e7918af9e93d3 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Sat, 23 Nov 2019 12:29:31 +0200 Subject: [PATCH 16/23] cmake: explicitly set library source files The recommended method is to explicitly list all sources files for targets. This way build configuration only needs to change if CMakeFiles.txt is explicitly modified. There's no confusion about what files are part of the build. --- CMakeLists.txt | 42 +++++------------------------------------- sources.cmake | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 37 deletions(-) create mode 100644 sources.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 9054a9a..e14084c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,39 +73,7 @@ else () add_compile_options(-W -Wall -Wextra -O3) endif () - -### -# variables -### -set(TACOPIE_INCLUDES ${PROJECT_SOURCE_DIR}/includes) - - -### -# includes -### -include_directories(${TACOPIE_INCLUDES}) - -### -# sources -### -set(SRC_DIRS "sources" "sources/network" "sources/network/common" "sources/utils" "includes/tacopie" "includes/tacopie/network" "includes/tacopie/utils") - -if (WIN32) - set(SRC_DIRS ${SRC_DIRS} "sources/network/windows") -else () - set(SRC_DIRS ${SRC_DIRS} "sources/network/unix") -endif () - -foreach(dir ${SRC_DIRS}) - # get directory sources and headers - file(GLOB s_${dir} "${dir}/*.cpp") - file(GLOB h_${dir} "${dir}/*.hpp") - file(GLOB i_${dir} "${dir}/*.ipp") - - # set sources - set(SOURCES ${SOURCES} ${s_${dir}} ${h_${dir}} ${i_${dir}}) -endforeach() - +include(sources.cmake) ### # outputs @@ -115,7 +83,6 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_PKGCONFIG_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/pkgconfig) - ### # pkg-config ### @@ -125,8 +92,9 @@ configure_file("tacopie.pc.in" "${CMAKE_PKGCONFIG_OUTPUT_DIRECTORY}/tacopie.pc" ### # executable ### -add_library(${PROJECT_NAME} STATIC ${SOURCES}) +add_library(${PROJECT_NAME} STATIC ${tacopie_sources}) set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) +target_include_directories(${PROJECT_NAME} PUBLIC ${tacopie_includes}) if (WIN32) set_target_properties(${PROJECT_NAME} PROPERTIES @@ -164,7 +132,6 @@ if (SELECT_TIMEOUT MATCHES "^[0-9]+") target_compile_definitions(${PROJECT_NAME} PRIVATE __TACOPIE_TIMEOUT=${SELECT_TIMEOUT}) endif () - ### # install ### @@ -174,7 +141,8 @@ install(CODE "FILE(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})") # install tacopie install(DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/ DESTINATION lib USE_SOURCE_PERMISSIONS) install(DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ DESTINATION bin USE_SOURCE_PERMISSIONS) -install(DIRECTORY ${TACOPIE_INCLUDES}/ DESTINATION include USE_SOURCE_PERMISSIONS) +# NOTE: this fails if more directories are added to ${tacopie_includes} +install(DIRECTORY ${tacopie_includes}/ DESTINATION include USE_SOURCE_PERMISSIONS) ### diff --git a/sources.cmake b/sources.cmake new file mode 100644 index 0000000..85620c1 --- /dev/null +++ b/sources.cmake @@ -0,0 +1,26 @@ +### +# sources +### +set(tacopie_sources + sources/network/common/tcp_socket.cpp + sources/network/io_service.cpp + sources/network/tcp_client.cpp + sources/network/tcp_server.cpp + sources/utils/error.cpp + sources/utils/logger.cpp + sources/utils/thread_pool.cpp) + +if (MSVC) + list(APPEND tacopie_sources + sources/network/windows/windows_self_pipe.cpp + sources/network/windows/windows_tcp_socket.cpp) +else() + list(APPEND tacopie_sources + sources/network/unix/unix_self_pipe.cpp + sources/network/unix/unix_tcp_socket.cpp) +endif() + +### +# includes +### +set(tacopie_includes ${PROJECT_SOURCE_DIR}/includes) From 2968ee004b33d33a02bf131d356bfe8f3a505bf4 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Sat, 23 Nov 2019 12:33:17 +0200 Subject: [PATCH 17/23] cmake: add options for implicit user configurable settings Each user configurable setting should have a corresponding option() for booleans or typed cache variable for strings and paths. --- CMakeLists.txt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e14084c..897a151 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,14 +34,11 @@ project(tacopie # config ### cmake_minimum_required(VERSION 3.13) +option(VERBOSE_MAKEFILE "Generate verbose output from Makefile builds" OFF) +set(CMAKE_VERBOSE_MAKEFILE ${VERBOSE_MAKEFILE}) set(CMAKE_MACOSX_RPATH 1) set(CMAKE_CXX_STANDARD 11) -### -# verbose make -### -# set(CMAKE_VERBOSE_MAKEFILE TRUE) - ### # compilation options ### @@ -148,18 +145,20 @@ install(DIRECTORY ${tacopie_includes}/ DESTINATION include USE_SOURCE_PERMISSION ### # examples ### +option(BUILD_EXAMPLES "Build examples" OFF) if (BUILD_EXAMPLES) add_subdirectory(examples) -endif (BUILD_EXAMPLES) +endif () ### # tests ### +option(BUILD_TESTS "Build tests" OFF) if (BUILD_TESTS) add_subdirectory(tests) include(ExternalProject) ExternalProject_Add("googletest" GIT_REPOSITORY "https://github.com/google/googletest.git" CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${PROJECT_SOURCE_DIR}/deps") -endif (BUILD_TESTS) +endif () From 79a7a947f53ecb4c6bc51c47c4b1a2fff6d3582a Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Sat, 23 Nov 2019 12:35:47 +0200 Subject: [PATCH 18/23] cmake: build a shared library The original library type was unclear, but POSITION_INDEPENDENT_CODE would hint that shared library was intended. CMake automatically enables PIC for shared libraries and modules. --- CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 897a151..fe46fb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,12 +85,10 @@ set(CMAKE_PKGCONFIG_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/pkgconfig ### configure_file("tacopie.pc.in" "${CMAKE_PKGCONFIG_OUTPUT_DIRECTORY}/tacopie.pc" @ONLY) - ### # executable ### -add_library(${PROJECT_NAME} STATIC ${tacopie_sources}) -set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) +add_library(${PROJECT_NAME} SHARED ${tacopie_sources}) target_include_directories(${PROJECT_NAME} PUBLIC ${tacopie_includes}) if (WIN32) From c9bbfed4dcd9d6cb704cc7e2638df67e6f032eb5 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Sat, 23 Nov 2019 12:38:11 +0200 Subject: [PATCH 19/23] cmake: minor fixes and comments --- CMakeLists.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe46fb4..8a12497 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,10 @@ if (MSVC) # was causing conflics with gtest build string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) - + # CMake 3.15 has support for automatically configuring MSVC runtime + # through target property MSVC_RUNTIME_LIBRARY. Since I'm not + # planning on supporting old CMake versions I will most likely bump + # cmake_minimum_required to 3.15 at some point. if ("${MSVC_RUNTIME_LIBRARY_CONFIG}" STREQUAL "") set(MSVC_RUNTIME_LIBRARY_CONFIG "/MT") endif () @@ -131,8 +134,8 @@ endif () # install ### # ensure lib and bin directories exist -install(CODE "FILE(MAKE_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})") -install(CODE "FILE(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})") +install(CODE "file(MAKE_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})") +install(CODE "file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})") # install tacopie install(DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/ DESTINATION lib USE_SOURCE_PERMISSIONS) install(DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ DESTINATION bin USE_SOURCE_PERMISSIONS) From 30212cc91b4666a5dc2b81b2183ff1dddd0dea16 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Sat, 23 Nov 2019 12:38:42 +0200 Subject: [PATCH 20/23] cmake: use FindThreads to determine thread library The package creates an imported target Threads::Threads that configures the correct library. --- CMakeLists.txt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a12497..3f42822 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,11 +100,8 @@ if (WIN32) COMPILE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) endif () -if (WIN32) - target_link_libraries(${PROJECT_NAME} PRIVATE ws2_32) -else () - target_link_libraries(${PROJECT_NAME} PRIVATE pthread) -endif () +find_package(Threads REQUIRED) +target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads) # __TACOPIE_LOGGING_ENABLED option(LOGGING_ENABLED "Enable logging" OFF) From 4cec14049523ae166d90c6d44d7a60c5a14aac3a Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Sat, 23 Nov 2019 12:40:41 +0200 Subject: [PATCH 21/23] cmake: rewrite tests/CMakeLists.txt The test directory doesn't need to be a project, in fact it SHOULDN'T be a project. All necessary flags etc. should be set by the library target the tests link against. --- tests/CMakeLists.txt | 50 +++++--------------------------------------- 1 file changed, 5 insertions(+), 45 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b732b75..5bd0747 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -20,55 +20,15 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -### -# project -### -set(PROJECT tacopie_tests) -project(${PROJECT} CXX) - - -### -# compilation options -### -IF (NOT WIN32) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") -ENDIF (NOT WIN32) - - -### -# includes -### -include_directories(${DEPS_INCLUDES} ${TACOPIE_INCLUDES}) - - -### -# libraries -### -link_directories(${DEPS_LIBRARIES}) - - ### # sources ### -set(SOURCES "") -set(DIRS "sources" "sources/spec" "sources/spec/**") -foreach(dir ${DIRS}) - # get directory sources - file(GLOB s_${dir} "${dir}/*.cpp") - # set sources - set(SOURCES ${SOURCES} ${s_${dir}}) -endforeach() - +set(tacopie_test_sources + sources/main.cpp) ### # executable ### -add_executable(${PROJECT} ${SOURCES}) - -target_link_libraries(${PROJECT} tacopie gtest) - -IF (WIN32) - target_link_libraries(${PROJECT} ws2_32) -ELSE () - target_link_libraries(${PROJECT} pthread) -ENDIF (WIN32) +add_executable(${PROJECT_NAME}_tests ${tacopie_test_sources}) +target_link_libraries(${PROJECT_NAME}_tests PRIVATE ${PROJECT_NAME} gtest) +add_test(NAME ${PROJECT_NAME}::tests COMMAND ${PROJECT_NAME}_tests) From 9e9d055a8748f305af736ea9846b25ec46b2a2ce Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Sat, 23 Nov 2019 12:43:30 +0200 Subject: [PATCH 22/23] add googletest as a submodule ExternalProject used the most recent version of gtest which will eventually lead to failing tests. Pin the version using a submodule. --- .gitmodules | 3 +++ CMakeLists.txt | 10 ++++++---- googletest | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 .gitmodules create mode 160000 googletest diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..8cf8b5e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "googletest"] + path = googletest + url = https://github.com/google/googletest.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f42822..48be4b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,9 @@ ### # project ### +# see cmake --help-policy CMP cmake_policy(SET CMP0048 NEW) +cmake_policy(SET CMP0077 NEW) project(tacopie LANGUAGES CXX VERSION 3.2.0 @@ -154,9 +156,9 @@ endif () ### option(BUILD_TESTS "Build tests" OFF) if (BUILD_TESTS) + if (NOT TARGET gtest) + set(INSTALL_GTEST OFF) + add_subdirectory(googletest) + endif () add_subdirectory(tests) - include(ExternalProject) - ExternalProject_Add("googletest" - GIT_REPOSITORY "https://github.com/google/googletest.git" - CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${PROJECT_SOURCE_DIR}/deps") endif () diff --git a/googletest b/googletest new file mode 160000 index 0000000..703bd9c --- /dev/null +++ b/googletest @@ -0,0 +1 @@ +Subproject commit 703bd9caab50b139428cea1aaff9974ebee5742e From 0a13c7ad7e30f9c9c794ab3ad9863f6e284c5a94 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom Date: Tue, 26 Nov 2019 14:18:54 +0200 Subject: [PATCH 23/23] cmake: install only build targets and pkgconfig file Adding SOVERSION property to the target makes CMake generate symlinks during installation. The RESOURCE property is supported by install(TARGETS) and can be used to automatically install *.pc files. The install(TARGETS) call specifies an EXPORT target name, initialized to PROJECT_NAME, that can be used when adding this repository as a submodule: set(EXPORT_TARGET_NAME myproj) add_subdirectory(tacopie) install(TARGETS myexe EXPORT myproj RUNTIME) install(EXPORT myproj DESTINATION lib/myproj) The last line will generate ${PREFIX}/lib/myproj/myproj.cmake that contains necessary CMake spells to include the installed files in another projects as CMake targets. Somewhat like pkg-config, but nicer for Windows people. --- CMakeLists.txt | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48be4b0..9e8292f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,8 @@ set(CMAKE_VERBOSE_MAKEFILE ${VERBOSE_MAKEFILE}) set(CMAKE_MACOSX_RPATH 1) set(CMAKE_CXX_STANDARD 11) +set(EXPORT_TARGET_NAME ${PROJECT_NAME} CACHE STRING "Name of the exported CMake target used in install(EXPORT)") + ### # compilation options ### @@ -94,7 +96,9 @@ configure_file("tacopie.pc.in" "${CMAKE_PKGCONFIG_OUTPUT_DIRECTORY}/tacopie.pc" # executable ### add_library(${PROJECT_NAME} SHARED ${tacopie_sources}) -target_include_directories(${PROJECT_NAME} PUBLIC ${tacopie_includes}) +target_include_directories(${PROJECT_NAME} PUBLIC + $ + $) if (WIN32) set_target_properties(${PROJECT_NAME} PROPERTIES @@ -102,6 +106,10 @@ if (WIN32) COMPILE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) endif () +set_target_properties(${PROJECT_NAME} PROPERTIES + SOVERSION ${PROJECT_VERSION} + RESOURCE ${CMAKE_PKGCONFIG_OUTPUT_DIRECTORY}/tacopie.pc) + find_package(Threads REQUIRED) target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads) @@ -132,15 +140,12 @@ endif () ### # install ### -# ensure lib and bin directories exist -install(CODE "file(MAKE_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})") -install(CODE "file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})") -# install tacopie -install(DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/ DESTINATION lib USE_SOURCE_PERMISSIONS) -install(DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ DESTINATION bin USE_SOURCE_PERMISSIONS) # NOTE: this fails if more directories are added to ${tacopie_includes} +include(GNUInstallDirs) install(DIRECTORY ${tacopie_includes}/ DESTINATION include USE_SOURCE_PERMISSIONS) - +install(TARGETS ${PROJECT_NAME} EXPORT ${EXPORT_TARGET_NAME} + LIBRARY + RESOURCE DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) ### # examples