17
17
18
18
]]
19
19
20
- set ( SCRIPT_DIR ${CMAKE_CURRENT_LIST_DIR} )
20
+ set_property ( GLOBAL PROPERTY SAMPLE_DESCRIPTORS "" )
21
21
22
- function (add_sample )
22
+ function (vkb__register_sample_descriptor )
23
23
set (options )
24
- set (oneValueArgs ID CATEGORY AUTHOR NAME DESCRIPTION )
25
- set (multiValueArgs FILES LIBS SHADER_FILES_GLSL )
24
+ set (oneValueArgs NAME DESCRIPTION LIB )
25
+ set (multiValueArgs )
26
26
27
27
cmake_parse_arguments (TARGET "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
28
28
29
- add_sample_with_tags (
30
- TYPE "Sample"
31
- ID ${TARGET_ID}
32
- CATEGORY ${TARGET_CATEGORY}
33
- AUTHOR ${TARGET_AUTHOR}
34
- NAME ${TARGET_NAME}
35
- DESCRIPTION ${TARGET_DESCRIPTION}
36
- TAGS
37
- "any"
38
- FILES
39
- ${SRC_FILES}
40
- LIBS
41
- ${TARGET_LIBS}
42
- SHADER_FILES_GLSL
43
- ${TARGET_SHADER_FILES_GLSL} )
29
+ get_property (DESCRIPTORS GLOBAL PROPERTY SAMPLE_DESCRIPTORS )
30
+ list (APPEND DESCRIPTORS "{\" name\" :\" ${TARGET_NAME} \" , \" description\" : \" ${TARGET_DESCRIPTION} \" , \" library_name\" : \" ${TARGET_LIB} \" }" )
31
+ set_property (GLOBAL PROPERTY SAMPLE_DESCRIPTORS ${DESCRIPTORS} )
44
32
endfunction ()
45
33
46
- function (add_sample_with_tags )
47
- set (options )
48
- set (oneValueArgs ID CATEGORY AUTHOR NAME DESCRIPTION )
49
- set (multiValueArgs TAGS FILES LIBS SHADER_FILES_GLSL )
50
-
51
- cmake_parse_arguments (TARGET "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
52
-
53
- list (APPEND TARGET_TAGS "any" )
54
-
55
- set (SRC_FILES
56
- ${TARGET_ID} .h
57
- ${TARGET_ID} .cpp
58
- )
59
-
60
- # Append extra files if present
61
- if (TARGET_FILES )
62
- list (APPEND SRC_FILES ${TARGET_FILES} )
63
- endif ()
64
-
65
- # Add GLSL shader files for this sample
66
- if (TARGET_SHADER_FILES_GLSL )
67
- list (APPEND SHADER_FILES_GLSL ${TARGET_SHADER_FILES_GLSL} )
68
- foreach (SHADER_FILE_GLSL ${SHADER_FILES_GLSL} )
69
- list (APPEND SHADERS_GLSL "${PROJECT_SOURCE_DIR} /shaders/${SHADER_FILE_GLSL} " )
70
- endforeach ()
71
- endif ()
72
-
73
- add_project (
74
- TYPE "Sample"
75
- ID ${TARGET_ID}
76
- CATEGORY ${TARGET_CATEGORY}
77
- AUTHOR ${TARGET_AUTHOR}
78
- NAME ${TARGET_NAME}
79
- DESCRIPTION ${TARGET_DESCRIPTION}
80
- TAGS
81
- ${TARGET_TAGS}
82
- FILES
83
- ${SRC_FILES}
84
- LIBS
85
- ${TARGET_LIBS}
86
- SHADERS_GLSL
87
- ${SHADERS_GLSL} )
88
-
89
- endfunction ()
34
+ add_custom_target (vkb__samples )
90
35
91
- function (vkb_add_test )
36
+ function (vkb__register_sample )
92
37
set (options )
93
- set (oneValueArgs ID )
94
- set (multiValueArgs )
95
-
96
- cmake_parse_arguments (TARGET "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
97
-
98
- add_project (
99
- TYPE "Test"
100
- ID ${TARGET_ID}
101
- CATEGORY "Tests"
102
- AUTHOR " "
103
- NAME ${TARGET_ID}
104
- DESCRIPTION " "
105
- VENDOR_TAG " "
106
- LIBS test_framework
107
- FILES
108
- ${CMAKE_CURRENT_SOURCE_DIR} /${TARGET_ID}.h
109
- ${CMAKE_CURRENT_SOURCE_DIR} /${TARGET_ID}.cpp )
110
- endfunction ()
111
-
112
- function (add_project )
113
- set (options )
114
- set (oneValueArgs TYPE ID CATEGORY AUTHOR NAME DESCRIPTION )
115
- set (multiValueArgs TAGS FILES LIBS SHADERS_GLSL )
38
+ set (oneValueArgs NAME )
39
+ set (multiValueArgs SRC LINK_LIBS INCLUDE_DIRS )
116
40
117
41
cmake_parse_arguments (TARGET "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
118
42
119
- if (${TARGET_TYPE} STREQUAL "Sample " )
120
- set ( "VKB_ ${TARGET_ID} " ON CACHE BOOL "Build sample ${TARGET_ID} " )
43
+ if (TARGET_NAME STREQUAL "" )
44
+ message ( FATAL_ERROR "NAME must be defined in vkb__register_tests " )
121
45
endif ()
122
46
123
- if (NOT ${VKB_${TARGET_ID}} )
124
- message (STATUS "${TARGET_TYPE} `${TARGET_ID} ` - DISABLED" )
125
- return ()
126
- endif ()
47
+ if (TARGET_SRC ) ## Create static library
48
+ message ("ADDING SAMPLE: sample__${TARGET_NAME} " )
127
49
128
- message ( STATUS " ${TARGET_TYPE} ` ${TARGET_ID} ` - BUILD" )
50
+ add_library ( "sample__ ${TARGET_NAME} " SHARED ${TARGET_SRC} )
129
51
130
- # create project (object target - reused by app target)
131
- project (${TARGET_ID} LANGUAGES C CXX )
52
+ target_link_libraries ("sample__${TARGET_NAME} " PUBLIC vkb__platform_headers ) # sample_main
132
53
133
- source_group ("\\ " FILES ${TARGET_FILES} )
54
+ if (TARGET_LINK_LIBS )
55
+ target_link_libraries ("sample__${TARGET_NAME} " PUBLIC ${TARGET_LINK_LIBS} )
56
+ endif ()
134
57
135
- # Add shaders to project group
136
- if (SHADERS_GLSL )
137
- source_group ("\\ Shaders" FILES ${SHADERS_GLSL} )
58
+ if (TARGET_INCLUDE_DIRS )
59
+ target_include_directories ("sample__${TARGET_NAME} " PUBLIC ${TARGET_INCLUDE_DIRS} )
60
+ endif ()
61
+
62
+ if (MSVC )
63
+ target_compile_options ("sample__${TARGET_NAME} " PRIVATE /W4 /WX )
64
+ else ()
65
+ target_compile_options ("sample__${TARGET_NAME} " PRIVATE -Wall -Wextra -Wpedantic -Werror )
66
+ endif ()
67
+ else ()
68
+ message (FATAL_ERROR "a sample must contain one or more source files" )
138
69
endif ()
139
70
140
- add_library (${PROJECT_NAME} STATIC ${TARGET_FILES} ${SHADERS_GLSL} )
141
-
142
- # inherit compile definitions from framework target
143
- target_compile_definitions (${PROJECT_NAME} PUBLIC $< TARGET_PROPERTY:framework,COMPILE_DEFINITIONS> )
144
-
145
- # # inherit include directories from framework target
146
- target_include_directories (${PROJECT_NAME} PUBLIC $< TARGET_PROPERTY:framework,INCLUDE_DIRECTORIES> $< TARGET_PROPERTY:plugins,INCLUDE_DIRECTORIES> ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
147
- target_link_libraries (${PROJECT_NAME} PRIVATE framework )
148
-
149
- # Link against extra project specific libraries
150
- if (TARGET_LIBS )
151
- target_link_libraries (${PROJECT_NAME} PUBLIC ${TARGET_LIBS} )
152
- endif ()
71
+ # copy lib to samples_launcher executable
72
+ add_custom_command (
73
+ TARGET "sample__${TARGET_NAME} "
74
+ POST_BUILD
75
+ COMMAND ${CMAKE_COMMAND} -E copy
76
+ "$<TARGET_FILE:sample__${TARGET_NAME} >"
77
+ "$<TARGET_FILE_DIR:samples_launcher>/$<TARGET_FILE_NAME:sample__${TARGET_NAME} >"
78
+ )
153
79
154
- # capitalise the first letter of the category (performance -> Performance)
155
- string (SUBSTRING ${TARGET_CATEGORY} 0 1 FIRST_LETTER )
156
- string (TOUPPER ${FIRST_LETTER} FIRST_LETTER )
157
- string (REGEX REPLACE "^.(.*)" "${FIRST_LETTER} \\ 1" CATEGORY "${TARGET_CATEGORY} " )
158
-
159
- if (${TARGET_TYPE} STREQUAL "Sample" )
160
- # set sample properties
161
- set_target_properties (${PROJECT_NAME}
162
- PROPERTIES
163
- SAMPLE_CATEGORY ${TARGET_CATEGORY}
164
- SAMPLE_AUTHOR ${TARGET_AUTHOR}
165
- SAMPLE_NAME ${TARGET_NAME}
166
- SAMPLE_DESCRIPTION ${TARGET_DESCRIPTION}
167
- SAMPLE_TAGS "${TARGET_TAGS} " )
168
-
169
- # add sample project to a folder
170
- set_property (TARGET ${PROJECT_NAME} PROPERTY FOLDER "Samples//${CATEGORY} " )
171
- elseif (${TARGET_TYPE} STREQUAL "Test" )
172
- # add test project to a folder
173
- set_property (TARGET ${PROJECT_NAME} PROPERTY FOLDER "Tests" )
174
- endif ()
175
- endfunction ()
80
+ add_dependencies ("sample__${TARGET_NAME} " samples_launcher ) # automatically build the samples_launcher if a sample is set to compile
81
+ add_dependencies (vkb__samples "sample__${TARGET_NAME} " )
82
+ endfunction ()
0 commit comments