summaryrefslogtreecommitdiffhomepage
path: root/cmake/ParseConfigHeader.cmake
diff options
context:
space:
mode:
authorLázaro Albuquerque <[email protected]>2024-06-16 04:49:59 -0400
committerGitHub <[email protected]>2024-06-16 10:49:59 +0200
commit307c998495a769092a8587c91a3efdb526de909c (patch)
tree6e5801ec81d27be32575ea4d92ee9e2d8f0d2830 /cmake/ParseConfigHeader.cmake
parenta29d334734f720431872266743ba5560870e3453 (diff)
downloadraylib-307c998495a769092a8587c91a3efdb526de909c.tar.gz
raylib-307c998495a769092a8587c91a3efdb526de909c.zip
[build] Making `config.h` fully available to CMake users (#4044)
* Create ParseConfigHeader.cmake This script parses the config.h file to automate the process of exposing the configuration flags and configuration values found in the latter. * Update CompileDefinitions.cmake Makes use of the new functionality found in ParseConfigHeader.cmake to make things consistent. * Update CMakeOptions.txt Makes use of the new functionality found in ParseConfigHeader.cmake to make things consistent. * Update CMakeLists.txt Changes required to make possible building raylib for web on Windows 10. * Update LibraryConfigurations.cmake Removes a warning that linker-only flags were being passed to the compiler, which is in accordance to https://emscripten.org/docs/tools_reference/settings_reference.html. * Update CMakeOptions.txt Removed clutter. * Update CompileDefinitions.cmake Removed clutter. * Update CompileDefinitions.cmake Some applications might check for PLATFORM_WEB instead of __EMSCRIPTEN__. * Update CompileDefinitions.cmake Reverting * Update CMakeLists.txt USE_AUDIO is redundant in the presence of the already existent and more descriptive SUPPORT_MODULE_RAUDIO. * Update CompileDefinitions.cmake USE_AUDIO is redundant in the presence of the already existent and more descriptive SUPPORT_MODULE_RAUDIO. * Update ParseConfigHeader.cmake * Revert "Update CMakeLists.txt" This reverts commit 1785fc06b5b89e65515cea3afd3e3c095f15e350. * Revert "Update CompileDefinitions.cmake" This reverts commit 62f9a3a0ea21af7bd0a1ab74d10a305fca2a5695. * Revert "Update CMakeLists.txt" This reverts commit 3e7912144edc5c69c53ed5a9515ae21d66937963. * Revert "Update LibraryConfigurations.cmake" This reverts commit bcc4310c4960c200c340671caa298983340ea386.
Diffstat (limited to 'cmake/ParseConfigHeader.cmake')
-rw-r--r--cmake/ParseConfigHeader.cmake17
1 files changed, 17 insertions, 0 deletions
diff --git a/cmake/ParseConfigHeader.cmake b/cmake/ParseConfigHeader.cmake
new file mode 100644
index 00000000..797eea3c
--- /dev/null
+++ b/cmake/ParseConfigHeader.cmake
@@ -0,0 +1,17 @@
+file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/config.h" CONFIG_HEADER_CONTENT)
+
+set(BLANK_OR_BACKSLASH_PATTERN "[ \t\r\n\\]")
+set(VALID_IDENTIFIER_PATTERN "[A-Za-z_]+[A-Za-z_0-9]*")
+set(VALID_VALUE_PATTERN [=["?[A-Za-z_0-9.-]+"?]=]) # not really correct but does the job since the config.h file hopefully will have been checked by a C preprocessor.
+set(MACRO_REGEX "(//${BLANK_OR_BACKSLASH_PATTERN}*)?\#define${BLANK_OR_BACKSLASH_PATTERN}+(${VALID_IDENTIFIER_PATTERN})${BLANK_OR_BACKSLASH_PATTERN}+(${VALID_VALUE_PATTERN})")
+
+string(REGEX MATCHALL ${MACRO_REGEX} MACRO_LIST ${CONFIG_HEADER_CONTENT})
+
+set(CONFIG_HEADER_FLAGS ${MACRO_LIST})
+list(FILTER CONFIG_HEADER_FLAGS INCLUDE REGEX "^.+SUPPORT_")
+list(TRANSFORM CONFIG_HEADER_FLAGS REPLACE ${MACRO_REGEX} [[\2=OFF]] REGEX "^//")
+list(TRANSFORM CONFIG_HEADER_FLAGS REPLACE ${MACRO_REGEX} [[\2=ON]])
+
+set(CONFIG_HEADER_VALUES ${MACRO_LIST})
+list(FILTER CONFIG_HEADER_VALUES EXCLUDE REGEX "(^.+SUPPORT_)|(^//)")
+list(TRANSFORM CONFIG_HEADER_VALUES REPLACE ${MACRO_REGEX} [[\2=\3]])