-
Notifications
You must be signed in to change notification settings - Fork 91
/
nanortConfig.cmake
105 lines (86 loc) · 3.38 KB
/
nanortConfig.cmake
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
# The MIT License (MIT)
#
# Copyright (c) 2021 Light Transport Entertainment, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
cmake_minimum_required(VERSION 3.1)
if (TARGET nanort::nanort)
return()
endif()
macro(nanort_config_message)
if (NOT DEFINED nanort_FIND_QUIETLY)
message(${ARGN})
endif()
endmacro()
## Setup base target ##
add_library(nanort::core INTERFACE IMPORTED)
target_include_directories(nanort::core INTERFACE ${CMAKE_CURRENT_LIST_DIR})
nanort_config_message(STATUS "Found nanort: ${CMAKE_CURRENT_LIST_DIR}")
nanort_config_message(" --> nanort core target available (nanort::core)")
## Setup target which uses C++11 threads ##
find_package(Threads QUIET)
if (TARGET Threads::Threads)
add_library(nanort::threads INTERFACE IMPORTED)
target_compile_features(nanort::threads
INTERFACE
cxx_std_11
)
target_link_libraries(nanort::threads
INTERFACE
Threads::Threads
nanort::core
)
target_compile_definitions(nanort::threads
INTERFACE
-DNANORT_USE_CPP11_FEATURE
-DNANORT_ENABLE_PARALLEL_BUILD
)
nanort_config_message(" --> nanort C++11 threading target available (nanort::threads)")
else()
nanort_config_message(WARNING "nanort C++11 threading target NOT available! (unable to find Threads)")
endif()
## Setup target which uses OpenMP ##
find_package(OpenMP QUIET)
if (TARGET OpenMP::OpenMP_CXX)
add_library(nanort::openmp INTERFACE IMPORTED)
target_link_libraries(nanort::openmp
INTERFACE
nanort::core
OpenMP::OpenMP_CXX
)
target_compile_definitions(nanort::openmp
INTERFACE
-DNANORT_ENABLE_PARALLEL_BUILD
)
nanort_config_message(" --> nanort OpenMP target available (nanort::openmp)")
else()
nanort_config_message(WARNING "nanort OpenMP target NOT available! (unable to find OpenMP)")
endif()
## Setup a target which uses the "best" available version ##
add_library(nanort::nanort INTERFACE IMPORTED)
if (TARGET nanort::openmp)
target_link_libraries(nanort::nanort INTERFACE nanort::openmp)
nanort_config_message(" --> default target (nanort::nanort) uses OpenMP")
elseif (TARGET nanort::threads)
target_link_libraries(nanort::nanort INTERFACE nanort::threads)
nanort_config_message(" --> default target (nanort::nanort) uses C++11 threads")
else()
target_link_libraries(nanort::nanort INTERFACE nanort::core)
nanort_config_message(" --> default target (nanort::nanort) uses only core nanort")
endif()