-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·124 lines (104 loc) · 4.82 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
cmake_minimum_required(VERSION 2.8.4)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
include(cotire OPTIONAL)
project(cBattleship)
set(CMAKE_CXX_FLAGS "-std=c++11 -DBOOST_LOG_DYN_LINK")
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREAD ON)
find_package(Boost 1.55.0 REQUIRED COMPONENTS thread system filesystem log log_setup signals)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
endif(Boost_FOUND)
# use pkg-config to find gtk3
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(GTKMM REQUIRED gtkmm-3.0)
include_directories(${GTKMM_INCLUDE_DIRS})
link_directories(${GTKMM_LIBRARY_DIRS})
add_definitions(${GTKMM_CFLAGS_OTHER})
endif(PKG_CONFIG_FOUND)
# add src to include directories so, every module can include headers
# from common
include_directories(${PROJECT_SOURCE_DIR}/src)
# common library
set(CBATTLESHIP_COMMON_SOURCE_PATH ${PROJECT_SOURCE_DIR}/src/common)
file(GLOB_RECURSE CBATTLESHIP_COMMON_SOURCE_FILES ${CBATTLESHIP_COMMON_SOURCE_PATH}/*.cpp)
add_library(cbattleship-common ${CBATTLESHIP_COMMON_SOURCE_FILES})
target_link_libraries(cbattleship-common ${Boost_LIBRARIES})
if(COMMAND cotire)
cotire(cbattleship-common)
endif()
# server
set(CBATTLESHIP_SERVER_SOURCE_PATH ${PROJECT_SOURCE_DIR}/src/server)
file(GLOB_RECURSE CBATTLESHIP_SERVER_SOURCE_FILES ${CBATTLESHIP_SERVER_SOURCE_PATH}/*.cpp)
add_executable(cbattleship-server ${CBATTLESHIP_SERVER_SOURCE_FILES})
target_link_libraries(cbattleship-server cbattleship-common ${Boost_LIBRARIES} pthread)
if(COMMAND cotire)
cotire(cbattleship-server)
endif()
# client library
set(CBATTLESHIP_CLIENTLIB_SOURCE_PATH ${PROJECT_SOURCE_DIR}/src/clientlib)
file(GLOB_RECURSE CBATTLESHIP_CLIENTLIB_SOURCE_FILES ${CBATTLESHIP_CLIENTLIB_SOURCE_PATH}/*.cpp)
add_library(cbattleship-clientlib ${CBATTLESHIP_CLIENTLIB_SOURCE_FILES})
target_link_libraries(cbattleship-clientlib cbattleship-common ${Boost_LIBRARIES} pthread)
if(COMMAND cotire)
cotire(cbattleship-clientlib)
endif()
# curses client
set(CBATTLESHIP_CLIENT_SOURCE_PATH ${PROJECT_SOURCE_DIR}/src/client)
file(GLOB_RECURSE CBATTLESHIP_CLIENT_SOURCE_FILES ${CBATTLESHIP_CLIENT_SOURCE_PATH}/*.cpp)
add_executable(cbattleship-curses-client ${CBATTLESHIP_CLIENT_SOURCE_FILES})
target_link_libraries(cbattleship-curses-client cbattleship-clientlib ${Boost_LIBRARIES})
if(COMMAND cotire)
cotire(cbattleship-curses-client)
endif()
# text client
set(CBATTLESHIP_SIMPLE_CLIENT_SOURCE_PATH ${PROJECT_SOURCE_DIR}/src/text-client)
file(GLOB_RECURSE CBATTLESHIP_SIMPLE_CLIENT_SOURCE_FILES ${CBATTLESHIP_SIMPLE_CLIENT_SOURCE_PATH}/*.cpp)
add_executable(cbattleship-text-client ${CBATTLESHIP_SIMPLE_CLIENT_SOURCE_FILES})
target_link_libraries(cbattleship-text-client cbattleship-clientlib ${Boost_LIBRARIES} pthread)
if(COMMAND cotire)
cotire(cbattleship-text-client)
endif()
# gtk client
if(PKG_CONFIG_FOUND)
set(CBATTLESHIP_GTK_CLIENT_SOURCE_PATH ${PROJECT_SOURCE_DIR}/src/gtk-client)
configure_file(${CBATTLESHIP_GTK_CLIENT_SOURCE_PATH}/gui-design.glade ${PROJECT_BINARY_DIR}/gui-design.glade COPYONLY)
file(GLOB_RECURSE CBATTLESHIP_GTK_CLIENT_SOURCE_FILES ${CBATTLESHIP_GTK_CLIENT_SOURCE_PATH}/*.cpp)
add_executable(cbattleship-gtk-client ${CBATTLESHIP_GTK_CLIENT_SOURCE_FILES})
target_link_libraries(cbattleship-gtk-client cbattleship-common ${Boost_LIBRARIES} ${GTKMM_LIBRARIES})
if(COMMAND cotire)
cotire(cbattleship-gtk-client)
endif()
endif(PKG_CONFIG_FOUND)
# test cases
set(CBATTLESHIP_TEST_SOURCE_PATH ${PROJECT_SOURCE_DIR}/src/test)
file(GLOB_RECURSE CBATTLESHIP_TEST_SOURCE_FILES ${CBATTLESHIP_TEST_SOURCE_PATH}/*.cpp)
add_executable(cbattleship-unit-tests ${CBATTLESHIP_TEST_SOURCE_FILES})
target_link_libraries(cbattleship-unit-tests cbattleship-common cppunit)
if(COMMAND cotire)
cotire(cbattleship-unit-tests)
endif()
# use ncurses library
set(CURSES_NEED_NCURSES TRUE)
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
target_link_libraries(cbattleship-curses-client pdcurses)
else()
target_link_libraries(cbattleship-curses-client curses)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(cbattleship-curses-client rt)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
endif()
# automatically run tests after build
enable_testing()
set(BUILD_TESTING ON)
add_test(NAME unit-tests COMMAND ${PROJECT_BINARY_DIR}/cbattleship-unit-tests)
add_test(NAME edge-bot-test COMMAND ${PROJECT_SOURCE_DIR}/scripts/tests/edge-bot-test ${PROJECT_BINARY_DIR})
# compile documentation graphs
find_program(DOT NAMES dot)
add_custom_command(OUTPUT network-sequence.png
COMMAND ${DOT} -Tpng ${PROJECT_SOURCE_DIR}/doc/network-sequence.dot > ${PROJECT_BINARY_DIR}/network-sequence.png
DEPENDS ${PROJECT_SOURCE_DIR}/doc/network-sequence.dot)
add_custom_target(doc
DEPENDS network-sequence.png)