Skip to content

Commit fb527b1

Browse files
authored
Install examples along with OCCA (#792)
* Install all the codegen files together * Minor refactoring in CMakeListst.txt * Install examples
1 parent 4bf0d6f commit fb527b1

File tree

4 files changed

+38
-51
lines changed

4 files changed

+38
-51
lines changed

cmake/CodeGen.cmake

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,8 @@ else()
2929
endif()
3030

3131
# Set installtion of files required in header
32-
install(
33-
FILES ${OCCA_BUILD_DIR}/include/codegen/kernelOperators.cpp_codegen
34-
DESTINATION include/codegen)
35-
install(
36-
FILES ${OCCA_BUILD_DIR}/include/codegen/kernelOperators.hpp_codegen
37-
DESTINATION include/codegen)
38-
install(
39-
FILES ${OCCA_BUILD_DIR}/include/codegen/macros.hpp_codegen
40-
DESTINATION include/codegen)
41-
install(
42-
FILES ${OCCA_BUILD_DIR}/include/codegen/runFunction.cpp_codegen
32+
install(FILES ${OCCA_BUILD_DIR}/include/codegen/kernelOperators.cpp_codegen
33+
${OCCA_BUILD_DIR}/include/codegen/kernelOperators.hpp_codegen
34+
${OCCA_BUILD_DIR}/include/codegen/macros.hpp_codegen
35+
${OCCA_BUILD_DIR}/include/codegen/runFunction.cpp_codegen
4336
DESTINATION include/codegen)

examples/CMakeLists.txt

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,47 +30,44 @@ macro(add_test_without_mode exe)
3030
set_property(TEST ${exe} APPEND PROPERTY ENVIRONMENT OCCA_CACHE_DIR=${OCCA_BUILD_DIR}/occa)
3131
endmacro()
3232

33-
macro(compile_c_example target file)
34-
add_executable(examples_c_${target} ${file})
35-
target_link_libraries(examples_c_${target} libocca)
36-
target_include_directories(examples_c_${target} PRIVATE
37-
$<BUILD_INTERFACE:${OCCA_SOURCE_DIR}/src>)
38-
if (OCCA_ENABLE_TESTS)
39-
add_test_with_modes(examples_c_${target})
33+
macro(compile_example target file mode)
34+
add_executable(${target} ${file})
35+
target_link_libraries(${target} libocca)
36+
target_include_directories(${target} PRIVATE $<BUILD_INTERFACE:${OCCA_SOURCE_DIR}/src>)
37+
38+
file(RELATIVE_PATH install_dir ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_LIST_DIR})
39+
file(GLOB_RECURSE OKLS "${CMAKE_CURRENT_LIST_DIR}/*.okl")
40+
install(TARGETS ${target} DESTINATION ${install_dir})
41+
install(FILES ${OKLS} DESTINATION ${install_dir})
42+
43+
if (NOT DEFINED OCCA_ENABLE_TESTS)
44+
return()
45+
endif()
46+
if (${mode})
47+
add_test_with_modes(${target})
48+
else()
49+
add_test_without_mode(${target})
4050
endif()
4151
endmacro()
4252

53+
macro(compile_c_example target file)
54+
compile_example(examples_c_${target} ${file} TRUE)
55+
endmacro()
56+
4357
macro(compile_cpp_example target file)
44-
add_executable(examples_cpp_${target} ${file})
45-
target_link_libraries(examples_cpp_${target} libocca)
46-
target_include_directories(examples_cpp_${target} PRIVATE
47-
$<BUILD_INTERFACE:${OCCA_SOURCE_DIR}/src>)
48-
if (OCCA_ENABLE_TESTS)
49-
add_test_without_mode(examples_cpp_${target})
50-
endif()
58+
compile_example(examples_cpp_${target} ${file} FALSE)
5159
endmacro()
5260

5361
macro(compile_cpp_example_with_modes target file)
54-
add_executable(examples_cpp_${target} ${file})
55-
target_link_libraries(examples_cpp_${target} libocca)
56-
target_include_directories(examples_cpp_${target} PRIVATE
57-
$<BUILD_INTERFACE:${OCCA_SOURCE_DIR}/src>)
58-
if (OCCA_ENABLE_TESTS)
59-
add_test_with_modes(examples_cpp_${target})
60-
endif()
62+
compile_example(examples_cpp_${target} ${file} TRUE)
63+
endmacro()
64+
65+
macro(compile_fortran_example_with_modes target file)
66+
compile_example(examples_fortran_${target} ${file} TRUE)
6167
endmacro()
6268

6369
add_subdirectory(c)
6470
add_subdirectory(cpp)
65-
6671
if (OCCA_ENABLE_FORTRAN)
67-
macro(compile_fortran_example_with_modes target file)
68-
add_executable(examples_fortran_${target} ${file})
69-
target_link_libraries(examples_fortran_${target} libocca)
70-
if (OCCA_ENABLE_TESTS)
71-
add_test_with_modes(examples_fortran_${target})
72-
endif()
73-
endmacro()
74-
7572
add_subdirectory(fortran)
7673
endif()

examples/cpp/31_oklt_v3_moving_avg/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ add_custom_target(cpp_example_oklt_v3_moving_avg_cpy ALL
44
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/constants.h constants.h
55
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/movingAverage.okl movingAverage.okl)
66
add_dependencies(examples_cpp_oklt_v3_moving_avg cpp_example_oklt_v3_moving_avg_cpy)
7-
target_sources(examples_cpp_oklt_v3_moving_avg
8-
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/movingAverage.okl
9-
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/constants.h
10-
)
7+
target_sources(examples_cpp_oklt_v3_moving_avg
8+
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/movingAverage.okl
9+
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/constants.h)

examples/cpp/CMakeLists.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ add_subdirectory(12_native_opencl_kernels)
1212
add_subdirectory(13_openmp_interop)
1313
add_subdirectory(14_cuda_interop)
1414
add_subdirectory(17_memory_pool)
15-
15+
# Don't force-compile OpenGL examples
16+
# add_subdirectory(16_finite_difference)
17+
# add_subdirectory(17_mandelbulb)
1618
add_subdirectory(18_nonblocking_streams)
1719
add_subdirectory(19_stream_tags)
1820
add_subdirectory(20_native_dpcpp_kernel)
1921
add_subdirectory(30_device_function)
2022

21-
22-
if (OCCA_CLANG_BASED_TRANSPILER)
23+
if (NOT DEFINED OCCA_CLANG_BASED_TRANSPILER)
2324
add_subdirectory(31_oklt_v3_moving_avg)
2425
endif()
25-
# Don't force-compile OpenGL examples
26-
# add_subdirectory(16_finite_difference)
27-
# add_subdirectory(17_mandelbulb)

0 commit comments

Comments
 (0)