From f1d749e3cd3aaa5ec875ea29ca010b73d3174f2c Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 7 Apr 2021 00:26:56 +0300 Subject: cmake: slight CMakeLists.txt refactoring --- CMakeLists.txt | 2 -- client/CMakeLists.txt | 12 +++++------- server/common/CMakeLists.txt | 6 +++--- server/lexer/CMakeLists.txt | 5 ++--- server/main/CMakeLists.txt | 13 +++++-------- server/parser/CMakeLists.txt | 1 - test/benchmarks/CMakeLists.txt | 3 --- test/unit_tests/CMakeLists.txt | 14 +++++++------- 8 files changed, 22 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f68e3c9..35484bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,7 @@ cmake_minimum_required(VERSION 3.8) # for C++17 project(math_server CXX) - enable_testing() -option(MATH_SERVER_TESTS "build the tests") # C++17 is mandatory: set(CC_CXX_STANDARD 17) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 0343ee2..1891e90 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,17 +1,15 @@ -file(GLOB client_src "*.cpp" "*.hpp") -add_executable(client ${client_src}) -set_target_properties(client PROPERTIES OUTPUT_NAME math-client) - +find_package(Boost 1.66.0 REQUIRED COMPONENTS filesystem program_options) set(CMAKE_THREAD_PREFER_PTHREAD ON) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) -target_link_libraries(client PRIVATE Threads::Threads) -find_package(Boost 1.66.0 REQUIRED COMPONENTS filesystem program_options) +file(GLOB client_src "*.cpp" "*.hpp") +add_executable(client ${client_src}) +set_target_properties(client PROPERTIES OUTPUT_NAME math-client) +target_link_libraries(client PRIVATE Threads::Threads) target_link_libraries(client PRIVATE Boost::disable_autolinking Boost::filesystem Boost::program_options) - install(TARGETS client RUNTIME DESTINATION bin) install_pdbs(TARGETS client DESTINATION bin) diff --git a/server/common/CMakeLists.txt b/server/common/CMakeLists.txt index f3d6605..77e35f0 100644 --- a/server/common/CMakeLists.txt +++ b/server/common/CMakeLists.txt @@ -1,5 +1,5 @@ +find_package(Boost REQUIRED) + add_library(common INTERFACE) target_include_directories(common INTERFACE ..) - -find_package(Boost REQUIRED) -target_link_libraries(common INTERFACE Boost::boost) +target_link_libraries(common INTERFACE Boost::disable_autolinking Boost::boost) diff --git a/server/lexer/CMakeLists.txt b/server/lexer/CMakeLists.txt index 68914d9..1f053a6 100644 --- a/server/lexer/CMakeLists.txt +++ b/server/lexer/CMakeLists.txt @@ -1,8 +1,7 @@ +find_package(Boost REQUIRED COMPONENTS regex) + file(GLOB_RECURSE lexer_src "*.cpp" "*.hpp") add_library(lexer ${lexer_src}) target_include_directories(lexer PUBLIC ..) - target_link_libraries(lexer PUBLIC common) - -find_package(Boost REQUIRED COMPONENTS regex) target_link_libraries(lexer PRIVATE Boost::disable_autolinking Boost::regex) diff --git a/server/main/CMakeLists.txt b/server/main/CMakeLists.txt index 22853a7..da5d8b9 100644 --- a/server/main/CMakeLists.txt +++ b/server/main/CMakeLists.txt @@ -1,3 +1,8 @@ +find_package(Boost 1.66.0 REQUIRED COMPONENTS filesystem program_options) +set(CMAKE_THREAD_PREFER_PTHREAD ON) +set(THREADS_PREFER_PTHREAD_FLAG ON) +find_package(Threads REQUIRED) + option(DEBUG_ASIO "enable debug output for Boost.Asio" OFF) file(GLOB server_src "*.cpp" "*.hpp") @@ -6,19 +11,11 @@ set_target_properties(server PROPERTIES OUTPUT_NAME math-server) if(DEBUG_ASIO) target_compile_definitions(server PRIVATE BOOST_ASIO_ENABLE_HANDLER_TRACKING) endif() - target_link_libraries(server PRIVATE common parser) - -set(CMAKE_THREAD_PREFER_PTHREAD ON) -set(THREADS_PREFER_PTHREAD_FLAG ON) -find_package(Threads REQUIRED) target_link_libraries(server PRIVATE Threads::Threads) - -find_package(Boost 1.66.0 REQUIRED COMPONENTS filesystem program_options) target_link_libraries(server PRIVATE Boost::disable_autolinking Boost::filesystem Boost::program_options) - install(TARGETS server RUNTIME DESTINATION bin) install_pdbs(TARGETS server DESTINATION bin) diff --git a/server/parser/CMakeLists.txt b/server/parser/CMakeLists.txt index a426c6a..27b4153 100644 --- a/server/parser/CMakeLists.txt +++ b/server/parser/CMakeLists.txt @@ -1,4 +1,3 @@ add_library(parser INTERFACE) target_include_directories(parser INTERFACE ..) - target_link_libraries(parser INTERFACE common lexer) diff --git a/test/benchmarks/CMakeLists.txt b/test/benchmarks/CMakeLists.txt index 190ae8f..ea419a6 100644 --- a/test/benchmarks/CMakeLists.txt +++ b/test/benchmarks/CMakeLists.txt @@ -1,11 +1,8 @@ file(GLOB benchmarks_src "*.cpp") add_executable(benchmarks ${benchmarks_src}) set_target_properties(benchmarks PROPERTIES OUTPUT_NAME math-server-benchmarks) - target_link_libraries(benchmarks PRIVATE lexer) - target_link_libraries(benchmarks PRIVATE benchmark benchmark_main) - install(TARGETS benchmarks RUNTIME DESTINATION bin) install_pdbs(TARGETS benchmarks DESTINATION bin) diff --git a/test/unit_tests/CMakeLists.txt b/test/unit_tests/CMakeLists.txt index b9f87bf..312d2f9 100644 --- a/test/unit_tests/CMakeLists.txt +++ b/test/unit_tests/CMakeLists.txt @@ -1,14 +1,14 @@ -file(GLOB unit_tests_src "*.cpp") -add_executable(unit_tests ${unit_tests_src}) -set_target_properties(unit_tests PROPERTIES OUTPUT_NAME math-server-unit-tests) - -target_link_libraries(unit_tests PRIVATE lexer parser) - find_package(Boost 1.67.0 REQUIRED COMPONENTS unit_test_framework) # It would be Boost 1.66 in a perfect world, but the tests fail to compile with # that: https://lists.boost.org/boost-bugs/2018/01/49711.php. -target_link_libraries(unit_tests PRIVATE Boost::disable_autolinking Boost::unit_test_framework) +file(GLOB unit_tests_src "*.cpp") +add_executable(unit_tests ${unit_tests_src}) +set_target_properties(unit_tests PROPERTIES OUTPUT_NAME math-server-unit-tests) +target_link_libraries(unit_tests PRIVATE lexer parser) +target_link_libraries(unit_tests PRIVATE + Boost::disable_autolinking + Boost::unit_test_framework) install(TARGETS unit_tests RUNTIME DESTINATION bin) install_pdbs(TARGETS unit_tests DESTINATION bin) -- cgit v1.2.3