-
Notifications
You must be signed in to change notification settings - Fork 15
/
CMakeLists.txt
137 lines (120 loc) · 4.29 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
cmake_minimum_required(VERSION 3.5)
project(epigraph)
set(CMAKE_CXX_STANDARD 17)
add_library(epigraph SHARED)
target_include_directories(epigraph PUBLIC include)
target_sources(epigraph PRIVATE
src/parameter.cpp
src/variable.cpp
src/expressions.cpp
src/constraint.cpp
src/problem.cpp
src/wrappers/wrapperBase.cpp
src/wrappers/socpWrapperBase.cpp
src/wrappers/qpWrapperBase.cpp
)
# ==== Solvers ====
# Make sure the repository is cloned with --recurse-submodules.
# Note that enabling certain solvers automatically alters the license.
# Set ENABLE_OSQP to TRUE to enable OSQP solver support. Apache-2.0 License.
# Set ENABLE_ECOS to TRUE to enable ECOS solver support. GPLv3 License.
find_package(Git QUIET)
if(NOT ENABLE_OSQP AND NOT ENABLE_ECOS)
message(FATAL_ERROR "Epigraph: No solvers enabled. Set the appropriate variables for the desired solvers and re-run cmake.")
endif()
# OSQP
if(ENABLE_OSQP)
find_package(osqp QUIET)
if(osqp_FOUND)
message("Using installed OSQP.")
target_link_libraries(epigraph osqp::osqp)
else()
message("Using OSQP from subdirectory.")
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/solvers/osqp
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "Failed to load the OSQP submodule with ${GIT_SUBMOD_RESULT}.")
endif()
add_subdirectory(solvers/osqp)
target_link_libraries(epigraph osqp)
else()
message(FATAL_ERROR "Git is not available or configured incorrectly.")
endif()
endif()
target_sources(epigraph PRIVATE src/wrappers/osqpWrapper.cpp)
target_compile_definitions(epigraph PUBLIC ENABLE_OSQP)
message("Epigraph: OSQP enabled.")
else()
message("Epigraph: OSQP disabled.")
endif()
# ECOS
if(ENABLE_ECOS)
find_package(ecos QUIET)
if(ecos_FOUND)
message("Using installed ECOS.")
target_link_libraries(epigraph ecos::ecos)
else()
message("Using ECOS from subdirectory.")
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/solvers/ecos
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "Failed to load the ECOS submodule with ${GIT_SUBMOD_RESULT}.")
endif()
add_subdirectory(solvers/ecos)
target_link_libraries(epigraph ecos)
else()
message(FATAL_ERROR "Git is not available or configured incorrectly.")
endif()
endif()
target_sources(epigraph PRIVATE src/wrappers/ecosWrapper.cpp)
target_compile_definitions(epigraph PUBLIC ENABLE_ECOS)
message("Epigraph: ECOS enabled.")
else()
message("Epigraph: ECOS disabled.")
endif()
# Set compiler flags
set(DEBUG_OPTIONS "")
set(RELEASE_OPTIONS "")
if(MSVC)
list(APPEND DEBUG_OPTIONS "/Od" "/Wall")
list(APPEND RELEASE_OPTIONS "/O2")
else()
list(APPEND DEBUG_OPTIONS "-O0" "-Wall" "-Wextra")
list(APPEND RELEASE_OPTIONS "-O3")
endif()
find_package(Eigen3 REQUIRED NO_MODULE)
if(TARGET Eigen3::Eigen)
target_link_libraries(epigraph Eigen3::Eigen)
else()
# Conan uses the package name for the target name
target_link_libraries(epigraph Eigen3::Eigen3)
endif()
# ==== Testing ====
find_package(Catch2 QUIET)
option(ENABLE_TESTING "Build tests. Requires Catch2 to be installed."
FALSE)
if(Catch2_FOUND AND ENABLE_TESTING)
if(NOT (ENABLE_OSQP AND ENABLE_ECOS))
message(FATAL_ERROR "Epigraph: Enable all solvers to enable testing.")
endif()
include_directories(epigraph tests)
add_executable(run_tests tests/run_tests.cpp)
target_link_libraries(run_tests epigraph)
message("Epigraph: Testing is enabled.")
# Coverage
if(CMAKE_COMPILER_IS_GNUCXX)
option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang" FALSE)
if(ENABLE_COVERAGE)
message("Epigraph: Code coverage is enabled.")
list(APPEND DEBUG_OPTIONS --coverage -O0)
target_link_libraries(epigraph --coverage)
endif()
endif()
endif()
# ====
target_compile_options(epigraph PUBLIC "$<$<CONFIG:DEBUG>:${DEBUG_OPTIONS}>")
target_compile_options(epigraph PUBLIC "$<$<CONFIG:RELEASE>:${RELEASE_OPTIONS}>")