forked from qpSWIFT/qpSWIFT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
135 lines (102 loc) · 4.02 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
cmake_minimum_required(VERSION 3.5)
project(
qpSWIFT
VERSION 1.00
DESCRIPTION "qpSWIFT: A Sparse Quadratic Program Solver"
)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/exec)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/arc)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/lib)
#### ---- Options ---- ####
option (QPTESTS "Build Unit Tests" OFF)
option (QPSHAREDLIB "Build Unit Tests" ON)
option (QPDEMOS "Build C and C++ Demos" ON)
#### ----- CXX Standard Flags ----- #####
### Include common install dirs
include(GNUInstallDirs)
set(EXTRA_LIBS "")
if(NOT MSVC)
### Add Standard Math Library
LIST(APPEND EXTRA_LIBS "-lm")
## For Linux add realtime library
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
LIST(APPEND EXTRA_LIBS "-lrt -ldl")
endif ()
endif(NOT MSVC)
### Turn on fPIC option on
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
### Default Build Type Release
if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()
#### ----- CXX Standard Flags ----- #####
add_subdirectory(src)
add_subdirectory(include)
if(QPTESTS)
enable_testing()
add_subdirectory(tests)
endif()
### --- Create Static Library
add_library(qpSWIFT-static STATIC ${qpSWIFT_src})
target_link_libraries(qpSWIFT-static ${EXTRA_LIBS})
set_target_properties(qpSWIFT-static PROPERTIES OUTPUT_NAME qpSWIFT)
target_compile_options(qpSWIFT-static PRIVATE -O3)
target_include_directories(qpSWIFT-static PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}/qpSWIFT>"
)
### --- Create Shared Library
if(QPSHAREDLIB)
add_library(qpSWIFT-shared SHARED ${qpSWIFT_src})
target_link_libraries(qpSWIFT-shared ${EXTRA_LIBS})
set_target_properties(qpSWIFT-shared PROPERTIES OUTPUT_NAME qpSWIFT)
target_include_directories(qpSWIFT-shared PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}/qpSWIFT>"
)
endif()
if(QPDEMOS)
### --- Build C Exectuable
add_executable(runqp)
target_sources(runqp PRIVATE ${PROJECT_SOURCE_DIR}/demo/runqp.c)
target_link_libraries(runqp PRIVATE qpSWIFT-static)
### --- Build Cpp Executable
add_executable(runqpcpp)
target_sources(runqpcpp PRIVATE ${PROJECT_SOURCE_DIR}/demo/runqpcpp.cpp)
target_link_libraries(runqpcpp PRIVATE qpSWIFT-static)
endif()
### ---- Install Static Library ------- ####
install(TARGETS qpSWIFT-static
EXPORT "${PROJECT_NAME}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
### ---- Install Shared Library ------- ####
if(QPSHAREDLIB)
install(TARGETS qpSWIFT-shared
EXPORT "${PROJECT_NAME}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
endif()
install(FILES ${qpSWIFT_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/qpSWIFT")
### ---- Create CMake Package for exporting the target ####
include(CMakePackageConfigHelpers)
export(EXPORT ${PROJECT_NAME}
FILE "${CMAKE_CURRENT_BINARY_DIR}/qpSWIFT-targets.cmake"
NAMESPACE qpSWIFT::
)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/qpSWIFTConfig.cmake "include(\"\${CMAKE_CURRENT_LIST_DIR}/qpSWIFT-targets.cmake\")\n")
# Create CMake packages for the install directory
set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/qpSWIFT)
install(EXPORT ${PROJECT_NAME}
FILE qpSWIFT-targets.cmake
NAMESPACE qpSWIFT::
DESTINATION ${ConfigPackageLocation}
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qpSWIFTConfig.cmake
DESTINATION ${ConfigPackageLocation}
)