-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
146 lines (123 loc) · 4.29 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
###########################
# CMake Build Environment #
###########################
#
# You can set the following Environment variables:
#
# CMAKE_MODULE_PATH to the search path for cmake modules (e.g., SFML.cmake)
# CMAKE_BUILD_TYPE to override the default build type. Valid options are 'release', 'profile' and 'debug'
#
#########################################
# Project name
project(game)
# Minimum Cmake Version
cmake_minimum_required(VERSION 2.6)
#####################
# Setup Environment #
#####################
# set to include custom modules
set(CMAKE_MODULE_PATH $ENV{CMAKE_MODULE_PATH} ${game_SOURCE_DIR}/cmake)
# set build type if specified by environment
if((NOT CMAKE_BUILD_TYPE) AND (NOT $ENV{CMAKE_BUILD_TYPE} STREQUAL ""))
set(CMAKE_BUILD_TYPE $ENV{CMAKE_BUILD_TYPE})
endif()
# Set include directories
include_directories(${game_SOURCE_DIR}/include)
# Get CPP files
file(GLOB_RECURSE SRC src/*cpp)
# Get Header files
file(GLOB_RECURSE HEADERS include/*h)
# Get executable files
file(GLOB EXECLIST bin/*cpp)
# Get media files
file(COPY media DESTINATION .)
#################################################
# #
# ADD CUSTOM LIBRARIES HERE. #
# #
# Example BOOST: #
# find_package(Boost REQUIRED) #
# include_directories(${Boost_INCLUDE_DIRS}) #
# link_libraries(${Boost_LIBRARIES}) #
#################################################
##################
# Add Chipmunk2D #
##################
option(BUILD_DEMOS OFF)
add_subdirectory(lib/Chipmunk2D)
include_directories(lib/Chipmunk2D/include/chipmunk)
link_libraries(chipmunk)
#############
# json11 #
#############
add_subdirectory(lib/json11)
include_directories(lib/json11)
link_libraries(json11)
#############
# Find SFML #
#############
find_package(SFML COMPONENTS graphics window system audio network)
include_directories(${SFML_INCLUDE_DIR})
link_libraries(${SFML_LIBRARIES})
if(NOT SFML_FOUND)
# SFML not found
message(FATAL_ERROR " * Make sure LIB includes the directory where the SFML libraries are installed.\n * Make sure INCLUDE includes the directory where the SFML header files are installed.")
endif()
###############
# C++ Options #
###############
# Enable C++11
# Change compiler flag for MSVC, do not check other compiler type.
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
endif()
# determine build type
# 1) use build type if specified by the user.
# 2) if in-source building, use default (debug) build type.
# 3) if out-source building, determine based on the build directory's name which build type.
# If build directory is called 'Release' or 'Profile' then use the 'Release' and 'Profile'
# build type respectively, otherwise use 'debug'.
if(CMAKE_BUILD_TYPE)
string(TOUPPER "${CMAKE_BUILD_TYPE}" TYPE)
message("-- Using user specified build type: ${TYPE}")
elseif(${game_SOURCE_DIR} STREQUAL ${game_BINARY_DIR})
set(CMAKE_BUILD_TYPE Debug)
message("-- In-source building. Build type set to: Debug")
else()
get_filename_component(TYPE ${game_BINARY_DIR} NAME)
string(TOUPPER "${TYPE}" TYPE)
if(${TYPE} STREQUAL "RELEASE")
set(CMAKE_BUILD_TYPE Release)
elseif(${TYPE} STREQUAL "PROFILE")
set(CMAKE_BUILD_TYPE Profile)
else()
set(CMAKE_BUILD_TYPE Debug)
endif()
message("-- Out-source building. Build type set to: ${TYPE}")
endif()
# Handle non-default build type 'Profile'
string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE)
if(${CMAKE_BUILD_TYPE} STREQUAL "PROFILE")
set(CMAKE_BUILD_TYPE DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
endif()
#######################
# Set Compile Targets #
#######################
# src library (all CPP files in 'src' dir)
if(NOT SRC STREQUAL "")
get_filename_component(LIBNAME ${game_SOURCE_DIR} NAME)
set(LIBNAME "${LIBNAME}_core")
add_library(${LIBNAME} ${SRC})
endif()
# executables (any CPP file in 'bin' dir)
foreach(EXEC ${EXECLIST})
get_filename_component(EXECNAME ${EXEC} NAME_WE)
add_executable(${EXECNAME} ${EXEC} ${SRC} ${HEADERS})
if(NOT SRC STREQUAL "")
target_link_libraries(${EXECNAME} LINK_PUBLIC ${LIBNAME})
endif()
message("-- Adding executable: ${EXECNAME}")
endforeach(EXEC)