forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
202 lines (169 loc) · 7.24 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
cmake_minimum_required(VERSION 3.0.2)
set(CMAKE_DISABLE_SOURCE_CHANGES ON) # Must go before project() below
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) # Must go before project() below
if(CMAKE_VERSION VERSION_GREATER "3.11" OR POLICY CMP0072)
# Prefer GLVND over libGL when available; this will be enabled by default
# once the minimum CMake version is at least 3.11.
cmake_policy(SET CMP0072 NEW)
endif()
if(CMAKE_VERSION VERSION_GREATER "3.12" OR POLICY CMP0074)
# Needed for THIRDPARTY_DIRECTORY support; this will be enabled by default
# once the minimum CMake version is at least 3.12.
cmake_policy(SET CMP0074 NEW)
endif()
if(POLICY CMP0091)
# Needed for CMake to pass /MD flag properly with non-VC generators.
cmake_policy(SET CMP0091 NEW)
endif()
# Determine whether we are using a multi-config generator.
if(CMAKE_VERSION VERSION_GREATER "3.8")
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
else()
message(WARNING "Multi-configuration builds may not work properly when using
a CMake < 3.9. Making a guess if this is a multi-config generator.")
if(DEFINED CMAKE_CONFIGURATION_TYPES)
set(IS_MULTICONFIG ON)
else()
set(IS_MULTICONFIG OFF)
endif()
endif()
if(WIN32)
if(CMAKE_GENERATOR_PLATFORM STREQUAL "")
# Assume x64
set(CMAKE_GENERATOR_PLATFORM "x64")
endif()
endif()
# Define the type of build we are setting up.
set(_configs Standard Release RelWithDebInfo Debug MinSizeRel)
if(CMAKE_CXX_COMPILER_ID MATCHES "(AppleClang|Clang|GCC)")
list(APPEND _configs Coverage)
endif()
if(IS_MULTICONFIG)
message(STATUS "Using multi-configuration generator")
else()
# Set the default CMAKE_BUILD_TYPE before calling project().
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Standard CACHE STRING "Choose the type of build." FORCE)
message(STATUS "Using default build type ${CMAKE_BUILD_TYPE}")
else()
message(STATUS "Using build type ${CMAKE_BUILD_TYPE}")
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${_configs})
endif()
# Figure out the version
set(_s "[\\t ]*") # CMake doesn't support \s*
file(STRINGS "setup.cfg" _version REGEX "^version${_s}=${_s}")
string(REGEX REPLACE "^.*=${_s}" "" _version "${_version}")
project(Panda3D VERSION ${_version})
unset(_version)
unset(_s)
enable_testing()
string(REPLACE "$(EFFECTIVE_PLATFORM_NAME)" "" PANDA_CFG_INTDIR "${CMAKE_CFG_INTDIR}")
# Add generic modules to cmake module path,
# and add Panda3D specific modules to cmake module path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/macros/")
if(CMAKE_VERSION VERSION_GREATER "3.8")
# When using the Xcode generator, don't append the platform name to the
# intermediate configuration directory.
set_property(GLOBAL PROPERTY XCODE_EMIT_EFFECTIVE_PLATFORM_NAME OFF)
endif()
# Include modules builtin to CMake
include(GNUInstallDirs) # Defines CMAKE_INSTALL_<dir> variables
# Include global modules needed for configure scripts
include(PackageConfig) # Defines package_option
include(PerConfigOption) # Defines per_config_option
# Configure Panda3D
include(dtool/CompilerFlags.cmake)
include(dtool/PandaVersion.cmake)
include(dtool/Package.cmake)
include(dtool/Config.cmake)
# Include global modules
include(AddBisonTarget) # Defines add_bison_target function
include(AddFlexTarget) # Defines add_flex_target function
include(BuildMetalib) # Defines add_component_library AND add_metalib
include(CompositeSources) # Defines composite_sources function
include(Python) # Defines add_python_target AND install_python_package
include(Interrogate) # Defines target_interrogate AND add_python_module
include(RunPzip) # Defines run_pzip function
include(Versioning) # Hooks 'add_library' to apply VERSION/SOVERSION
# Determine which trees to build.
option(BUILD_DTOOL "Build the dtool source tree." ON)
option(BUILD_PANDA "Build the panda source tree." ON)
option(BUILD_DIRECT "Build the direct source tree." ON)
option(BUILD_PANDATOOL "Build the pandatool source tree." ON)
option(BUILD_CONTRIB "Build the contrib source tree." ON)
option(BUILD_MODELS "Build/install the built-in models." ON)
option(BUILD_BSP "Build the bsp source tree." ON)
# Include Panda3D packages
if(BUILD_DTOOL)
add_subdirectory(dtool "${CMAKE_BINARY_DIR}/dtool")
endif()
if(BUILD_PANDA)
add_subdirectory(panda "${CMAKE_BINARY_DIR}/panda")
endif()
if(BUILD_DIRECT)
add_subdirectory(direct "${CMAKE_BINARY_DIR}/direct")
endif()
if(BUILD_PANDATOOL)
add_subdirectory(pandatool "${CMAKE_BINARY_DIR}/pandatool")
endif()
if(BUILD_CONTRIB)
add_subdirectory(contrib "${CMAKE_BINARY_DIR}/contrib")
endif()
if(BUILD_BSP)
add_subdirectory(bsp "${CMAKE_BINARY_DIR}/bsp")
endif()
if(BUILD_MODELS)
run_pzip(models
"${CMAKE_CURRENT_SOURCE_DIR}/models/"
"${PROJECT_BINARY_DIR}/${PANDA_CFG_INTDIR}/models"
*.egg)
run_pzip(dmodels
"${CMAKE_CURRENT_SOURCE_DIR}/dmodels/src/"
"${PROJECT_BINARY_DIR}/${PANDA_CFG_INTDIR}/models"
*.egg)
add_custom_command(TARGET models
POST_BUILD
COMMAND ${CMAKE_COMMAND}
-DSOURCE="${CMAKE_CURRENT_SOURCE_DIR}/models/maps/"
-DDESTINATION="${PANDA_OUTPUT_DIR}/models/maps"
-P ${PROJECT_SOURCE_DIR}/cmake/scripts/CopyPattern.cmake
COMMENT "Copying models/maps")
add_custom_command(TARGET dmodels
POST_BUILD
COMMAND ${CMAKE_COMMAND}
-DSOURCE="${CMAKE_CURRENT_SOURCE_DIR}/dmodels/src/"
-DDESTINATION="${PANDA_OUTPUT_DIR}/models"
-DFILES_MATCHING="PATTERN;*.rgb;PATTERN;*.png;PATTERN;*.jpg;PATTERN;*.wav"
-P ${PROJECT_SOURCE_DIR}/cmake/scripts/CopyPattern.cmake
COMMENT "Copying dmodels' assets")
install(DIRECTORY "${PANDA_OUTPUT_DIR}/models"
COMPONENT Models DESTINATION ${CMAKE_INSTALL_DATADIR}/panda3d)
endif()
if(INTERROGATE_PYTHON_INTERFACE)
# If we built the Python interface, run the test suite. Note, we do NOT test
# for pytest before adding this test. If the user doesn't have pytest, we'd
# like for the tests to fail.
# In the Coverage configuration, we also require pytest-cov
add_test(NAME pytest
COMMAND "${PYTHON_EXECUTABLE}" -m pytest "${PROJECT_SOURCE_DIR}/tests"
$<$<CONFIG:Coverage>:--cov=.>
WORKING_DIRECTORY "${PANDA_OUTPUT_DIR}")
endif()
# Generate the Panda3DConfig.cmake file so find_package(Panda3D) works, and
# also register the build directory with CMake's package registry.
file(COPY "${PROJECT_SOURCE_DIR}/cmake/install/Panda3DConfig.cmake"
DESTINATION "${PROJECT_BINARY_DIR}")
install(FILES "${PROJECT_SOURCE_DIR}/cmake/install/Panda3DConfig.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Panda3D")
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/Panda3DConfigVersion.cmake"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY AnyNewerVersion)
install(FILES "${PROJECT_BINARY_DIR}/Panda3DConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Panda3D")
if(NOT CMAKE_CROSSCOMPILING)
export(PACKAGE Panda3D)
endif()