1- # Common helper functions and defaults for project targets
1+ # Common helper functions and defaults for project targets.
2+ #
3+ # Keep this file lightweight: it should not implement a "mini framework".
24
35function (itlabai_target_defaults target_name )
4- if (CMAKE_CONFIGURATION_TYPES )
5- foreach (_cfg IN LISTS CMAKE_CONFIGURATION_TYPES )
6- string (TOUPPER "${_cfg} " _cfg_upper)
7- string (TOLOWER "${_cfg} " _cfg_lower)
8- set_target_properties (${target_name} PROPERTIES
9- ARCHIVE_OUTPUT_DIRECTORY_${_cfg_upper} "${CMAKE_BINARY_DIR } /lib/${_cfg_lower} "
10- LIBRARY_OUTPUT_DIRECTORY_${_cfg_upper} "${CMAKE_BINARY_DIR } /lib/${_cfg_lower} "
11- RUNTIME_OUTPUT_DIRECTORY_${_cfg_upper} "${CMAKE_BINARY_DIR } /bin/${_cfg_lower} "
12- )
13- endforeach ()
14- else ()
15- set_target_properties (${target_name} PROPERTIES
16- ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR } /lib"
17- LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR } /lib"
18- RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR } /bin"
19- )
20- endif ()
21-
226 if (MSVC )
237 target_compile_options (${target_name} PRIVATE /W4 /permissive- /EHsc )
248 if (ITLABAI_WERROR)
@@ -30,6 +14,7 @@ function(itlabai_target_defaults target_name)
3014 target_compile_options (${target_name} PRIVATE -Werror )
3115 endif ()
3216 endif ()
17+
3318 target_compile_features (${target_name} PRIVATE cxx_std_20 )
3419
3520 # Apply project feature defines to every in-tree target.
@@ -43,91 +28,6 @@ function(itlabai_target_defaults target_name)
4328 endif ()
4429endfunction ()
4530
46- function (itlabai_use_opencv target_name )
47- itlabai_use_externals_scope (_scope ${target_name} )
48- target_link_libraries (${target_name} ${_scope} OpenCV::opencv_world )
49- get_target_property (_tgt_type ${target_name} TYPE)
50- if (NOT _tgt_type STREQUAL "INTERFACE_LIBRARY" )
51- add_dependencies (${target_name} opencv_external )
52- endif ()
53- endfunction ()
54-
55- function (itlabai_use_tbb target_name )
56- itlabai_use_externals_scope (_scope ${target_name} )
57- target_link_libraries (${target_name} ${_scope} TBB::tbb )
58- get_target_property (_tgt_type ${target_name} TYPE)
59- if (NOT _tgt_type STREQUAL "INTERFACE_LIBRARY" )
60- add_dependencies (${target_name} tbb_external )
61- endif ()
62- endfunction ()
63-
64- function (itlabai_use_onednn target_name )
65- itlabai_use_externals_scope (_scope ${target_name} )
66- target_link_libraries (${target_name} ${_scope} dnnl )
67- get_target_property (_tgt_type ${target_name} TYPE)
68- if (NOT _tgt_type STREQUAL "INTERFACE_LIBRARY" )
69- add_dependencies (${target_name} onednn_external )
70- endif ()
71- endfunction ()
72-
73- function (itlabai_use_kokkos target_name )
74- itlabai_use_externals_scope (_scope ${target_name} )
75- target_link_libraries (${target_name} ${_scope} Kokkos_imported )
76- if (ITLABAI_ENABLE_KOKKOS)
77- get_target_property (_tgt_type ${target_name} TYPE)
78- if (NOT _tgt_type STREQUAL "INTERFACE_LIBRARY" )
79- add_dependencies (${target_name} kokkos_external )
80- endif ()
81- endif ()
82- if (MSVC )
83- # Suppress Kokkos header warning C4702 only on targets that use Kokkos.
84- target_compile_options (${target_name} ${_scope} /wd4702 )
85- endif ()
86- endfunction ()
87-
88- function (itlabai_use_openmp target_name )
89- itlabai_use_externals_scope (_scope ${target_name} )
90- target_link_libraries (${target_name} ${_scope} OpenMP::OpenMP_CXX )
91- endfunction ()
92-
93- function (itlabai_use_gtest target_name )
94- itlabai_use_externals_scope (_scope ${target_name} )
95- target_link_libraries (${target_name} ${_scope} gtest_main gtest )
96- get_target_property (_tgt_type ${target_name} TYPE)
97- if (NOT _tgt_type STREQUAL "INTERFACE_LIBRARY" )
98- add_dependencies (${target_name} gtest_external )
99- endif ()
100- endfunction ()
101-
102- function (itlabai_use_externals_scope out_var target_name )
103- get_target_property (_tgt_type ${target_name} TYPE)
104- if (_tgt_type STREQUAL "INTERFACE_LIBRARY" )
105- set (${out_var} INTERFACE PARENT_SCOPE )
106- else ()
107- set (${out_var} PUBLIC PARENT_SCOPE )
108- endif ()
109- endfunction ()
110-
111- function (itlabai_link_externals target_name )
112- foreach (ext IN LISTS ARGN)
113- if (ext STREQUAL "opencv" )
114- itlabai_use_opencv (${target_name} )
115- elseif (ext STREQUAL "tbb" )
116- itlabai_use_tbb (${target_name} )
117- elseif (ext STREQUAL "onednn" )
118- itlabai_use_onednn (${target_name} )
119- elseif (ext STREQUAL "kokkos" )
120- itlabai_use_kokkos (${target_name} )
121- elseif (ext STREQUAL "openmp" )
122- if (ITLABAI_ENABLE_OPENMP)
123- itlabai_use_openmp (${target_name} )
124- endif ()
125- elseif (ext STREQUAL "gtest" )
126- itlabai_use_gtest (${target_name} )
127- endif ()
128- endforeach ()
129- endfunction ()
130-
13131function (itlabai_apply_runtime_rpath target_name )
13232 set (_paths "" )
13333 foreach (_var IN ITEMS ONEDNN_INSTALL_DIR OPENCV_INSTALL_DIR TBB_INSTALL_DIR KOKKOS_INSTALL_DIR)
@@ -146,3 +46,4 @@ function(itlabai_apply_runtime_rpath target_name)
14646 )
14747 endif ()
14848endfunction ()
49+
0 commit comments