Skip to content

Commit

Permalink
Re-enable all examples
Browse files Browse the repository at this point in the history
  • Loading branch information
neatudarius committed Oct 21, 2024
1 parent 325a07f commit f2aca35
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Define a list
set(ALL_EXAMPLES
#identity_as_default_projection
identity_direct_usage)
identity_direct_usage 17
identity_as_default_projection 20)

foreach(example ${ALL_EXAMPLES})
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tmp)

# Iterate over the list in steps of 2
list(LENGTH ALL_EXAMPLES ALL_EXAMPLES_LENGTH)
math(EXPR LAST_INDEX "${ALL_EXAMPLES_LENGTH} - 1")
foreach(i RANGE 0 ${LAST_INDEX} 2)
list(GET ALL_EXAMPLES "${i}" example) # Get the example name
math(EXPR cpp_standard_index "${i} + 1")
list(GET ALL_EXAMPLES ${cpp_standard_index} cpp_standard) # Get the C++ standard for that example
message(STATUS "Try compile example: ${example} cpp_standard: ${cpp_standard}")

# Try to compile the example. Continue to the next example if compilation fails.
try_compile(
COMPILE_SUCCESS
${CMAKE_BINARY_DIR}/tmp
${CMAKE_CURRENT_SOURCE_DIR}/${example}.cpp
CMAKE_FLAGS
-DCMAKE_CXX_STANDARD=${cpp_standard}
-DCMAKE_CXX_STANDARD_REQUIRED=YES
-DCMAKE_CXX_EXTENSIONS=NO
-DCMAKE_CXX_FLAGS="-I${CMAKE_CURRENT_SOURCE_DIR}/../include" # does not work
OUTPUT_VARIABLE COMPILE_OUTPUT # Capture output
)
message(STATUS "Compile output: ${COMPILE_OUTPUT}") # debug
if (NOT COMPILE_SUCCESS)
message(WARNING "Skipping ${example}: Requires C++${cpp_standard} or later")
continue()
endif()

# Add executable and link to the target.
add_executable(beman.exemplar.examples.${example})
target_sources(beman.exemplar.examples.${example} PRIVATE ${example}.cpp)
target_link_libraries(beman.exemplar.examples.${example} beman::exemplar)
target_compile_features(beman.exemplar.examples.${example} PRIVATE cxx_std_${cpp_standard})
endforeach()

0 comments on commit f2aca35

Please sign in to comment.