Skip to content

Commit 9be1dfd

Browse files
authored
patched CMake install (#616)
This resolves the issues highlighted in #611 while maintaining QuEST's header include structure in the source
1 parent ce95cf2 commit 9be1dfd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+90
-59
lines changed

CMakeLists.txt

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ message(STATUS "Library will be named lib${LIB_NAME}. Set LIB_NAME to modify.")
6767
option(VERBOSE_LIB_NAME "Modify library name based on compilation configuration. Turned OFF by default." OFF)
6868
message(STATUS "Verbose library naming is turned ${VERBOSE_LIB_NAME}. Set VERBOSE_LIB_NAME to modify.")
6969

70+
if (VERBOSE_LIB_NAME)
71+
# Same headers will be used for several verbosely-named libraries
72+
set(MULTI_LIB_HEADERS 1)
73+
function(compile_option VAR VALUE)
74+
target_compile_definitions(QuEST PUBLIC ${VAR}=${VALUE})
75+
endfunction()
76+
else()
77+
# Headers will be used for a single library with a single valid configuration
78+
set(MULTI_LIB_HEADERS 0)
79+
function(compile_option VAR VALUE)
80+
target_compile_definitions(QuEST PRIVATE ${VAR}=${VALUE})
81+
set(${VAR} ${VALUE})
82+
endfunction()
83+
endif()
84+
85+
7086
# Precision
7187
set(FLOAT_PRECISION 2
7288
CACHE
@@ -253,8 +269,8 @@ target_include_directories(QuEST
253269
PUBLIC
254270
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/quest/include>
255271
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
272+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
256273
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
257-
$<INSTALL_INTERFACE:${ORG_INSTALL_PATH}>
258274
)
259275
set_target_properties(QuEST PROPERTIES
260276
VERSION ${PROJECT_VERSION}
@@ -283,7 +299,7 @@ target_compile_options(QuEST
283299

284300

285301
# Set user options
286-
target_compile_definitions(QuEST PUBLIC FLOAT_PRECISION=${FLOAT_PRECISION})
302+
compile_option(FLOAT_PRECISION ${FLOAT_PRECISION})
287303

288304
if (ENABLE_MULTITHREADING)
289305

@@ -299,7 +315,7 @@ if (ENABLE_MULTITHREADING)
299315
message(FATAL_ERROR ${ErrorMsg})
300316
endif()
301317

302-
target_compile_definitions(QuEST PUBLIC COMPILE_OPENMP=1)
318+
compile_option(COMPILE_OPENMP 1)
303319
target_link_libraries(QuEST
304320
PRIVATE
305321
OpenMP::OpenMP_CXX
@@ -317,14 +333,14 @@ else()
317333
target_compile_options(QuEST PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-Wno-unknown-pragmas>)
318334
endif()
319335

320-
target_compile_definitions(QuEST PUBLIC COMPILE_OPENMP=0)
336+
compile_option(COMPILE_OPENMP 0)
321337
endif()
322338

323339
if (ENABLE_DISTRIBUTION)
324340
find_package(MPI REQUIRED
325341
COMPONENTS CXX
326342
)
327-
target_compile_definitions(QuEST PUBLIC COMPILE_MPI=1)
343+
compile_option(COMPILE_MPI 1)
328344
target_link_libraries(QuEST
329345
PRIVATE
330346
MPI::MPI_CXX
@@ -333,7 +349,7 @@ if (ENABLE_DISTRIBUTION)
333349
string(CONCAT LIB_NAME ${LIB_NAME} "+mpi")
334350
endif()
335351
else()
336-
target_compile_definitions(QuEST PUBLIC COMPILE_MPI=0)
352+
compile_option(COMPILE_MPI 0)
337353
endif()
338354

339355
if (ENABLE_CUDA)
@@ -357,14 +373,14 @@ endif()
357373

358374
if (ENABLE_CUQUANTUM)
359375
find_package(CUQUANTUM REQUIRED)
360-
target_compile_definitions(QuEST PUBLIC COMPILE_CUQUANTUM=1)
376+
compile_option(COMPILE_CUQUANTUM 1)
361377
target_link_libraries(QuEST PRIVATE CUQUANTUM::cuStateVec)
362378
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
363379
if (VERBOSE_LIB_NAME)
364380
string(CONCAT LIB_NAME ${LIB_NAME} "+cuquantum")
365381
endif()
366382
else()
367-
target_compile_definitions(QuEST PUBLIC COMPILE_CUQUANTUM=0)
383+
compile_option(COMPILE_CUQUANTUM 0)
368384
endif()
369385

370386
if (ENABLE_HIP)
@@ -384,7 +400,7 @@ if (ENABLE_HIP)
384400
find_package(HIP REQUIRED)
385401
message(STATUS "Found HIP: " ${HIP_VERSION})
386402

387-
target_compile_definitions(QuEST PUBLIC COMPILE_CUQUANTUM=0)
403+
compile_option(COMPILE_CUQUANTUM 0)
388404
target_link_libraries(QuEST PRIVATE hip::host)
389405

390406
if (VERBOSE_LIB_NAME)
@@ -393,9 +409,9 @@ if (ENABLE_HIP)
393409
endif()
394410

395411
if (ENABLE_CUDA OR ENABLE_HIP)
396-
target_compile_definitions(QuEST PUBLIC COMPILE_CUDA=1)
412+
compile_option(COMPILE_CUDA 1)
397413
else()
398-
target_compile_definitions(QuEST PUBLIC COMPILE_CUDA=0)
414+
compile_option(COMPILE_CUDA 0)
399415
endif()
400416

401417
if (ENABLE_DEPRECATED_API)
@@ -533,27 +549,36 @@ set(QuEST_INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/QuEST")
533549

534550
# Write QuESTConfigVersion.cmake
535551
write_basic_package_version_file(
536-
"${CMAKE_CURRENT_BINARY_DIR}/QuESTConfigVersion.cmake"
552+
"${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME}ConfigVersion.cmake"
537553
VERSION ${PROJECT_VERSION}
538554
COMPATIBILITY AnyNewerVersion
539555
)
540556

541557
# Configure QuESTConfig.cmake (from template)
542558
configure_package_config_file(
543559
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/QuESTConfig.cmake.in"
544-
"${CMAKE_CURRENT_BINARY_DIR}/QuESTConfig.cmake"
560+
"${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME}Config.cmake"
545561
INSTALL_DESTINATION "${QuEST_INSTALL_CONFIGDIR}"
546562
)
547563

548564
# Install them
549565
install(FILES
550-
"${CMAKE_CURRENT_BINARY_DIR}/QuESTConfig.cmake"
551-
"${CMAKE_CURRENT_BINARY_DIR}/QuESTConfigVersion.cmake"
566+
"${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME}Config.cmake"
567+
"${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME}ConfigVersion.cmake"
552568
DESTINATION "${QuEST_INSTALL_CONFIGDIR}"
553569
)
554570

571+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/quest.h"
572+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
573+
)
574+
575+
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/quest/include"
576+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/quest"
577+
FILES_MATCHING PATTERN "*.h"
578+
)
579+
555580
install(EXPORT QuESTTargets
556-
FILE QuESTTargets.cmake
581+
FILE "${LIB_NAME}Targets.cmake"
557582
NAMESPACE QuEST::
558583
DESTINATION "${QuEST_INSTALL_CONFIGDIR}"
559584
)

cmake/QuESTConfig.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# @author Erich Essmann
22

33
@PACKAGE_INIT@
4-
include("${CMAKE_CURRENT_LIST_DIR}/QuESTTargets.cmake")
4+
include("${CMAKE_CURRENT_LIST_DIR}/@LIB_NAME@Targets.cmake")

quest/include/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# @author Oliver Thomson Brown
22
# @author Erich Essmann
33

4-
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
5-
DESTINATION "${CMAKE_INSTALL_PREFIX}"
6-
FILES_MATCHING PATTERN "*.h"
7-
)
4+
configure_file(quest.h.in "${CMAKE_BINARY_DIR}/include/quest.h" @ONLY)

quest/include/deprecated.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#ifndef DEPRECATED_H
1919
#define DEPRECATED_H
2020

21-
#include "quest/include/quest.h"
21+
#include "quest.h"
2222

2323
#include "stdlib.h"
2424

quest/include/quest.h renamed to quest/include/quest.h.in

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@
3030
#define QUEST_H
3131

3232

33+
#if !@MULTI_LIB_HEADERS@
34+
#cmakedefine FLOAT_PRECISION @FLOAT_PRECISION@
35+
#cmakedefine01 COMPILE_MPI
36+
#cmakedefine01 COMPILE_OPENMP
37+
#cmakedefine01 COMPILE_CUDA
38+
#cmakedefine01 COMPILE_CUQUANTUM
39+
#endif
40+
41+
3342
// include version first so it is accessible to
3443
// debuggers in case a subsequent include fails
3544
#include "quest/include/version.h"
@@ -60,4 +69,4 @@
6069

6170

6271

63-
#endif // QUEST_H
72+
#endif // QUEST_H

tests/deprecated/test_calculations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// warnings issued by its compilation
2121
#define INCLUDE_DEPRECATED_FUNCTIONS 1
2222
#define DISABLE_DEPRECATION_WARNINGS 1
23-
#include "quest/include/quest.h"
23+
#include "quest.h"
2424

2525
#include "test_utilities.hpp"
2626

tests/deprecated/test_data_structures.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// warnings issued by its compilation
2121
#define INCLUDE_DEPRECATED_FUNCTIONS 1
2222
#define DISABLE_DEPRECATION_WARNINGS 1
23-
#include "quest/include/quest.h"
23+
#include "quest.h"
2424

2525
#include "test_utilities.hpp"
2626

tests/deprecated/test_gates.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// warnings issued by its compilation
2424
#define INCLUDE_DEPRECATED_FUNCTIONS 1
2525
#define DISABLE_DEPRECATION_WARNINGS 1
26-
#include "quest/include/quest.h"
26+
#include "quest.h"
2727

2828
#include "test_utilities.hpp"
2929

tests/deprecated/test_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define INCLUDE_DEPRECATED_FUNCTIONS 1
2222
#define DISABLE_DEPRECATION_WARNINGS 1
2323

24-
#include "quest/include/quest.h"
24+
#include "quest.h"
2525
#include "test_utilities.hpp"
2626

2727
#include <stdexcept>

tests/deprecated/test_operators.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// warnings issued by its compilation
2121
#define INCLUDE_DEPRECATED_FUNCTIONS 1
2222
#define DISABLE_DEPRECATION_WARNINGS 1
23-
#include "quest/include/quest.h"
23+
#include "quest.h"
2424

2525
#include "test_utilities.hpp"
2626

0 commit comments

Comments
 (0)