Skip to content

Commit 9786705

Browse files
committed
Update examples/CMakeLists.txt
1 parent 175a53e commit 9786705

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

examples/CMakeLists.txt

+11-5
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,27 @@ source_group("test" FILES
1616
speed_test.cpp
1717
)
1818

19-
macro(add_example)
19+
if(NOT TARGET tests)
20+
add_custom_target(tests)
21+
endif()
22+
23+
function(add_example)
2024
cmake_parse_arguments("addex" "" "NAME" "SRCS;DEPS" ${ARGN})
2125
if("${addex_NAME}" STREQUAL "")
22-
message(FATAL_ERROR "add_example: no NAME")
26+
message(SEND_ERROR "add_example: no NAME")
27+
return()
2328
endif()
2429
if("${addex_SRCS}" STREQUAL "")
25-
message(FATAL_ERROR "add_example: no SRCS")
30+
message(SEND_ERROR "add_example: no SRCS")
31+
return()
2632
endif()
2733
message(STATUS "add_example: ${addex_NAME} SRCS: ${addex_SRCS} DEPS: ${addex_DEPS}")
2834
add_executable("${PROJECT_NAME}-example-${addex_NAME}"
2935
${addex_SRCS})
3036
set_property(TARGET "${PROJECT_NAME}-example-${addex_NAME}" PROPERTY FOLDER "example")
3137
target_link_libraries("${PROJECT_NAME}-example-${addex_NAME}" PRIVATE ${addex_DEPS})
32-
endmacro()
33-
#
38+
add_dependencies(tests "${PROJECT_NAME}-example-${addex_NAME}")
39+
endfunction()
3440

3541
add_example(NAME custom_data_type SRCS custom_data_type.cpp DEPS Boost::property_tree)
3642
add_example(NAME debug_settings SRCS debug_settings.cpp DEPS Boost::property_tree)

0 commit comments

Comments
 (0)