22godotcpp.cmake
33--------------
44
5+ As godot-cpp is a C++ project, there are no C files, and detection of a C
6+ compiler is unnecessary. When CMake performs the configure process, if a
7+ C compiler is specified, like in a toolchain, or from an IDE, then it will
8+ print a warning stating that the CMAKE_C_COMPILER compiler is unused.
9+ This if statement simply silences that warning.
10+ ]=======================================================================]
11+ if ( CMAKE_C_COMPILER )
12+ endif ()
13+
14+ #[=======================================================================[.rst:
15+ Include Platform Files
16+ ----------------------
17+
518Because these files are included into the top level CMakelists.txt before the
619project directive, it means that
720
@@ -18,10 +31,7 @@ include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos.cmake)
1831include ( ${CMAKE_CURRENT_SOURCE_DIR} /cmake/web.cmake)
1932include ( ${CMAKE_CURRENT_SOURCE_DIR} /cmake/windows.cmake)
2033
21- #Silence warning from unused CMAKE_C_COMPILER from toolchain
22- if ( CMAKE_C_COMPILER )
23- endif ()
24-
34+ # Detect number of processors
2535include (ProcessorCount)
2636ProcessorCount(PROC_MAX)
2737message ( "Auto-detected ${PROC_MAX} CPU cores available for build parallelism." )
@@ -99,8 +109,7 @@ function( godotcpp_options )
99109 #TODO threads
100110 #TODO compiledb
101111 #TODO compiledb_file
102-
103- #NOTE: build_profile's equivalent in cmake is CMakePresets.json
112+ #TODO build_profile
104113
105114 set (GODOT_USE_HOT_RELOAD "" CACHE BOOL
106115 "Enable the extra accounting required to support hot reload. (ON|OFF)" )
@@ -114,17 +123,26 @@ function( godotcpp_options )
114123 set_property ( CACHE GODOT_SYMBOL_VISIBILITY PROPERTY STRINGS "auto;visible;hidden" )
115124
116125 #TODO optimize
117- #TODO debug_symbols
118- option ( GODOT_DEBUG_SYMBOLS "" OFF )
126+
119127 option ( GODOT_DEV_BUILD "Developer build with dev-only debugging code (DEV_ENABLED)" OFF )
120128
129+ #[[ debug_symbols
130+ Debug symbols are enabled by using the Debug or RelWithDebInfo build configurations.
131+ Single Config Generator is set at configure time
132+
133+ cmake ../ -DCMAKE_BUILD_TYPE=Debug
134+
135+ Multi-Config Generator is set at build time
136+
137+ cmake --build . --config Debug
138+
139+ ]]
140+
121141 # FIXME These options are not present in SCons, and perhaps should be added there.
122142 option ( GODOT_SYSTEM_HEADERS "Expose headers as SYSTEM." OFF )
123143 option ( GODOT_WARNING_AS_ERROR "Treat warnings as errors" OFF )
124144
125- # Run options commands on the following to populate cache for all
126- # platforms. This type of thing is typically done conditionally But as
127- # scons shows all options so shall we.
145+ #[[ Target Platform Options ]]
128146 android_options()
129147 ios_options()
130148 linux_options()
@@ -136,7 +154,6 @@ endfunction()
136154# Function to configure and generate the targets
137155function ( godotcpp_generate )
138156 #[[ Multi-Threaded MSVC Compilation
139-
140157 When using the MSVC compiler the build command -j <n> only specifies
141158 parallel jobs or targets, and not multi-threaded compilation To speed up
142159 compile times on msvc, the /MP <n> flag can be set. But we need to set it
@@ -157,13 +174,11 @@ function( godotcpp_generate )
157174
158175 #[[ GODOT_SYMBOL_VISIBLITY
159176 To match the SCons options, the allowed values are "auto", "visible", and "hidden"
160- This effects the compiler flag -fvisibility=[default|internal|hidden|protected]
161- The corresponding CMake option CXX_VISIBILITY_PRESET accepts the compiler values.
177+ This effects the compiler flag_ -fvisibility=[default|internal|hidden|protected]
178+ The corresponding target option CXX_VISIBILITY_PRESET accepts the compiler values.
162179
163180 TODO: It is probably worth a pull request which changes both to use the compiler values
164- https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fvisibility
165-
166- This performs the necessary conversion
181+ .. _flag:https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fvisibility
167182 ]]
168183 if ( ${GODOT_SYMBOL_VISIBILITY} STREQUAL "auto" OR ${GODOT_SYMBOL_VISIBILITY} STREQUAL "visible" )
169184 set ( GODOT_SYMBOL_VISIBILITY "default" )
@@ -230,14 +245,29 @@ function( godotcpp_generate )
230245 godot_arch_map( SYSTEM_ARCH ${CMAKE_SYSTEM_PROCESSOR} )
231246 endif ()
232247
248+ # Transform options into generator expressions
249+ set ( HOT_RELOAD-UNSET "$<STREQUAL:${GODOT_USE_HOT_RELOAD} ,>" )
250+
251+ set ( DISABLE_EXCEPTIONS "$<BOOL:${GODOT_DISABLE_EXCEPTIONS} >" )
252+
253+ # GODOT_DEV_BUILD
254+ set ( RELEASE_TYPES "Release;MinSizeRel" )
255+ get_property ( IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG )
256+ if ( IS_MULTI_CONFIG )
257+ message ( NOTICE "=> Default build type is Debug. For other build types add --config <type> to build command" )
258+ elseif ( GODOT_DEV_BUILD AND CMAKE_BUILD_TYPE IN_LIST RELEASE_TYPES )
259+ message ( WARNING "=> GODOT_DEV_BUILD implies a Debug-like build but CMAKE_BUILD_TYPE is '${CMAKE_BUILD_TYPE} '" )
260+ endif ()
261+ set ( IS_DEV_BUILD "$<BOOL:${GODOT_DEV_BUILD} >" )
262+ # The .dev portion of the name if GODOT_DEV_BUILD is true.
263+ set ( DEV_TAG "$<${IS_DEV_BUILD} :.dev>" )
264+
233265 ### Define our godot-cpp library targets
234266 foreach ( TARGET_NAME template_debug template_release editor )
235267
236- # Useful genex snippits used in subsequent genex's
237- set ( IS_RELEASE "$<STREQUAL:${TARGET_NAME} ,template_release>" )
238- set ( IS_DEV "$<BOOL:${GODOT_DEV_BUILD} >" )
239- set ( DEBUG_FEATURES "$<OR:$<STREQUAL:${TARGET_NAME} ,template_debug>,$<STREQUAL:${TARGET_NAME} ,editor>>" )
240- set ( HOT_RELOAD "$<IF:${HOT_RELOAD-UNSET},$<NOT:${IS_RELEASE} >,$<BOOL:${GODOT_USE_HOT_RELOAD} >>" )
268+ # Generator Expressions that rely on the target
269+ set ( DEBUG_FEATURES "$<NOT:$<STREQUAL:${TARGET_NAME} ,template_release>>" )
270+ set ( HOT_RELOAD "$<IF:${HOT_RELOAD-UNSET},${DEBUG_FEATURES} ,$<BOOL:${GODOT_USE_HOT_RELOAD} >>" )
241271
242272 # the godot-cpp.* library targets
243273 add_library ( ${TARGET_NAME} STATIC EXCLUDE_FROM_ALL )
@@ -268,7 +298,7 @@ function( godotcpp_generate )
268298 BUILD_RPATH_USE_ORIGIN ON
269299
270300 PREFIX lib
271- OUTPUT_NAME "${PROJECT_NAME} .${SYSTEM_NAME} .${TARGET_NAME} .${SYSTEM_ARCH} "
301+ OUTPUT_NAME "${PROJECT_NAME} .${SYSTEM_NAME} .${TARGET_NAME}${DEV_TAG} .${SYSTEM_ARCH} "
272302 ARCHIVE_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR} /bin>"
273303
274304 # Things that are handy to know for dependent targets
0 commit comments