Skip to content

Commit 6815e71

Browse files
committed
Build specific example using -DBUILD_EXAMPLE cmake flag
1 parent a6a08c7 commit 6815e71

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ if(NOT TARGET uninstall)
5959
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
6060
endif()
6161

62-
if (${BUILD_EXAMPLES})
62+
if (NOT ${BUILD_EXAMPLE} STREQUAL "")
63+
MESSAGE(STATUS "Building example '${BUILD_EXAMPLE}'")
64+
add_subdirectory(examples)
65+
elseif (${BUILD_EXAMPLES})
6366
MESSAGE(STATUS "Building examples is enabled")
6467
add_subdirectory(examples)
6568
endif()

CMakeOptions.txt

+1
Original file line numberDiff line numberDiff line change
@@ -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
88

99
# Configuration options
1010
option(BUILD_EXAMPLES "Build the examples." ${RAYLIB_IS_MAIN})
11+
option(BUILD_EXAMPLE "Build a specific example by filename." "")
1112
option(CUSTOMIZE_BUILD "Show options for customizing your Raylib library build." OFF)
1213
option(ENABLE_ASAN "Enable AddressSanitizer (ASAN) for debugging (degrades performance)" OFF)
1314
option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan) for debugging" OFF)

examples/CMakeLists.txt

+17-3
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,24 @@ endif ()
4848
# into a CMake variable
4949
set(example_sources)
5050
set(example_resources)
51+
set(example_found FALSE)
5152
foreach (example_dir ${example_dirs})
52-
# Get the .c files
53-
file(GLOB sources ${example_dir}/*.c)
54-
list(APPEND example_sources ${sources})
53+
if (BUILD_EXAMPLE)
54+
if (NOT example_found)
55+
file(GLOB sources ${example_dir}/${BUILD_EXAMPLE}.c)
56+
if (EXISTS ${sources})
57+
list(APPEND example_sources ${sources})
58+
set(example_found TRUE)
59+
message("Raylib example '${BUILD_EXAMPLE}.c' found in ${example_dir}!")
60+
else()
61+
message("Raylib example '${BUILD_EXAMPLE}.c' not found in ${example_dir}...")
62+
endif()
63+
endif()
64+
else()
65+
# Get the .c files
66+
file(GLOB sources ${example_dir}/*.c)
67+
list(APPEND example_sources ${sources})
68+
endif()
5569

5670
# Any any resources
5771
file(GLOB resources ${example_dir}/resources/*)

0 commit comments

Comments
 (0)