11cmake_minimum_required (VERSION 3.18 )
22
3- # Have to define this variable to let vcpkg know that we need gtest or not.
3+ # Forced to define this variable here to let vcpkg know that we need gtest or not.
4+ option (BUILD_TESTING "Build tests" ON )
5+ # Note: This is not possible to build python test using vcpkg.
6+ option (build_python_test "Enable python test module" OFF )
7+ option (build_cuda "Enable cuda module" OFF )
8+
49if (BUILD_TESTING)
5- list (APPEND VCPKG_MANIFEST_FEATURES "test" )
10+ list (APPEND VCPKG_MANIFEST_FEATURES "tests" )
11+ endif ()
12+ if (build_cuda)
13+ list (APPEND VCPKG_MANIFEST_FEATURES "cuda" )
614endif ()
7-
8- # Note: This is not possible to build python test using vcpkg.
9- option (emu_build_python_test "Enable python test module" OFF )
10- option (emu_build_cuda "Enable cuda module" OFF )
1115
1216# other otions:
1317
@@ -39,17 +43,17 @@ include(GNUInstallDirs)
3943# Emu Core
4044#
4145
42- add_library (emucore )
46+ add_library (core )
4347
44- target_sources (emucore
48+ target_sources (core
4549 PRIVATE
4650 src/core/error.cpp
4751 src/core/pointer.cpp
4852 src/core/dlpack.cpp
4953 src/core/numeric_type.cpp
5054)
5155
52- target_sources (emucore PUBLIC FILE_SET HEADERS BASE_DIRS include /core FILES
56+ target_sources (core PUBLIC FILE_SET HEADERS BASE_DIRS include /core FILES
5357 include /core/emu/blas.hpp
5458 include /core/emu/tuple.hpp
5559 include /core/emu/capsule.hpp
@@ -108,44 +112,41 @@ target_sources(emucore PUBLIC FILE_SET HEADERS BASE_DIRS include/core FILES
108112)
109113
110114
111- target_compile_features (emucore PUBLIC cxx_std_20 )
115+ target_compile_features (core PUBLIC cxx_std_20 )
112116
113- if (emu_build_cuda )
114- target_compile_definitions (emucore PUBLIC EMU_CUDA )
117+ if (build_cuda )
118+ target_compile_definitions (core PUBLIC EMU_CUDA )
115119endif ()
116120
117- target_compile_definitions (emucore PUBLIC EMU_BOOST_NAMESPACE=${emu_boost_namespace} )
121+ target_compile_definitions (core PUBLIC EMU_BOOST_NAMESPACE=${emu_boost_namespace} )
118122
119- find_package (Boost REQUIRED )
120- find_package (fmt REQUIRED )
121- find_package (Microsoft.GSL REQUIRED )
122- find_package (mdspan REQUIRED )
123+ find_package (Boost CONFIG REQUIRED )
124+ find_package (fmt CONFIG REQUIRED )
125+ find_package (Microsoft.GSL CONFIG REQUIRED )
126+ find_package (mdspan CONFIG REQUIRED )
123127
124- target_link_libraries (emucore PUBLIC
128+ target_link_libraries (core PUBLIC
125129 Boost::boost
126130 fmt::fmt
127131 Microsoft.GSL::GSL
128132 std::mdspan
129133)
130134
131- add_library (emu::core ALIAS emucore )
132-
133- install (TARGETS emucore
134- EXPORT ${PROJECT_NAME } -targets
135- FILE_SET HEADERS
136- )
135+ if (NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR )
136+ add_library (emu::core ALIAS core )
137+ endif ()
137138
138139########################################################################
139140#
140141# Emu CUDA
141142#
142143
143- if (emu_build_cuda )
144+ if (build_cuda )
144145 enable_language (CUDA )
145146
146- add_library (emucuda )
147+ add_library (cuda )
147148
148- target_sources (emucuda
149+ target_sources (cuda
149150 PRIVATE
150151 src/cuda/cublas/handle.cpp
151152 src/cuda/cublas/error.cpp
@@ -165,7 +166,7 @@ if (emu_build_cuda)
165166 src/cuda/thrust/execution_policy.cu
166167 )
167168
168- target_sources (emucuda PUBLIC FILE_SET HEADERS BASE_DIRS include /cuda FILES
169+ target_sources (cuda PUBLIC FILE_SET HEADERS BASE_DIRS include /cuda FILES
169170 include /cuda/emu/config.cuh
170171 include /cuda/emu/macro.cuh
171172 include /cuda/emu/thrust.cuh
@@ -201,26 +202,26 @@ if (emu_build_cuda)
201202 include /cuda/emu/test/device_test.hpp
202203 )
203204
204- target_compile_options (emucuda PUBLIC
205+ target_compile_options (cuda PUBLIC
205206 $<$<COMPILE_LANGUAGE :CUDA >:
206207 --extended -lambda
207208 --expt -relaxed -constexpr
208209 >
209210 )
210211 # Only needed for CUDA source file but it's easier to just set it
211- target_compile_definitions (emucuda PUBLIC FMT_USE_CONSTEXPR=1 )
212+ target_compile_definitions (cuda PUBLIC FMT_USE_CONSTEXPR=1 )
212213
213214 # Force the link of emu_cuda_device_pointer symbol in src/cuda/cuda/pointer.cpp
214215 if (NOT BUILD_SHARED_LIBS )
215- target_link_options (emucuda INTERFACE "-Wl,-u,emu_cuda_device_pointer" )
216+ target_link_options (cuda INTERFACE "-Wl,-u,emu_cuda_device_pointer" )
216217 endif ()
217218
218219 find_package (CUDAToolkit REQUIRED )
219220 find_package (cuda-api-wrappers CONFIG REQUIRED )
220221 # find_package(matx REQUIRED)
221222
222- target_link_libraries (emucuda PUBLIC
223- emucore
223+ target_link_libraries (cuda PUBLIC
224+ core
224225 CUDA::cublas
225226 CUDA::cusolver
226227 CUDA::cudart
@@ -229,16 +230,15 @@ if (emu_build_cuda)
229230 # matx::matx
230231 )
231232
232- add_library (emu::cuda ALIAS emucuda )
233+ if (NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR )
234+ add_library (emu::cuda ALIAS cuda )
235+ endif ()
233236
234- install (TARGETS emucuda
235- FILE_SET HEADERS
236- )
237237endif ()
238238
239- add_library (emupython INTERFACE )
239+ add_library (python INTERFACE )
240240
241- target_sources (emupython INTERFACE FILE_SET HEADERS BASE_DIRS include /python FILES
241+ target_sources (python INTERFACE FILE_SET HEADERS BASE_DIRS include /python FILES
242242 include /python/emu/pybind11/numpy.hpp
243243 include /python/emu/pybind11/cast/container.hpp
244244 include /python/emu/pybind11/cast/cstring_view.hpp
@@ -259,44 +259,63 @@ target_sources(emupython INTERFACE FILE_SET HEADERS BASE_DIRS include/python FIL
259259)
260260
261261# We do not link to pybind11 here, we let the consumer do it
262- target_link_libraries (emupython INTERFACE
263- emucore
262+ target_link_libraries (python INTERFACE
263+ core
264264)
265265
266- if (emu_build_cuda )
267- target_link_libraries (emupython INTERFACE emucuda )
266+ if (build_cuda )
267+ target_link_libraries (python INTERFACE cuda )
268268endif ()
269269
270- add_library (emu::python ALIAS emupython )
270+ if (NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR )
271+ add_library (emu::python ALIAS python )
272+ endif ()
271273
272- install (TARGETS emupython
274+ ########################################################################
275+ #
276+ # Install
277+ # What is going on here???
278+
279+ set (INSTALL_TARGETS core python)
280+ if (build_cuda)
281+ list (APPEND INSTALL_TARGETS cuda)
282+ endif ()
283+
284+ install (TARGETS ${INSTALL_TARGETS}
285+ COMPONENT emu-core
286+ EXPORT emu-targets
273287 FILE_SET HEADERS
274288)
275289
276- # Installation help
277290configure_package_config_file (
278- "${PROJECT_SOURCE_DIR } /cmake/${ PROJECT_NAME } -config.cmake.in"
279- "${PROJECT_BINARY_DIR } /${ PROJECT_NAME } -config.cmake"
280- INSTALL_DESTINATION "share/cmake/ ${ PROJECT_NAME } " )
291+ "${PROJECT_SOURCE_DIR } /cmake/emu -config.cmake.in"
292+ "${PROJECT_BINARY_DIR } /emu -config.cmake"
293+ INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR} /cmake/emu " )
281294
282295write_basic_package_version_file (
283- "${PROJECT_BINARY_DIR } /${PROJECT_NAME } -config-version.cmake"
296+ "${PROJECT_BINARY_DIR } /emu-config-version.cmake"
297+ VERSION "${PROJECT_VERSION } "
284298 COMPATIBILITY SameMajorVersion
285- ARCH_INDEPENDENT )
286-
287- # install(TARGETS emucore
288- # EXPORT ${PROJECT_NAME}-targets
289- # INCLUDES DESTINATION "${CMAKE_INSTALL_DATADIR}")
299+ ) INCLUDES DESTINATION "${CMAKE_INSTALL_DATADIR} " )
290300
291- install ( EXPORT ${ PROJECT_NAME } - targets
292- DESTINATION " ${CMAKE_INSTALL_DATADIR} /cmake/ ${ PROJECT_NAME } "
301+ export ( TARGETS
302+ ${INSTALL_TARGETS}
293303 NAMESPACE emu::
294- FILE "${PROJECT_NAME } -targets.cmake" )
304+ FILE "${PROJECT_BINARY_DIR } /emu-targets.cmake"
305+ )
295306
296307install (FILES
297- "${PROJECT_BINARY_DIR } /${PROJECT_NAME } -config-version.cmake"
298- "${PROJECT_BINARY_DIR } /${PROJECT_NAME } -config.cmake"
299- DESTINATION "${CMAKE_INSTALL_DATADIR} /cmake/${PROJECT_NAME } " )
308+ "${PROJECT_BINARY_DIR } /emu-config-version.cmake"
309+ "${PROJECT_BINARY_DIR } /emu-config.cmake"
310+ DESTINATION "${CMAKE_INSTALL_DATADIR} /cmake/emu"
311+ COMPONENT emu-core
312+ )
313+
314+ install (EXPORT emu-targets
315+ DESTINATION "${CMAKE_INSTALL_DATADIR} /cmake/emu"
316+ NAMESPACE emu::
317+ COMPONENT emu-core
318+ )
300319
301320########################################################################
302321#
0 commit comments