-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
184 lines (149 loc) · 6.94 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# This was created using pieces of the abandoned cmake script for Ogre at:
# https://github.com/ogre3d/clean-project/blob/master/tools/cmake/common.cmake
cmake_minimum_required(VERSION 3.0)
project(Ogre3D)
# Use bullet
option (INCLUDE_BULLET "Include the Bullet Physics Library" OFF)
if (INCLUDE_BULLET)
option(BUILD_BULLET2_DEMOS OFF)
option(BUILD_CPU_DEMOS OFF)
option(BUILD_EXTRAS OFF)
option(BUILD_OPENGL3_DEMOS OFF)
option(BUILD_UNIT_TESTS OFF)
add_subdirectory(vendor/bullet)
endif()
# Place targets into their own solution folders
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Set the proper paths for windows
# using the OGRE_HOME environment variable.
if(MSVC)
# Get the OGRE_HOME environment variable with unix slashes
set(OGRE_HOME "$ENV{OGRE_HOME}")
STRING(REGEX REPLACE "\\\\" "/" OGRE_HOME ${OGRE_HOME})
# Set the paths to search relative to the SDK root
set(CMAKE_MODULE_PATH "${OGRE_HOME}/CMake/;${CMAKE_MODULE_PATH}")
set(OGRE_SAMPLES_INCLUDEPATH "${OGRE_HOME}/Samples/include")
set(OGRE_BOOST_INCLUDE_PATH "${OGRE_HOME}/boost")
set(OGRE_BOOST_LIBRARIES "${OGRE_HOME}/boost/lib")
# Copy Media and Bin folders out to the repository
file(COPY ${OGRE_HOME}/bin DESTINATION ${CMAKE_SOURCE_DIR})
file(COPY ${OGRE_HOME}/media DESTINATION ${CMAKE_SOURCE_DIR})
# Hide the console in visual studio projects in debug and release
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS")
endif(MSVC)
# Set the proper paths for linux/mac
if(UNIX)
# Search for Ogre in some common locations
if(EXISTS "/usr/local/lib/OGRE/cmake")
set(CMAKE_MODULE_PATH "/usr/local/lib/OGRE/cmake/;${CMAKE_MODULE_PATH}")
set(OGRE_SAMPLES_INCLUDEPATH "/usr/local/share/OGRE/Samples/Common/include/")
elseif(EXISTS "/usr/lib/OGRE/cmake")
# Otherwise, this one
set(CMAKE_MODULE_PATH "/usr/lib/OGRE/cmake/;${CMAKE_MODULE_PATH}")
set(OGRE_SAMPLES_INCLUDEPATH "/usr/share/OGRE/Samples/Common/include/")
# apt-get installation
# In that case environment var OGRE_HOME should be set, because .deb ogre
# packages does not carry samples
elseif(EXISTS "/usr/share/OGRE/cmake/modules")
set(CMAKE_MODULE_PATH "/usr/share/OGRE/cmake/modules/;${CMAKE_MODULE_PATH}")
set(OGRE_SAMPLES_INCLUDEPATH "$ENV{OGRE_HOME}/Samples/Common/include/")
else ()
message(SEND_ERROR "Failed to find module path.")
endif(EXISTS "/usr/local/lib/OGRE/cmake")
endif(UNIX)
# Support C++11
set(CMAKE_CXX_STANDARD_REQUIRED on)
set(CMAKE_CXX_STANDARD 11)
# Set compiler flags
# -w Disables all warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
# Find libraries
find_package(OGRE REQUIRED)
find_package(OIS REQUIRED)
# Display an error if OIS was not found
if(NOT OIS_FOUND)
message(SEND_ERROR "Failed to find OIS.")
endif()
# Add include directories
include_directories(${OGRE_INCLUDE_DIRS}
${OIS_INCLUDE_DIRS}
${OGRE_SAMPLES_INCLUDEPATH}
${OGRE_Overlay_INCLUDE_DIRS})
# Add MSVC Boost include and library path
if(MSVC)
include_directories(${OGRE_BOOST_INCLUDE_PATH})
link_directories(${OGRE_BOOST_LIBRARIES})
endif(MSVC)
# Add Bullet include path
if(INCLUDE_BULLET)
include_directories(vendor/bullet/src)
endif(INCLUDE_BULLET)
# Create file globs
file(GLOB_RECURSE PROJECT_HEADERS src/*.h)
file(GLOB_RECURSE PROJECT_SOURCES src/*.cpp)
file(GLOB PROJECT_CONFIGS CMakeLists.txt
README.md
.gitignore)
# Define source file groupings
source_group("Headers" FILES ${PROJECT_HEADERS})
source_group("Sources" FILES ${PROJECT_SOURCES})
source_group("Configs" FILES ${PROJECT_CONFIGS})
# Add configs to the source grouping for Visual Studio
if(MSVC)
file(GLOB PROJECT_CONFIGS_WINDOWS_RELEASE src/config/windows/release/*.cfg)
file(GLOB PROJECT_CONFIGS_WINDOWS_DEBUG src/config/windows/debug/*.cfg)
file(GLOB PROJECT_CONFIGS_UNIX src/config/unix/*.cfg)
source_group("Configs\\Windows_Configs\\Release" FILES ${PROJECT_CONFIGS_WINDOWS_RELEASE})
source_group("Configs\\Windows_Configs\\Debug" FILES ${PROJECT_CONFIGS_WINDOWS_DEBUG})
source_group("Configs\\Unix_Configs" FILES ${PROJECT_CONFIGS_UNIX})
endif(MSVC)
# Define the executable
add_executable( ${PROJECT_NAME} ${PROJECT_HEADERS}
${PROJECT_SOURCES}
${PROJECT_CONFIGS}
${PROJECT_CONFIGS_WINDOWS_RELEASE}
${PROJECT_CONFIGS_WINDOWS_DEBUG}
${PROJECT_CONFIGS_UNIX})
# Define libraries to link to
target_link_libraries( ${PROJECT_NAME} ${OGRE_LIBRARIES}
${OIS_LIBRARIES}
${OGRE_Paging_LIBRARIES}
${OGRE_Terrain_LIBRARIES}
${OGRE_Property_LIBRARIES}
${OGRE_RTShaderSystem_LIBRARIES}
${OGRE_Volume_LIBRARIES}
${OGRE_Overlay_LIBRARIES}
${OGRE_MeshLodGenerator_LIBRARIES}
${OGRE_HLMS_LIBRARIES}
${OGRE_Bites_LIBRARIES})
# Statically link Bullet libraries
if(INCLUDE_BULLET)
target_link_libraries(${PROJECT_NAME} BulletDynamics BulletCollision LinearMath)
endif(INCLUDE_BULLET)
# Output to bin directory
set_target_properties(${PROJECT_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
if(MSVC)
# Set the startup project
set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
# Set the working directory
set_target_properties(${PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/debug)
# Copy debug configs to output folder after a successful bug build
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/src/config/windows/debug
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
# Copy release configs to output folder after a successful build
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/src/config/windows/release
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
endif(MSVC)
if(UNIX)
# Copy configs to output folder after a successful build
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/src/config/unix
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
endif(UNIX)