CMakeLists.txt 6.17 KB
Newer Older
dionisos's avatar
dionisos committed
1
cmake_minimum_required(VERSION 2.6)
2
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
dionisos's avatar
dionisos committed
3

dionisos's avatar
dionisos committed
4

5 6 7 8 9
##########################
# Project definition
##########################

project(batajelo)
10

dionisos's avatar
dionisos committed
11
set(batajelo_VERSION_MAJOR 0)
12
set(batajelo_VERSION_MINOR 1)
13 14 15 16

##########################
# Project compile flags
##########################
dionisos's avatar
dionisos committed
17

18 19 20
# This flag is very important for the fixmath library, if one client is
# compiled without it, its world representation may not be identical with
# the other’s one.
21
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFIXMATH_SIN_LUT")
22

23
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -pedantic -Wall -Wextra")
louiz’'s avatar
louiz’ committed
24
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -pedantic -Wall -Wextra -Weffc++")
25

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
configure_file("${PROJECT_SOURCE_DIR}/src/config.hpp.in" "${PROJECT_SOURCE_DIR}/src/config.hpp")

##########################
# Command line options
##########################

set(BUILD_SERVER true)
option(BUILD_SERVER "build the server" ${BUILD_SERVER})

set(BUILD_CLIENT true)
option(BUILD_CLIENT "build the server" ${BUILD_CLIENT})


##########################
# Libraries look up
##########################
dionisos's avatar
dionisos committed
42

43
find_package(Boost 1.48.0 COMPONENTS filesystem system iostreams locale serialization chrono REQUIRED)
44
find_package(Cryptopp REQUIRED)
45
find_package(Protobuf REQUIRED)
46 47 48 49 50

if(BUILD_CLIENT)
  find_package(SFML 2 REQUIRED system window graphics audio)
endif()

louiz’'s avatar
louiz’ committed
51 52
find_package(GTest)

53 54 55
##########################
# Includes and Linkage
##########################
dionisos's avatar
dionisos committed
56

57 58
include_directories("src/")

dionisos's avatar
dionisos committed
59
include_directories(${Boost_INCLUDE_DIR})
60
include_directories(${CRYPTO++_INCLUDE_DIR})
61
include_directories(${PROTOBUF_INCLUDE_DIRS})
louiz’'s avatar
louiz’ committed
62 63 64
if(GTEST_FOUND)
  include_directories(${GTEST_INCLUDE_DIRS})
endif()
dionisos's avatar
dionisos committed
65 66

link_directories(${Boost_LIBRARY_DIRS})
67
link_directories(${CRYPTO++_LIBRARIES})
dionisos's avatar
dionisos committed
68

69 70 71
##########################
# Targets
##########################
dionisos's avatar
dionisos committed
72

73
if(BUILD_CLIENT)
74 75
  add_executable(batajelo_client src/main/batajelo_client.cpp)
  target_link_libraries(batajelo_client
louiz’'s avatar
louiz’ committed
76 77
    game_client
    client
78 79 80
    gui
    )
endif()
81 82

if(BUILD_SERVER)
83 84 85 86
  add_executable(batajelo_server src/main/batajelo_server.cpp)
  target_link_libraries(batajelo_server
    server
    )
87
endif(BUILD_SERVER)
dionisos's avatar
dionisos committed
88

89

90 91 92 93 94 95 96 97 98 99 100 101 102 103
#########################
# Project libraries
#########################

#
## Config
#
file(GLOB source_config
  src/config/config.[hc]pp
  )

add_library(config STATIC ${source_config})

target_link_libraries(config
104
  utils
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
  )

#
## Logging
#
file(GLOB source_logging
  src/logging/logging.[hc]pp
  )

add_library(logging STATIC ${source_logging})

target_link_libraries(logging
  config
  ${Boost_LIBRARIES}
  )
120

