-
Notifications
You must be signed in to change notification settings - Fork 47
/
CMakeLists.txt
105 lines (86 loc) · 3.27 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
cmake_minimum_required(VERSION 3.16.3)
project(Forge-Examples LANGUAGES CXX)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
set(FORGE_BUILD_TREE OFF)
if(Forge_BINARY_DIR AND EXISTS "${Forge_BINARY_DIR}")
set(Forge_DIR ${Forge_BINARY_DIR})
set(FORGE_BUILD_TREE ON)
endif()
find_package(OpenCL 1.2 QUIET)
find_package(CUDA QUIET)
find_package(Forge REQUIRED)
include(CMakeParseArguments)
include(CMakeDependentOption)
include(InternalUtils)
include(build_cl2hpp)
cmake_dependent_option(FG_BUILD_OPENCL_EXAMPLES
"Build opencl examples" ON
"OpenCL_FOUND;FG_BUILD_EXAMPLES" OFF)
cmake_dependent_option(FG_BUILD_CUDA_EXAMPLES
"Build cuda examples" ON
"CUDA_FOUND;FG_BUILD_EXAMPLES" OFF)
fg_deprecate(BUILD_EXAMPLES_CUDA FG_BUILD_CUDA_EXAMPLES)
fg_deprecate(BUILD_EXAMPLES_OPENCL FG_BUILD_OPENCL_EXAMPLES)
function(add_example target_name source backend)
set(options CXX11)
set(single_value_args "")
set(multiple_value_args INCLUDE_DIRS LIBRARIES)
cmake_parse_arguments(arg "${options}" "${single_value_args}" "${multiple_value_args}" ${ARGN})
set(target "example_${target_name}_${backend}")
string(TOLOWER ${backend} lowerCaseBackend)
if (${lowerCaseBackend} STREQUAL "cuda")
set(native_cc_flags "")
if (WIN32)
set(native_cc_flags
"-Xcompiler /wd4275 -Xcompiler /bigobj -Xcompiler /EHsc")
endif ()
if (FORGE_BUILD_TREE)
CUDA_INCLUDE_DIRECTORIES(
${Forge_BINARY_DIR}/include
${Forge_SOURCE_DIR}/include
)
else ()
get_target_property(
FORGE_INC_DIRS Forge::forge INTERFACE_INCLUDE_DIRECTORIES)
CUDA_INCLUDE_DIRECTORIES(${FORGE_INC_DIRS})
endif ()
cuda_add_executable(${target} ${source}
OPTIONS
"${native_cc_flags} -D_FORCE_INLINES -Xcudafe \"--diag_suppress=1388\""
)
else ()
add_executable(${target} ${source})
endif ()
set_target_properties(${target} PROPERTIES OUTPUT_NAME "${target_name}")
set_target_properties(${target} PROPERTIES FOLDER Examples/${backend})
if (${arg_CXX11})
set_target_properties(${target} PROPERTIES CXX_STANDARD 11)
endif (${arg_CXX11})
if(WIN32)
target_compile_definitions(${target} PRIVATE OS_WIN WIN32_MEAN_AND_LEAN)
elseif(APPLE)
target_compile_definitions(${target} PRIVATE OS_MAC)
else(WIN32)
target_compile_definitions(${target} PRIVATE OS_LNX)
endif(WIN32)
target_include_directories(${target} PRIVATE ${arg_INCLUDE_DIRS})
if(${lowerCaseBackend} STREQUAL "cuda")
# CUDA backend examples need same LINK keyword(PRIVATE|PUBLIC) used for
# example targets i.e. used by FindCUDA which is empty by default
target_link_libraries(${target} Forge::forge ${arg_LIBRARIES})
else()
target_link_libraries(${target} PRIVATE Forge::forge ${arg_LIBRARIES})
endif()
endfunction()
add_subdirectory(cpu)
conditional_directory(FG_BUILD_CUDA_EXAMPLES cuda)
conditional_directory(FG_BUILD_OPENCL_EXAMPLES opencl)
mark_as_advanced(
CUDA_HOST_COMPILER
CUDA_USE_STATIC_CUDA_RUNTIME
CUDA_rt_LIBRARY
CMAKE_CUDA_HOST_COMPILER
FG_BUILD_CUDA_EXAMPLES
FG_BUILD_OPENCL_EXAMPLES
)