-
Notifications
You must be signed in to change notification settings - Fork 12
/
CMakeLists.txt
149 lines (129 loc) · 4.71 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
146
147
148
149
cmake_minimum_required(VERSION 2.8.12)
project(SIMPLEAI C CXX)
include(CheckFunctionExists)
include(CheckCXXCompilerFlag)
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(SIMPLEAI_VERSION "0.1")
option(SIMPLEAI_USE_CCACHE "Use ccache if available" ON)
option(SIMPLEAI_RUN "Compile run program" ON)
option(SIMPLEAI_DEBUGGER "Compile with qt debugger support" OFF)
option(SIMPLEAI_TEST "Compile tests" ON)
option(SIMPLEAI_LUA "Compile with lua support" ON)
option(SIMPLEAI_XML "Compile with xml support" OFF)
option(SIMPLEAI_EXCEPTIONS "Compile with exception support" OFF)
if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU" OR ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11)
check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if (COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif (COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
if (NOT SIMPLEAI_EXCEPTIONS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
endif()
elseif (MSVC)
else()
message(WARNING "C++ Compiler: Unknown")
endif()
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Compile Type" FORCE)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release MinSizeRel RelWithDebInfo)
if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(WINDOWS 1)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(LINUX 1)
else()
message(WARNING "Unknown host system: ${CMAKE_SYSTEM_NAME}. Default to linux")
set(LINUX 1)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if (${CMAKE_EXTRA_GENERATOR} MATCHES "Eclipse CDT4")
message(STATUS "Generate eclipse projects")
set(CMAKE_ECLIPSE_GENERATE_LINKED_RESOURCES OFF)
set(CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT ON)
set(CMAKE_ECLIPSE_VERSION "4.3" CACHE STRING "Eclipse version")
set(CMAKE_CXX_COMPILER_ARG1 "-std=c++11" CACHE STRING "C++ version for Eclipse")
endif()
message(STATUS "Place binaries in ${CMAKE_CURRENT_SOURCE_DIR}")
# First for the generic no-config case (e.g. with mingw)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)
# Second, for multi-config builds (e.g. msvc)
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)
endforeach()
if (NOT CMAKE_TOOLCHAIN_FILE)
if (WINDOWS)
include(${CMAKE_MODULE_PATH}/toolchains/windows-toolchain.cmake)
else()
include(${CMAKE_MODULE_PATH}/toolchains/linux-toolchain.cmake)
endif()
endif()
if (SIMPLEAI_USE_CCACHE)
find_program(CCACHE "ccache")
if (CCACHE)
message(STATUS "Using ccache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE})
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE})
endif()
endif()
if (SIMPLEAI_EXCEPTIONS)
add_definitions(-DAI_EXCEPTIONS=1)
message(STATUS "Build with exception support")
else()
if (SIMPLEAI_LUA)
add_definitions(-DLUA_USE_LONGJMP)
endif()
add_definitions(-DAI_EXCEPTIONS=0)
message(STATUS "Build without exception support")
endif()
macro(check_lua_files TARGET FILES)
find_program(LUAC_EXECUTABLE NAMES luac luac5.3)
if (LUAC_EXECUTABLE)
message(STATUS "${LUAC_EXECUTABLE} found")
foreach(_FILE ${FILES})
string(REPLACE "/" "-" TARGETNAME ${_FILE})
add_custom_target(
${TARGETNAME}
COMMENT "checking lua file ${_FILE} with ${LUAC_EXECUTABLE}"
COMMAND ${LUAC_EXECUTABLE} -p ${_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_dependencies(${TARGET} ${TARGETNAME})
endforeach()
else()
message(STATUS "No lua compiler (luac) found")
endif()
endmacro()
add_subdirectory(src/ai)
add_subdirectory(src/libs)
if (SIMPLEAI_RUN)
if (NOT SIMPLEAI_LUA)
message(STATUS "Lua is needed for the run tool")
else()
add_subdirectory(src/run)
endif()
endif()
if (SIMPLEAI_DEBUGGER)
add_subdirectory(src/debug)
endif()
if (SIMPLEAI_TEST)
add_subdirectory(src/test)
endif()
find_package(Doxygen)
if (DOXYGEN_FOUND)
set(top_srcdir ${CMAKE_CURRENT_SOURCE_DIR})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif(DOXYGEN_FOUND)