-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
69 lines (59 loc) · 1.69 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
cmake_minimum_required (VERSION 3.9...3.14)
project (AsioClientServer
VERSION 0.1
DESCRIPTION "Tcp client-server program using Asio and Protobuf."
LANGUAGES CXX
)
include(CTest)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra")
# thread library
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads) # REQUIRED ?
# find Asio headers
# uses standalone Asio (without Boost dependencies)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
find_package(Asio REQUIRED)
if(Asio_FOUND)
message ("Asio include dirs: ${Asio_INCLUDE_DIRS}")
endif()
# find the Protobuf compiler and libraries
find_package(Protobuf REQUIRED)
if(Protobuf_FOUND)
message ("Protobuf include dir: ${Protobuf_INCLUDE_DIRS}")
endif()
add_subdirectory(common)
add_subdirectory(client)
add_subdirectory(server)
if(BUILD_TESTING)
# TODO find GTest, GMock
# find_package(GTest)
# see subdirs:
# common/tests
# server/tests
# client/tests
if(NOT TARGET commonTests)
add_custom_target(commonTests) # empty
endif()
if(NOT TARGET serverTests)
add_custom_target(serverTests) # empty
endif()
if(NOT TARGET clientTests)
add_custom_target(clientTests) # empty
endif()
add_custom_target(AllTests ALL)
add_dependencies(AllTests
commonTests
serverTests
clientTests
)
add_custom_command(TARGET AllTests
COMMENT "Run tests"
POST_BUILD
COMMAND ctest #-C $<CONFIGURATION> --output-on-failure
# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
else()
message ("Building of tests is disabled")
endif()