-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
120 lines (102 loc) · 3.47 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
cmake_minimum_required(VERSION 3.14)
project(cddp)
set(CMAKE_CXX_STANDARD 17) # Enforce C++17 as the minimum standard
set(CMAKE_CXX_STANDARD_REQUIRED ON) # Enforce C++17 as the minimum standard
set(ABSL_PROPAGATE_CXX_STD ON) # Enforce C++17 for absl
# Set the default build type to Release
set(CMAKE_BUILD_TYPE "Release")
# Options.
option(CDDP-CPP_BUILD_TESTS
"Whether to build tests." ON
)
# EIGEN
find_package(Eigen3 REQUIRED)
# Enable FetchContent for downloading dependencies
include(FetchContent)
# ABSL
if (NOT TARGET absl::strings OR NOT TARGET absl::status OR NOT TARGET absl::span)
message(STATUS "CDDP-cpp: `absl` targets not found. Attempting to fetch contents...")
FetchContent_Declare(
abseil-cpp
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
GIT_TAG origin/master
)
FetchContent_MakeAvailable(abseil-cpp)
else()
message(STATUS "CDDP-cpp: `absl` targets found.")
endif()
# OSQP
if (NOT TARGET osqpstatic)
message(STATUS "CDDP-cpp: `osqp` targets not found. Attempting to fetch contents...")
FetchContent_Declare(
osqp
GIT_REPOSITORY https://github.com/oxfordcontrol/osqp.git
GIT_TAG v0.6.0
)
FetchContent_MakeAvailable(osqp)
else()
message(STATUS "CDDP-cpp: `osqp` targets found.")
endif()
# OSQP-CPP
if (NOT TARGET osqp-cpp OR NOT TARGET osqpstatic)
message(STATUS "CDDP-cpp: `osqp-cpp` targets not found. Attempting to fetch contents...")
FetchContent_Declare(
osqp-cpp
GIT_REPOSITORY https://github.com/google/osqp-cpp
GIT_TAG master
)
FetchContent_MakeAvailable(osqp-cpp)
else()
message(STATUS "CDDP-cpp: `osqp-cpp` targets found.")
find_package(osqp-cpp REQUIRED)
endif()
# Matplotplusplus
if (NOT TARGET matplot)
message(STATUS "CDDP-cpp: `matplot` targets not found. Attempting to fetch contents...")
FetchContent_Declare(
matplotplusplus
GIT_REPOSITORY https://github.com/alandefreitas/matplotplusplus
GIT_TAG origin/master
)
FetchContent_GetProperties(matplotplusplus)
if(NOT matplotplusplus_POPULATED)
FetchContent_Populate(matplotplusplus)
add_subdirectory(${matplotplusplus_SOURCE_DIR} ${matplotplusplus_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
else()
message(STATUS "CDDP-cpp: `matplot` targets found.")
endif()
# Googletest
if (CDDP-CPP_BUILD_TESTS)
enable_testing()
if (NOT TARGET gtest OR NOT TARGET gmock OR NOT TARGET gtest_main)
message(STATUS "CDDP-cpp: `googletest` targets not found. Attempting to fetch contents...")
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG origin/main
)
FetchContent_MakeAvailable(googletest)
include(GoogleTest)
else()
message(STATUS "CDDP-cpp: `googletest` targets found.")
endif()
endif()
# # Add the include directory
# include_directories(include/cddp)
# Add the main library
message(STATUS "CDDP-cpp: Adding CDDP-cpp library...")
add_library(cddp src/cddp_core/CDDPProblem.cpp)
target_link_libraries(cddp PUBLIC
Eigen3::Eigen
PRIVATE osqp-cpp ${CMAKE_DL_LIBS})
target_include_directories(cddp PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
include/cddp)
message(STATUS "CDDP-cpp: Added CDDP-cpp library.")
# Eigen test (Placeholder for now, will be removed later on)
add_executable(cddp_eigen_test test/test_eigen.cpp)
target_link_libraries(cddp_eigen_test Eigen3::Eigen)
# LOCAL TEST
add_subdirectory(test)