Skip to content

Commit 0faa327

Browse files
committed
Adds experimental support for vcpkg.
1 parent 1dc78a8 commit 0faa327

9 files changed

Lines changed: 257 additions & 83 deletions

File tree

CMakeLists.txt

Lines changed: 80 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
cmake_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+
49
if(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")
614
endif()
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)
115119
endif()
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-
)
237237
endif()
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)
268268
endif()
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
277290
configure_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

282295
write_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

296307
install(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
#

cmake/emu-config.cmake.in

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
11
@PACKAGE_INIT@
22

3+
find_package(Boost CONFIG REQUIRED)
4+
find_package(fmt CONFIG REQUIRED)
5+
find_package(Microsoft.GSL CONFIG REQUIRED)
6+
find_package(mdspan CONFIG REQUIRED)
7+
38
include("${CMAKE_CURRENT_LIST_DIR}/emu-targets.cmake")
9+
10+
if(NOT TARGET emu::emu)
11+
add_library(emu::emu INTERFACE IMPORTED)
12+
13+
if(TARGET emu::core)
14+
set_property(TARGET emu::emu APPEND PROPERTY INTERFACE_LINK_LIBRARIES emu::core)
15+
endif()
16+
if(TARGET emu::cuda)
17+
set_property(TARGET emu::emu APPEND PROPERTY INTERFACE_LINK_LIBRARIES emu::cuda)
18+
endif()
19+
if(TARGET emu::python)
20+
set_property(TARGET emu::emu APPEND PROPERTY INTERFACE_LINK_LIBRARIES emu::python)
21+
endif()
22+
endif()
23+
24+
check_required_components(emu)

conanfile.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class EmuConan(ConanFile):
1212

1313
settings = 'os', 'compiler', 'build_type', 'arch'
1414

15-
exports_sources = 'CMakeLists.txt', 'include/*', 'src/*', 'test/*'
15+
exports_sources = 'CMakeLists.txt', 'include/*', 'src/*', 'test/*', 'cmake/*'
1616

1717
# Generate the logic between shared and fPic
1818
implements = ['auto_shared_fpic']
@@ -70,8 +70,8 @@ def layout(self):
7070
def generate(self):
7171
tc = CMakeToolchain(self)
7272

73-
tc.cache_variables['emu_build_cuda'] = self.options.cuda
74-
tc.cache_variables['emu_build_python_test'] = self.options.python
73+
tc.cache_variables['build_cuda'] = self.options.cuda
74+
tc.cache_variables['build_python_test'] = self.options.python
7575
tc.cache_variables['emu_boost_namespace'] = self.dependencies['boost'].options.namespace
7676

7777
tc.generate()
@@ -89,18 +89,12 @@ def package(self):
8989
cmake.install()
9090

9191
def package_info(self):
92-
self.cpp_info.components['core'].libs = ['emucore']
92+
self.cpp_info.components['core'].libs = ['core']
9393
self.cpp_info.components['core'].requires = [
9494
'fmt::fmt',
9595
'boost::boost',
9696
'ms-gsl::_ms-gsl',
97-
'tl-expected::expected',
98-
'tl-optional::optional',
9997
'mdspan::mdspan',
100-
'half::half',
101-
'dlpack::dlpack',
102-
'range-v3::range-v3'
103-
10498
]
10599

106100
self.cpp_info.components['core'].defines = ['EMU_BOOST_NAMESPACE={}'.format(self.dependencies['boost'].options.namespace)]
@@ -112,9 +106,10 @@ def package_info(self):
112106
if self.options.cuda:
113107
# Conan does not provide a cuda 'package'. conan_cuda allows to retrieve
114108
# cuda lib dir and include dir and append it to emucuda
109+
# TODO: investigate why unused.
115110
cuda_prop = self.python_requires['conan_cuda'].module.properties()
116111

117-
self.cpp_info.components['cuda'].libs = ['emucuda']
112+
self.cpp_info.components['cuda'].libs = ['cuda']
118113
self.cpp_info.components['cuda'].requires = [
119114
'core',
120115
'cuda-api-wrappers::cuda-api-wrappers',

flake.lock

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)