121 122 123 124 125 126 127 128
#
## fixmath
#
file(GLOB source_fixmath
  src/fixmath/*.c
  src/fixmath/*.cpp
  )

129 130
add_library(fixmath STATIC ${source_fixmath})

131 132 133 134 135 136
#
## Utils
#
file(GLOB source_utils
  src/utils/*.[hc]pp
  )
dionisos's avatar
dionisos committed
137

138 139 140
add_library(utils STATIC ${source_utils})

target_link_libraries(
141
  utils
142
  ${Boost_LIBRARIES}
143
  )
144

145 146 147
#
## Gui
#
148
if(BUILD_CLIENT)
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
  file(GLOB source_gui
    src/gui/*.[hc]pp
    src/gui/camera/*.[hc]pp
    src/gui/screen/*.[hc]pp
    src/gui/hud/*.[hc]pp
    src/gui/sprites/*.[hc]pp
    )

  add_library(gui STATIC ${source_gui})

  target_Link_libraries(gui
    logging
    config
    world
    utils
    ${SFML_LIBRARIES}
    ${Boost_LIBRARIES}
    )
endif()

#
## World
#
file(GLOB source_world
  src/world/*.[hc]pp
louiz’'s avatar
louiz’ committed
174
  src/world/abilities/*.[hc]pp
175 176
  src/world/tasks/*.[hc]pp
  src/world/works/*.[hc]pp
louiz’'s avatar
louiz’ committed
177
  src/world/status/*.[hc]pp
178 179
  )

louiz’'s avatar
louiz’ committed
180 181
add_library(world STATIC ${source_world})

182 183 184
target_Link_libraries(world
  logging
  serialization
185
  fixmath
186 187 188 189 190 191 192
  utils
  ${Boost_LIBRARIES}
  )

#
## Serialization
#
193 194
file(GLOB proto_files
  src/proto/*.proto
195
  )
196
PROTOBUF_GENERATE_CPP(PROTO_SRC PROTO_HDRS ${proto_files})
197

198 199 200
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_library(serialization STATIC ${PROTO_SRC})
target_link_libraries(serialization ${PROTOBUF_LIBRARIES})
201

202 203 204 205 206 207

#
## Network server
#

file(GLOB source_server
208
  src/network/*.[hc]pp
209 210 211 212 213 214 215 216
  )

add_library(server STATIC ${source_server})

target_link_libraries(server
  logging
  config
  game
louiz’'s avatar
louiz’ committed
217
  world
218 219 220 221 222 223 224 225 226
  ${Boost_LIBRARIES}
  )

#
## Network client
#
file(GLOB source_client
  src/network/client.*
  src/network/game_client.*
227
  src/network/client_base.*
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
  src/network/command_handler.*
  src/network/transfer_receiver.*
  src/network/command.*
  src/network/timed_event.*
  src/network/timed_event_handler.*
  src/network/ping_handler.*
  )

add_library(client STATIC ${source_client})

target_link_libraries(client
  logging
  config
  )

add_library(network STATIC ${source_server} ${source_client})

#
## Game
#
file(GLOB source_game
louiz’'s avatar
louiz’ committed
249 250 251 252 253 254 255 256 257 258
  src/game/game.[ch]pp
  src/game/game_server.[ch]pp
  src/game/occupant.[ch]pp
  src/game/occupants_handler.[ch]pp
  src/game/remote_game_client.[ch]pp
  src/game/replay.[ch]pp
  src/game/selection.[ch]pp
  src/game/time.[ch]pp
  src/game/turn.[ch]pp
  src/game/turn_handler.[ch]pp
259 260 261 262 263 264
  )

add_library(game STATIC ${source_game})

target_link_libraries(game
  serialization
265
  network
266 267 268
  client
  logging
  config
269
  world
270 271 272 273 274
  )

#
## Game client
#
louiz’'s avatar
louiz’ committed
275 276
file(GLOB source_game_client
  src/game/game_client.[ch]pp
277 278
  src/game/sounds_handler.[ch]pp
  src/game/sound.[ch]pp
louiz’'s avatar
louiz’ committed
279 280 281
  )

add_library(game_client STATIC ${source_game_client})
282 283 284

target_link_libraries(game_client
  game
louiz’'s avatar
louiz’ committed
285
  gui
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
  )

#
## Menu client
#
add_library(menu_client STATIC ${source_game})

target_link_libraries(menu_client
  game
  )

#
## Server
#
if(BUILD_SERVER)
  add_library(game_server STATIC ${source_server})

  target_link_libraries(game_server
    logging
    config
    world
    ${Boost_LIBRARIES}
    )
endif()

####################
# Tests
####################
dionisos's avatar
dionisos committed
314

louiz’'s avatar
louiz’ committed
315 316 317
if(GTEST_FOUND)
  enable_testing()
  add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} -V)
318

louiz’'s avatar
louiz’ committed
319 320 321 322 323 324
  file(GLOB tests_srcs
    tests/*test.cpp
    )

  foreach(test_src ${tests_srcs})
    get_filename_component(lib ${test_src} NAME_WE)
dionisos's avatar
dionisos committed
325

louiz’'s avatar
louiz’ committed
326
    string(REGEX REPLACE "(.*)_test$" "\\1" lib ${lib})
dionisos's avatar
dionisos committed
327

louiz’'s avatar
louiz’ committed
328 329 330 331 332 333 334 335 336 337 338 339 340 341
    if(TARGET ${lib})
      add_executable(${lib}_test  EXCLUDE_FROM_ALL ${test_src})

      target_link_libraries(${lib}_test
        ${lib}
        ${GTEST_BOTH_LIBRARIES}
        )
      add_test(${lib}_test ${lib}_test)
      add_dependencies(check ${lib}_test)
    else()
      message("Library ${lib} does not exist, ${lib}_test.cpp will not be enabled.")
    endif()
  endforeach(test_src)
endif()