-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
166 lines (136 loc) · 4.57 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
cmake_minimum_required(VERSION 3.10)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type specified, defaulting to Release")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE)
endif()
set(CMAKE_CXX_STANDARD 11)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
# extract version information from header file
if (NOT SPARSEIR_VERSION)
include("VersionFromHeader")
version_from_header(SPARSEIR_VERSION
HEADER "include/sparseir/version.h"
MACROS SPARSEIR_VERSION_MAJOR SPARSEIR_VERSION_MINOR SPARSEIR_VERSION_PATCH
)
message(STATUS "Extracted package version: ${SPARSEIR_VERSION}")
set(SPARSEIR_VERSION "${SPARSEIR_VERSION}"
CACHE STRING "version of the sparseir package")
mark_as_advanced(SPARSEIR_VERSION)
endif()
# Configure project
project(
SparseIR
LANGUAGES CXX
VERSION "${SPARSEIR_VERSION}"
DESCRIPTION "SparseIR library"
)
# Add Fortran language support if building Fortran bindings
option(SPARSEIR_BUILD_FORTRAN "Build Fortran bindings" OFF)
if(SPARSEIR_BUILD_FORTRAN)
enable_language(Fortran)
message(STATUS "Fortran support enabled for building Fortran bindings")
endif()
# Eigen3
set(EIGEN3_REQUIRED_VERSION "3.4.0")
find_package (Eigen3 ${EIGEN3_REQUIRED_VERSION} QUIET NO_MODULE)
if(NOT Eigen3_FOUND)
message(STATUS "Eigen3 not found in system, fetching from GitHub...")
include(FetchContent)
FetchContent_Declare(Eigen3
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG ${EIGEN3_REQUIRED_VERSION}
)
FetchContent_MakeAvailable(Eigen3)
message(STATUS "Eigen3 fetched from GitHub")
else()
message(STATUS "Eigen3 found in system: ${Eigen3_VERSION}")
endif()
find_package(Threads REQUIRED)
# libxprec - built only as a static dependency, not for installation
include(FetchContent)
FetchContent_Declare(XPrec
GIT_REPOSITORY https://github.com/tuwien-cms/libxprec
GIT_TAG mainline
)
# Extract the content but don't process it through add_subdirectory
FetchContent_GetProperties(XPrec)
if(NOT xprec_POPULATED)
FetchContent_Populate(XPrec)
message(STATUS "XPrec source directory: ${xprec_SOURCE_DIR}")
endif()
# Add XPrec include directory
include_directories(${xprec_SOURCE_DIR}/include)
# ---------------------------------
# Building
# Enable debug logging
#add_definitions(-DDEBUG_CINTERFACE)
# Set the default component name for installations
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME sparseir)
add_library(sparseir SHARED
src/utils.cpp
src/linalg.cpp
src/root.cpp
src/specfuncs.cpp
src/svd.cpp
src/sve.cpp
src/poly.cpp
src/kernel.cpp
src/cinterface.cpp
)
if(NOT MSVC)
target_compile_options(sparseir PRIVATE -Wall -Wextra -pedantic)
endif()
target_include_directories(sparseir PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${XPrec_SOURCE_DIR}/include>
)
set_target_properties(sparseir PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
)
target_link_libraries(sparseir PRIVATE Eigen3::Eigen Threads::Threads)
# Use library convention.
add_library(SparseIR::sparseir ALIAS sparseir)
# Build Fortran bindings if enabled
if(SPARSEIR_BUILD_FORTRAN)
add_subdirectory(fortran)
endif()
# Add include paths from parent scope if available
# -------------------------------------
# Testing
option(SPARSEIR_BUILD_TESTING "Enable creation of SparseIR tests." ${BUILD_TESTING})
if (SPARSEIR_BUILD_TESTING)
enable_testing()
# Download and configure Catch2 for testing
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0
)
FetchContent_MakeAvailable(Catch2)
# Pass include paths to test subdirectory
add_subdirectory("test")
endif()
# -------------------------------------
# Installation
# Provides CMAKE_INSTALL_* directories
include(GNUInstallDirs)
set(SPARSEIR_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}"
CACHE PATH "directory into which to install sparseir include files")
set(SPARSEIR_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}"
CACHE PATH "directory into which to install sparseir library files")
# Install only the C API library and headers
install(TARGETS sparseir
DESTINATION "${SPARSEIR_INSTALL_LIBDIR}"
COMPONENT sparseir
)
# Install only necessary header files (C API)
install(FILES
include/sparseir/sparseir.h
include/sparseir/version.h
DESTINATION "${SPARSEIR_INSTALL_INCLUDEDIR}/sparseir"
COMPONENT sparseir
)