-
Notifications
You must be signed in to change notification settings - Fork 62
/
CMakeLists.txt
96 lines (84 loc) · 3.1 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
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.14)
project(osqp-cpp)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Options.
option(OSQP-CPP_BUILD_TESTS
"Whether to build tests." ON
)
include(FetchContent)
# ABSL
if (NOT TARGET absl::strings OR NOT TARGET absl::status OR NOT TARGET absl::span)
message(STATUS "osqp-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 "osqp-cpp: `absl` targets found.")
endif()
# EIGEN
# Eigen is usually available as a system package, so we use find_package.
if (NOT TARGET Eigen3::Eigen)
message(STATUS "osqp-cpp: `Eigen3` targets not found. Attempting to find package...")
find_package(Eigen3 3.3.7 REQUIRED NO_MODULE)
else()
message(STATUS "osqp-cpp: `Eigen3` targets found.")
endif()
# OSQP
if (NOT TARGET osqpstatic)
message(STATUS "osqp-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 "osqp-cpp: `osqp` targets found.")
endif()
# Googletest
if (OSQP-CPP_BUILD_TESTS)
enable_testing()
if (NOT TARGET gtest OR NOT TARGET gmock OR NOT TARGET gtest_main)
message(STATUS "osqp-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 "osqp-cpp: `googletest` targets found.")
endif()
endif()
message(STATUS "osqp-cpp: Adding osqp-cpp library...")
add_library(osqp-cpp src/osqp++.cc)
target_link_libraries(osqp-cpp PUBLIC absl::strings absl::status absl::statusor Eigen3::Eigen PRIVATE osqpstatic ${CMAKE_DL_LIBS})
target_include_directories(osqp-cpp PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
message(STATUS "osqp-cpp: Added osqp-cpp library.")
# Build and register tests.
if (OSQP-CPP_BUILD_TESTS)
message(STATUS "osqp-cpp: Adding osqp-cpp tests...")
add_executable(osqp_test test/osqp++_test.cc)
target_link_libraries(osqp_test gtest gmock gtest_main absl::status absl::span osqp-cpp)
gtest_discover_tests(osqp_test)
message(STATUS "osqp-cpp: Added osqp-cpp tests.")
endif()