-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
142 lines (115 loc) · 4.82 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
#
# Copyright (c) 2021-2023 INRIA
#
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
SET(PROJECT_NAME pycppad)
SET(PROJECT_DESCRIPTION "Python bindings for CppAD and CppADCodeGen using Boost.Python")
SET(PROJECT_URL "https://github.com/simple-robotics/pycppad")
SET(PROJECT_CUSTOM_HEADER_EXTENSION "hpp")
SET(PROJECT_USE_CMAKE_EXPORT TRUE)
# Project configuration
SET(PROJECT_USE_CMAKE_EXPORT TRUE)
SET(CMAKE_VERBOSE_MAKEFILE TRUE)
SET(CXX_DISABLE_WERROR TRUE)
# Check if the submodule cmake have been initialized
IF(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake/base.cmake")
MESSAGE(FATAL_ERROR "\nPlease run the following command first:\ngit submodule update --init\n")
ENDIF()
INCLUDE(cmake/base.cmake)
INCLUDE(cmake/boost.cmake)
INCLUDE(cmake/ide.cmake)
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/find-external/CppAD/" ${CMAKE_MODULE_PATH})
# Project definition
COMPUTE_PROJECT_ARGS(PROJECT_ARGS LANGUAGES CXX)
PROJECT(${PROJECT_NAME} ${PROJECT_ARGS})
CHECK_MINIMAL_CXX_STANDARD(11 ENFORCE)
# Project options
OPTION(SUFFIX_SO_VERSION "Suffix library name with its version" ON)
OPTION(BUILD_WITH_CPPAD_CODEGEN_BINDINGS "Build the python bindings for code generation (via CppADCodeGen)" OFF)
SET_BOOST_DEFAULT_OPTIONS()
ADD_PROJECT_DEPENDENCY(Boost REQUIRED)
EXPORT_BOOST_DEFAULT_OPTIONS()
IF(BUILD_WITH_CPPAD_CODEGEN_BINDINGS)
ADD_PROJECT_DEPENDENCY(cppadcg 2.4.1 REQUIRED PKG_CONFIG_REQUIRES "cppadcg >= 2.4.1") # CppADCodeGen 2.4.1 is the first version to check the minimal version of CppAD
ADD_DEFINITIONS(-DPYCPPAD_WITH_CPPAD_CODEGEN_BINDINGS)
ENDIF(BUILD_WITH_CPPAD_CODEGEN_BINDINGS)
ADD_PROJECT_DEPENDENCY(cppad 20180000.0 REQUIRED PKG_CONFIG_REQUIRES "cppad >= 20180000.0")
ADD_PROJECT_DEPENDENCY(Eigen3 REQUIRED PKG_CONFIG_REQUIRES "eigen3 >= 3.0.5")
ADD_PROJECT_DEPENDENCY(eigenpy 2.7.14 REQUIRED)
SET(${PROJECT_NAME}_HEADERS
include/${PROJECT_NAME}/fwd.hpp
include/${PROJECT_NAME}/ad.hpp
include/${PROJECT_NAME}/independent.hpp
include/${PROJECT_NAME}/ad_fun.hpp
include/${PROJECT_NAME}/cast.hpp
include/${PROJECT_NAME}/cppad.hpp
include/${PROJECT_NAME}/cppad-scalar.hpp
include/${PROJECT_NAME}/utils/scope.hpp
# Generated headers
${${PROJECT_NAME}_BINARY_DIR}/include/${PROJECT_NAME}/config.hpp
${${PROJECT_NAME}_BINARY_DIR}/include/${PROJECT_NAME}/deprecated.hpp
${${PROJECT_NAME}_BINARY_DIR}/include/${PROJECT_NAME}/warning.hpp
)
SET(${PROJECT_NAME}_SOURCES
src/cppad.cpp
src/expose-type-double.cpp
src/expose-type-double-row-major.cpp
)
IF(BUILD_WITH_CPPAD_CODEGEN_BINDINGS)
LIST(APPEND ${PROJECT_NAME}_HEADERS
include/${PROJECT_NAME}/codegen/cg.hpp
include/${PROJECT_NAME}/codegen/cppadcg-scalar.hpp
include/${PROJECT_NAME}/codegen/code-handler.hpp
include/${PROJECT_NAME}/codegen/lang/c/language-c.hpp
include/${PROJECT_NAME}/codegen/lang/c/lang-c-default-var-name-gen.hpp
)
ENDIF(BUILD_WITH_CPPAD_CODEGEN_BINDINGS)
ADD_LIBRARY(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SOURCES} ${${PROJECT_NAME}_HEADERS})
IF(SUFFIX_SO_VERSION)
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION})
ENDIF(SUFFIX_SO_VERSION)
TARGET_LINK_BOOST_PYTHON(${PROJECT_NAME} PUBLIC)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC ${cppad_LIBRARY} eigenpy::eigenpy)
IF(BUILD_WITH_CPPAD_CODEGEN_BINDINGS)
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME}
SYSTEM PUBLIC
${cppadcg_INCLUDE_DIR}
)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC ${CMAKE_DL_LIBS})
ENDIF(BUILD_WITH_CPPAD_CODEGEN_BINDINGS)
IF(MSVC)
TARGET_COMPILE_OPTIONS(${PROJECT_NAME} PUBLIC "/bigobj")
ENDIF()
# Do not report:
# -Wconversion as the BOOST_PYTHON_FUNCTION_OVERLOADS implicitly converts.
# -Wcomment as latex equations have multi-line comments.
IF(NOT WIN32)
TARGET_COMPILE_OPTIONS(${PROJECT_NAME} PRIVATE -Wno-conversion -Wno-comment)
ENDIF(NOT WIN32)
IF(WIN32)
TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} PRIVATE -DNOMINMAX)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC ${PYTHON_LIBRARY})
ENDIF(WIN32)
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME}
SYSTEM PUBLIC
${Boost_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
${PYTHON_INCLUDE_DIRS}
$<INSTALL_INTERFACE:include>)
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC $<INSTALL_INTERFACE:include>)
INSTALL(TARGETS ${PROJECT_NAME}
EXPORT ${TARGETS_EXPORT_NAME}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
ADD_HEADER_GROUP(${PROJECT_NAME}_HEADERS)
ADD_SOURCE_GROUP(${PROJECT_NAME}_SOURCES)
ADD_SUBDIRECTORY(python)
ADD_SUBDIRECTORY(example)
PKG_CONFIG_APPEND_LIBS(${PROJECT_NAME})
PKG_CONFIG_APPEND_CFLAGS("-I${PYTHON_INCLUDE_DIRS}")
PKG_CONFIG_APPEND_BOOST_LIBS(${BOOST_COMPONENTS})
# Install catkin package.xml
INSTALL(FILES package.xml DESTINATION share/${PROJECT_NAME})