Skip to content

Commit

Permalink
Merge pull request cburstedde#177 from mkirilin/cmake-examples
Browse files Browse the repository at this point in the history
Build cmake examples by default
  • Loading branch information
cburstedde authored Apr 22, 2024
2 parents d95bc14 + db659ab commit 66ad8f4
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,44 @@ endif()

# --- build examples

function(test_sc_example name files)
function(sc_example name files)

add_executable(sc_${name} ${files})

target_link_libraries(sc_${name} PRIVATE SC::SC)
set_target_properties(sc_${name}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}"
LABELS sc
)

# it is not intended to run examples as tests in the top-level SC project
if(NOT PROJECT_IS_TOP_LEVEL)
return()
endif()

if(SC_ENABLE_MPI)
add_test(NAME sc:example:${name} COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} $<TARGET_FILE:sc_${name}>)
else()
add_test(NAME sc:example:${name} COMMAND sc_${name})
endif()

if(WIN32)
set_property(TEST sc:example:${name} PROPERTY ENVIRONMENT_MODIFICATION "PATH=path_list_append:${SC_INCLUDE_DIR}/../bin")
endif()

endfunction(test_sc_example)
endfunction(sc_example)


test_sc_example(function function/function.c)
test_sc_example(logging logging/logging.c)
test_sc_example(test_shmem testing/sc_test_shmem.c)
sc_example(function function/function.c)
sc_example(logging logging/logging.c)
sc_example(test_shmem testing/sc_test_shmem.c)

configure_file(options/sc_options_example.ini sc_options_example.ini COPYONLY)
configure_file(options/sc_options_example.json sc_options_example.json COPYONLY)
configure_file(options/sc_options_preload.ini sc_options_preload.ini COPYONLY)
test_sc_example(options options/options.c)
sc_example(options options/options.c)

# The OpenMP example is disabled
# We are likely removing the OpenMP configuration entirely
#
# if(OpenMP_FOUND)
# test_sc_example(openmp openmp/openmp.c)
# sc_example(openmp openmp/openmp.c)
# target_link_libraries(sc_openmp PRIVATE OpenMP::OpenMP_C)
# endif()

if(CMAKE_USE_PTHREADS_INIT)
test_sc_example(pthread pthread/pthread.c)
sc_example(pthread pthread/pthread.c)
target_link_libraries(sc_pthread PRIVATE Threads::Threads)
endif()

if(SC_ENABLE_V4L2)
test_sc_example(v4l2 v4l2/v4l2.c)
sc_example(v4l2 v4l2/v4l2.c)
endif()

if(NOT PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
Expand Down

0 comments on commit 66ad8f4

Please sign in to comment.