-
Notifications
You must be signed in to change notification settings - Fork 10
/
CMakeLists.txt
122 lines (94 loc) · 3.82 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
cmake_minimum_required(VERSION 3.13.4) # CMake 3.13.4 is the currently default in Debian 10 repositories
# Do not allow in-source builds.
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed!\nCreate a \"build\" dir and remove:\n- ${CMAKE_SOURCE_DIR}/CMakeCache.txt\n- ${CMAKE_SOURCE_DIR}/CMakeFiles")
endif()
project(sopt
DESCRIPTION "Sparse OPTimisation using state-of-the-art convex optimisation algorithms."
HOMEPAGE_URL "http://astro-informatics.github.io/sopt/"
LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html
# Enable output of compile commands during generation. If enabled, generates a compile_commands.json file containing the exact compiler calls for all translation units of the project in machine-readable form. This can be consumed by various IDEs and static analysers to provide smarter project diagnostics/completions etc.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# https://stackoverflow.com/a/67410042
# Create a symlink to compile_commands.json located in CMAKE_BINARY_DIR to the project root (works across filesystems)
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_SOURCE_DIR}/compile_commands.json)
# Location of extra cmake includes for the project
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_files)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/build)
# Version and git hash id
find_package(Git)
# Set version variable
set(SOPT_VERSION 5.0.0)
# If git is found and this is a git workdir, then figure out build id
# Stores results in SOPT_VERSION and SOPT_GITREF
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
RESULT_VARIABLE HASH_RESULT
OUTPUT_VARIABLE GIT_HASH
ERROR_QUIET
)
if(HASH_RESULT EQUAL 0)
string(STRIP "${GIT_HASH}" GIT_HASH)
else()
set(GIT_HASH "NA")
endif()
else()
set(GIT_HASH "NA")
endif()
set(SOPT_GITREF ${GIT_HASH})
option(tests "Enable testing" on)
option(benchmarks "Enable benchmarking" off)
option(examples "Enable Examples" on)
option(openmp "Enable OpenMP" on)
option(dompi "Enable MPI" on)
option(docs "Build documentation" off)
option(coverage "Build coverage" off)
option(onnxrt "Enable ONNXruntime interface" off)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build Type" FORCE)
endif()
message(STATUS "Building sopt in ${CMAKE_BUILD_TYPE} mode")
if(tests OR examples)
enable_testing()
endif()
include(compilations)
# search/install dependencies
include(dependencies)
# sets rpath policy explicitly
if(CMAKE_VERSION VERSION_LESS 3.0)
set_property(GLOBAL PROPERTY MACOSX_RPATH ON)
else()
cmake_policy(SET CMP0042 NEW)
endif()
if(SOPT_MPI)
include(DetectIntegerArchitecture)
DetectIntegerArchitecture(SOPT)
endif()
if(tests)
find_package(Catch2)
include(AddCatchTest)
endif()
if(examples)
include(AddExample)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument")
if(tests AND coverage)
# Enable code coverage.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
# Build with debugging information to make the output meaningful.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
# Disable optimizations to get the most accurate results.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
endif()
add_subdirectory(cpp)
# Exports all Sopt so other packages can access it
include(export_sopt)