-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
155 lines (113 loc) · 2.98 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
############
# Sparse2D #
############
# -------------- #
# Project Set Up #
# -------------- #
cmake_minimum_required(VERSION 3.12.0)
project(
Sparse2D
VERSION 3.0
DESCRIPTION "Sparsity-based signal processing tools"
LANGUAGES CXX
)
# Set policy for later versions of CMake
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
# Prohibit in-source builds
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source build is not permitted!")
endif()
# Include custom modules in CMake module path
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# Load CMake tools
include(ExternalProject)
include(FetchContent)
include(FindPkgConfig)
# Load custom CMake functions: find_pkg, build_package, build_pybind
include(FindPkg)
include(BuildPackage)
include(BuildPybind)
include(BuildTests)
# Load Sparse2D build options
include(BuildOptions)
# Set default build type as Release
if(CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Release")
endif()
message(STATUS "CMake Build Type: ${CMAKE_BUILD_TYPE}")
# Set RPATH options
set(CMAKE_INSTALL_RPATH "${CMAKE_BINARY_DIR}/lib")
# ----------------- #
# Find Dependencies #
# ----------------- #
if(BUILD_PYBIND)
# Locate Python
set(Python_FIND_STRATEGY LOCATION)
find_package(Python COMPONENTS Interpreter Development)
include_directories(${Python_INCLUDE_DIRS})
link_directories(${Python_LIBRARY_DIRS})
# Source Pybind11
include(FetchPybind11)
endif()
# Use BigMac for local clang build
if(
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang"
AND NOT "${CMAKE_CXX_COMPILER}" MATCHES "Homebrew"
)
find_package(BigMac 0.0.6 REQUIRED)
endif()
# Locate OpenMP
find_package(OpenMP REQUIRED)
# Locate Catch2
find_package(Catch2 3)
# Locate CFITSIO
find_pkg(CFITSIO cfitsio)
if(USE_FFTW)
# Locate FFTW
find_pkg(FFTW3 "fftw3 fftw3f")
endif()
if(BUILD_MR)
# Locate GSL
find_pkg(GSL gsl)
endif()
if(BUILD_MRS)
# Locate HEALPix
find_pkg(HEALPIX healpix_cxx)
endif()
if(BUILD_DICLEARN)
# Locate GSL
find_pkg(GSL gsl)
# Locate Armadillo
find_package(Armadillo)
include_directories(${ARMADILLO_INCLUDE_DIRS})
endif()
# ------------------ #
# Compilation Set Up #
# ------------------ #
# Set CXX options
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Set CXX compilation flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BigMac_NOWARN} -DNO_DISP_IO -w -Wno-everything -D_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION")
if(USE_FFTW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_FFTW")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS}")
# -------------- #
# Build Sources #
# -------------- #
# Build packages in the source directory
add_subdirectory(src)
# ---------- #
# Unit Tests #
# -----------#
if(Catch2_FOUND)
# Enable unit Tests
enable_testing()
# Build unit tests
add_subdirectory(tests)
endif()