-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
170 lines (143 loc) · 5.98 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
project(gsplines VERSION "0.0.1")
include(CTest)
find_program(CTEST_MEMORYCHECK_COMMAND valgrind)
# -mfpmath avx2
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -funroll-loops -mfpmath=sse ")
set(CMAKE_CXX_FLAGS_DEBUG "-g3 -pthread ")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_INSTALL_PREFIX /usr)
set(PYBIND11_FINDPYTHON
OFF
CACHE BOOL "")
set(PYBIND11_PYTHON_VERSION
3.8
CACHE STRING "")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(ifopt REQUIRED)
find_package(Eigen3 REQUIRED)
add_library(
gsplines SHARED
${PROJECT_SOURCE_DIR}/src/Basis/BasisLegendre.cpp
${PROJECT_SOURCE_DIR}/src/Basis/BasisLagrange.cpp
${PROJECT_SOURCE_DIR}/src/Basis/Basis0101.cpp
${PROJECT_SOURCE_DIR}/src/Basis/Basis.cpp
${PROJECT_SOURCE_DIR}/src/Interpolator.cpp
${PROJECT_SOURCE_DIR}/src/GSpline.cpp
${PROJECT_SOURCE_DIR}/src/Tools.cpp
${PROJECT_SOURCE_DIR}/src/FunctionalAnalysis/Sobolev.cpp
${PROJECT_SOURCE_DIR}/src/FunctionalAnalysis/Integral.cpp
${PROJECT_SOURCE_DIR}/src/Optimization/ipopt_interface.cpp
${PROJECT_SOURCE_DIR}/src/Optimization/ipopt_solver.cpp
${PROJECT_SOURCE_DIR}/src/Functions/FunctionSum.cpp
${PROJECT_SOURCE_DIR}/src/Functions/FunctionMul.cpp
${PROJECT_SOURCE_DIR}/src/Functions/FunctionsComp.cpp
${PROJECT_SOURCE_DIR}/src/Functions/FunctionsConcat.cpp
${PROJECT_SOURCE_DIR}/src/Functions/Functions.cpp
${PROJECT_SOURCE_DIR}/src/Functions/FunctionExpression.cpp
${PROJECT_SOURCE_DIR}/src/Functions/FunctionGenericOperations.cpp
${PROJECT_SOURCE_DIR}/src/Functions/FunctionBase.cpp
${PROJECT_SOURCE_DIR}/src/Functions/ElementalFunctions.cpp
${PROJECT_SOURCE_DIR}/src/Collocation/GaussLobattoPointsWeights.cpp
${PROJECT_SOURCE_DIR}/src/Collocation/GaussLobattoLagrange.cpp
${PROJECT_SOURCE_DIR}/src/Collocation/GaussLobattoLagrangeFunctionals.cpp
# --
)
target_link_libraries(gsplines PUBLIC ${ifopt_LIBRARIES})
target_include_directories(
gsplines
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include> ${EIGEN3_INCLUDE_DIRS}
${ifopt_INCLUDE_DIRS})
set_target_properties(
gsplines
PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON
VERSION ${gsplines_VERSION}
SOVERSION ${gsplines_VERSION_MAJOR}.${gsplines_VERSION_MINOR}
EXPORT_NAME GSplines)
link_directories(${PROJECT_SOURCE_DIR}/build)
if(NOT TARGET pybind11)
add_subdirectory(${PROJECT_SOURCE_DIR}/modules/pybind11)
endif()
pybind11_add_module(pygsplines ${PROJECT_SOURCE_DIR}/bindings/bindings.cpp)
target_include_directories(
pygsplines PUBLIC ${EIGEN3_INCLUDE_DIRS}
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/modules/pybind11>)
target_link_libraries(pygsplines PUBLIC ${EIGEN3_LIBRARIES} ${ifopt_LIBRARIES}
gsplines)
# Generate the environment setup script
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/setup_python_env.sh
COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_SOURCE_DIR}/setup_python_env.sh
COMMENT "Removing old setup_python_env.sh")
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/setup_python_env.py
COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_SOURCE_DIR}/setup_python_env.py
COMMENT "Removing old setup_python_env.py")
set(PYTHON_PACKAGE_DIR "${CMAKE_SOURCE_DIR}/python")
configure_file(${CMAKE_SOURCE_DIR}/setup_python_env.in
${CMAKE_SOURCE_DIR}/setup_python_env.sh @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/setup_python_env.in.py
${CMAKE_SOURCE_DIR}/setup_python_env.py @ONLY)
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}
AND ${BUILD_TESTING})
enable_testing()
add_subdirectory(tests)
endif()
if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json")
execute_process(
COMMAND
${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json
${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json)
endif()
include(GNUInstallDirs)
set(INSTALL_CMAKE_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/GSplines)
install(
TARGETS gsplines
EXPORT GSplinesTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
"import site; print(site.getsitepackages()[0])"
OUTPUT_VARIABLE PYTHON_INSTALL_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE)
install(DIRECTORY python/ DESTINATION ${PYTHON_INSTALL_PATH})
install(TARGETS pygsplines DESTINATION ${PYTHON_INSTALL_PATH}/gsplines)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
export(EXPORT GSplinesTargets
FILE ${CMAKE_CURRENT_BINARY_DIR}/GSplinesTargets.cmake)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/GSplinesConfigVersion.cmake
COMPATIBILITY SameMajorVersion)
configure_package_config_file(
cmake/GSplinesConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/GSplinesConfig.cmake
INSTALL_DESTINATION ${INSTALL_CMAKE_CONFIG_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/GSplinesConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/GSplinesConfigVersion.cmake
DESTINATION ${INSTALL_CMAKE_CONFIG_DIR})
install(EXPORT GSplinesTargets DESTINATION ${INSTALL_CMAKE_CONFIG_DIR})
# Packaging
set(CPACK_PACKAGE_VENDOR "Rafael A. Rojas")
set(CPACK_GENERATOR "DEB")
set(CPACK_PACKAGE_VERSION ${gsplines_VERSION})
set(CPACK_SYSTEM_NAME ${CMAKE_HOST_SYSTEM_PROCESSOR})
# Debian
find_program(DPKG_PROG dpkg DOC "'dpkg' executable")
if(DPKG_PROG)
execute_process(
COMMAND ${DPKG_PROG} --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
# Change system name to use the correct architecture in file name
set(CPACK_SYSTEM_NAME ${CPACK_DEBIAN_PACKAGE_ARCHITECTURE})
endif()
# Debian versions require a dash
set(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}-1)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Rafael A. Rojas")
set(CPACK_DEBIAN_PACKAGE_DEPENDS
"coinor-libipopt-dev, ros-noetic-ifopt, libeigen3-dev")
include(CPack)