forked from QuTech-Delft/libqasm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
103 lines (88 loc) · 3.2 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
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
if(CMAKE_VERSION VERSION_GREATER 3.0)
CMAKE_POLICY(SET CMP0048 NEW)
endif()
project(cqasm CXX)
# Library type option. Default is a static library.
option(
BUILD_SHARED_LIBS
"whether the cqasm library should be built as a shared object or as a static library"
OFF
)
# Whether tests should be built.
option(
LIBQASM_BUILD_TESTS
"whether the tests should be built and added to `make test`"
OFF
)
if (LIBQASM_BUILD_TESTS)
enable_testing()
endif()
# Compatibility mode. When enabled, the legacy API headers in src/library are
# added to the public headers of the cqasm target. To enable this in your CMake
# project, add `option(LIBQASM_COMPAT "" ON)` before the `add_subdirectory`
# command.
option(
LIBQASM_COMPAT
"whether the legacy API headers should be added to the cqasm library"
OFF
)
# Whether the Python module should be built. This should only be enabled for
# setup.py's builds.
option(
LIBQASM_BUILD_PYTHON
"Whether the Python module should be built"
OFF
)
mark_as_advanced(LIBQASM_BUILD_PYTHON)
# Where the Python module should be built.
set(
LIBQASM_PYTHON_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/python/libQasm"
CACHE STRING "Where to install the Python library"
)
mark_as_advanced(LIBQASM_PYTHON_DIR)
# Used to override the (base)name of the Python extension.
set(
LIBQASM_PYTHON_EXT ""
CACHE STRING "Basename for the Python extension, or \"\" to let CMake's SWIG implementation handle it"
)
mark_as_advanced(LIBQASM_PYTHON_EXT)
# The Python library requires the compatibility headers, so make sure those are
# enabled.
if (LIBQASM_BUILD_PYTHON AND NOT LIBQASM_COMPAT)
message(SEND_ERROR "The Python library requires the compatibility headers! Please add -DLIBQASM_COMPAT=ON")
endif()
# Jump to where the new API and the core of libqasm lives.
add_subdirectory(src/cqasm)
# Compatibility mode: provide/test the original API in addition to the new one.
if (LIBQASM_COMPAT)
# Add the compatibility headers to the include path.
target_include_directories(cqasm_objlib INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/library/)
# Make sure to install the headers as well.
include(GNUInstallDirs)
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/library/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp"
)
# If LIBQASM_BUILD_TESTS is also enabled, also add the tests for the
# original API.
if (LIBQASM_BUILD_TESTS)
file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/tests/cpp/*.cpp)
foreach(TEST_SRC ${TEST_SRCS})
get_filename_component(TEST_NAME ${TEST_SRC} NAME_WE)
add_executable(${TEST_NAME} ${TEST_SRC})
target_include_directories(${TEST_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/cpp/doctest)
target_link_libraries(${TEST_NAME} cqasm)
add_test(
NAME ${TEST_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/test_data
COMMAND ${TEST_NAME}
)
endforeach()
endif()
endif()
# Include the tests directory if requested.
if(LIBQASM_BUILD_PYTHON)
add_subdirectory(python)
endif()