summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBenji <[email protected]>2024-04-17 13:26:18 -0400
committerGitHub <[email protected]>2024-04-17 19:26:18 +0200
commitc1fd98591d7996dd45a5ce9ecbb4b571607d417b (patch)
treeefd388b67277f5a38bd527e36ce211b05de42f21
parent112ce672e1423dd9923da8dead418152836c3176 (diff)
downloadraylib-c1fd98591d7996dd45a5ce9ecbb4b571607d417b.tar.gz
raylib-c1fd98591d7996dd45a5ce9ecbb4b571607d417b.zip
Build specific example using -DBUILD_EXAMPLE cmake flag (#3921)
-rw-r--r--CMakeLists.txt5
-rw-r--r--CMakeOptions.txt1
-rw-r--r--examples/CMakeLists.txt20
3 files changed, 22 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 57719691..d5c06604 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -59,7 +59,10 @@ if(NOT TARGET uninstall)
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
-if (${BUILD_EXAMPLES})
+if (NOT ${BUILD_EXAMPLE} STREQUAL "")
+ MESSAGE(STATUS "Building example '${BUILD_EXAMPLE}'")
+ add_subdirectory(examples)
+elseif (${BUILD_EXAMPLES})
MESSAGE(STATUS "Building examples is enabled")
add_subdirectory(examples)
endif()
diff --git a/CMakeOptions.txt b/CMakeOptions.txt
index 2c58cd5c..76fa411f 100644
--- a/CMakeOptions.txt
+++ b/CMakeOptions.txt
@@ -8,6 +8,7 @@ enum_option(OPENGL_VERSION "OFF;4.3;3.3;2.1;1.1;ES 2.0;ES 3.0" "Force a specific
# Configuration options
option(BUILD_EXAMPLES "Build the examples." ${RAYLIB_IS_MAIN})
+option(BUILD_EXAMPLE "Build a specific example by filename." "")
option(CUSTOMIZE_BUILD "Show options for customizing your Raylib library build." OFF)
option(ENABLE_ASAN "Enable AddressSanitizer (ASAN) for debugging (degrades performance)" OFF)
option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan) for debugging" OFF)
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 92232367..0f4be218 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -48,10 +48,24 @@ endif ()
# into a CMake variable
set(example_sources)
set(example_resources)
+set(example_found FALSE)
foreach (example_dir ${example_dirs})
- # Get the .c files
- file(GLOB sources ${example_dir}/*.c)
- list(APPEND example_sources ${sources})
+ if (BUILD_EXAMPLE)
+ if (NOT example_found)
+ file(GLOB sources ${example_dir}/${BUILD_EXAMPLE}.c)
+ if (EXISTS ${sources})
+ list(APPEND example_sources ${sources})
+ set(example_found TRUE)
+ message("Raylib example '${BUILD_EXAMPLE}.c' found in ${example_dir}!")
+ else()
+ message("Raylib example '${BUILD_EXAMPLE}.c' not found in ${example_dir}...")
+ endif()
+ endif()
+ else()
+ # Get the .c files
+ file(GLOB sources ${example_dir}/*.c)
+ list(APPEND example_sources ${sources})
+ endif()
# Any any resources
file(GLOB resources ${example_dir}/resources/*)