This repository has been archived by the owner on Jun 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
85 lines (76 loc) · 2.22 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
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(dqcsim
VERSION 0.4.1
DESCRIPTION "C++ bindings for the Delft Quantum & Classical Simulator"
LANGUAGES CXX
)
# Wrapper target
add_library(dqcsim SHARED IMPORTED GLOBAL)
# Build rust project
# NOTE: crate is built at build-time, not configure-time
set(TARGET_DIR ${CMAKE_CURRENT_SOURCE_DIR}/target)
if(CMAKE_BUILD_TYPE STREQUAL Release)
set(BUILD_DIR ${TARGET_DIR}/release)
# NOTE: Using a gen expr in the call to cargo, makes cargo to crash
set(CARGO_BUILD_TYPE --release)
else()
set(BUILD_DIR ${TARGET_DIR}/debug)
endif()
include(ExternalProject)
ExternalProject_Add(
crate
DOWNLOAD_COMMAND ""
CONFIGURE_COMMAND ""
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/rust
BINARY_DIR ${TARGET_DIR}/include
BUILD_ALWAYS ON
BUILD_COMMAND cargo build ${CARGO_BUILD_TYPE} --manifest-path=${CMAKE_CURRENT_SOURCE_DIR}/rust/Cargo.toml --features=bindings
INSTALL_COMMAND ""
)
add_dependencies(dqcsim crate)
# Add dependencies
target_include_directories(dqcsim INTERFACE
$<BUILD_INTERFACE:${TARGET_DIR}/include>
$<INSTALL_INTERFACE:include>
)
set_target_properties(dqcsim PROPERTIES IMPORTED_LOCATION ${BUILD_DIR}/${CMAKE_SHARED_MODULE_PREFIX}dqcsim${CMAKE_SHARED_LIBRARY_SUFFIX})
include(FetchContent)
FetchContent_Declare(cmake-modules
GIT_REPOSITORY https://github.com/abs-tudelft/cmake-modules.git
GIT_TAG master
)
FetchContent_MakeAvailable(cmake-modules)
include(CompileUnits)
add_subdirectory(cpp)
compile_units()
# Install header files
install(
FILES
${TARGET_DIR}/include/dqcsim
${TARGET_DIR}/include/cdqcsim
${TARGET_DIR}/include/dqcsim.h
DESTINATION include
)
# Install shared library
get_target_property(DQCSIM_LIB dqcsim IMPORTED_LOCATION)
install(
FILES ${DQCSIM_LIB}
DESTINATION lib
)
# Install CMake module
include(CMakePackageConfigHelpers)
configure_package_config_file(dqcsimConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/dqcsimConfig.cmake
INSTALL_DESTINATION lib/cmake/dqcsim
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/dqcsimConfigVersion.cmake
VERSION
COMPATIBILITY SameMajorVersion
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/dqcsimConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/dqcsimConfigVersion.cmake
DESTINATION lib/cmake/dqcsim
)