forked from NVIDIA/cudaqx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
168 lines (139 loc) · 5.58 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# ============================================================================ #
# Copyright (c) 2024 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #
set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "" FORCE)
# We need 3.28 because of the `EXCLUDE_FROM_ALL` in FetchContent_Declare
cmake_minimum_required(VERSION 3.28 FATAL_ERROR)
project(CUDAQX
VERSION 0.0.0
LANGUAGES C CXX)
set(CUDAQX_ALL_LIBS "qec;solvers")
set(CUDAQX_ENABLE_LIBS "" CACHE STRING
"Semicolon-separated list of libs to build (${CUDAQX_ALL_LIBS}), or \"all\".")
# We don't want to handle "all" later, thus expand it here.
if(CUDAQX_ENABLE_LIBS STREQUAL "all" )
set(CUDAQX_ENABLE_LIBS ${CUDAQX_ALL_LIBS})
endif()
# Sanity check.
foreach(lib ${CUDAQX_ENABLE_LIBS})
if (NOT "${lib}" IN_LIST CUDAQX_ALL_LIBS)
message(FATAL_ERROR "${lib} isn't a known library: ${CUDAQX_ALL_LIBS}.")
endif()
endforeach()
# Project setup
# ==============================================================================
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Add our Modules to the path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
# Include custom CUDA-QX modules
include(CUDA-QX)
# Options
# ==============================================================================
option(CUDAQX_INCLUDE_TESTS "Generate build targets for unit tests." OFF)
option(CUDAQX_INCLUDE_DOCS "Generate build targets for the docs." OFF)
option(CUDAQX_BINDINGS_PYTHON "Generate build targets for python bindings." OFF)
# Top-level External Dependencies
# ==============================================================================
# FIXME for now, we only use library mode
set(CUDAQ_LIBRARY_MODE ON)
find_package(CUDAQ REQUIRED)
# Top-level targets
# ==============================================================================
# Helper targets to collect libraries and python modules
add_custom_target(cudaqx-pymodules)
# Top-level testing
# ==============================================================================
if (CUDAQX_INCLUDE_TESTS)
include(CTest)
add_custom_target(CUDAQXUnitTests)
add_custom_target(run_tests
COMMAND ${CMAKE_COMMAND} -E env
PYTHONPATH="${CUDAQ_INSTALL_DIR}:${CMAKE_BINARY_DIR}/python"
${CMAKE_CTEST_COMMAND} --output-on-failure
DEPENDS CUDAQXUnitTests
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
if (CUDAQX_BINDINGS_PYTHON)
set(PYTHON_TEST_DIRS "")
foreach(lib ${CUDAQX_ENABLE_LIBS})
list(APPEND PYTHON_TEST_DIRS ../libs/${lib}/python/tests)
endforeach()
add_custom_target(run_python_tests
COMMAND ${CMAKE_COMMAND} -E env
PYTHONPATH="${CUDAQ_INSTALL_DIR}:${CMAKE_BINARY_DIR}/python"
pytest -v ${PYTHON_TEST_DIRS}
DEPENDS cudaqx-pymodules
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()
endif()
# Hooks setup. If the repo contains a custom pre-push hook, attempt to install
# it. If the user has a different one installed, then warn them but do not fail
# configuration.
# ==============================================================================
# Define the directory where your hooks are stored
set(SRC_HOOK_PRE_PUSH "${CMAKE_SOURCE_DIR}/.githooks/pre-push")
if(EXISTS "${SRC_HOOK_PRE_PUSH}")
# Get the Git hooks directory from the Git configuration
execute_process(
COMMAND git config --get core.hooksPath
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_HOOKS_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Determine the target hooks directory
if(GIT_HOOKS_DIR)
set(TARGET_HOOKS_DIR "${GIT_HOOKS_DIR}")
else()
set(TARGET_HOOKS_DIR "${CMAKE_SOURCE_DIR}/.git/hooks")
endif()
set(DST_HOOK_PRE_PUSH "${TARGET_HOOKS_DIR}/pre-push")
if(EXISTS "${DST_HOOK_PRE_PUSH}")
# Compare the contents of the src and dst hook.
execute_process(
COMMAND git hash-object "${DST_HOOK_PRE_PUSH}"
OUTPUT_VARIABLE SHA_DST
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git hash-object "${SRC_HOOK_PRE_PUSH}"
OUTPUT_VARIABLE SHA_SRC
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT SHA_SRC STREQUAL SHA_DST)
message(WARNING
"You already have a ${DST_HOOK_PRE_PUSH} script installed. "
"This configuration script will not overwrite it despite the fact that "
"it is strongly recommended to use ${SRC_HOOK_PRE_PUSH} in your environment."
"\nProceed with caution!")
endif()
else()
if(EXISTS "${TARGET_HOOKS_DIR}")
file(COPY "${SRC_HOOK_PRE_PUSH}"
DESTINATION "${TARGET_HOOKS_DIR}"
FILE_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
message(STATUS "Git pre-push hook installed to ${TARGET_HOOKS_DIR}")
else()
message(WARNING
"The Git hooks directory does not exist: ${TARGET_HOOKS_DIR}\n"
"Are you sure this is a Git repository? Hook cannot be installed."
)
endif()
endif()
endif()
# Directory setup
# ==============================================================================
add_subdirectory(libs/core)
if (CUDAQX_INCLUDE_DOCS)
add_subdirectory(docs)
endif()
foreach(lib ${CUDAQX_ENABLE_LIBS})
add_subdirectory(libs/${lib})
endforeach()