@@ -17,9 +17,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
17
17
## find and include required dependencies
18
18
find_package (ct_core REQUIRED)
19
19
20
- ## add compiler definitions exported by ct_core
21
- add_definitions (${ct_core_COMPILE_DEFINITIONS} )
22
-
23
20
24
21
## find and include optional dependencies
25
22
option (MATLAB "Compile with matlab support" OFF )
@@ -29,19 +26,19 @@ option(DEBUG_PRINT "Print debug messages" OFF)
29
26
30
27
if (DEBUG_PRINT)
31
28
message (STATUS "Debug Print ON" )
32
- add_definitions (-DDEBUG_PRINT )
29
+ list ( APPEND ct_optcon_COMPILE_DEFINITIONS DEBUG_PRINT )
33
30
endif (DEBUG_PRINT)
34
31
35
32
if (MATLAB_FULL_LOG)
36
33
message (WARNING "Compiling with full log to matlab. Execution will be very slow." )
37
34
set (MATLAB ON )
38
- add_definitions (-DMATLAB_FULL_LOG )
35
+ list ( APPEND ct_optcon_COMPILE_DEFINITIONS MATLAB_FULL_LOG )
39
36
endif (MATLAB_FULL_LOG)
40
37
41
38
if (MATLAB)
42
39
message (STATUS "MATLAB support ON" )
43
40
find_package (matlab_cpp_interface REQUIRED)
44
- add_definitions ( -DMATLAB )
41
+ list ( APPEND ct_optcon_COMPILE_DEFINITIONS MATLAB )
45
42
endif (MATLAB)
46
43
47
44
@@ -50,8 +47,8 @@ find_package(LAPACK QUIET)
50
47
set (LAPACK_LIBS "" )
51
48
if (LAPACK_FOUND)
52
49
message (STATUS "Found LAPACK library" )
53
- add_definitions (-DCT_USE_LAPACK)
54
50
list (APPEND LAPACK_LIBS lapack)
51
+ list (APPEND ct_optcon_COMPILE_DEFINITIONS CT_USE_LAPACK)
55
52
else (LAPACK_FOUND)
56
53
message (STATUS "Could not find LAPACK library" )
57
54
endif (LAPACK_FOUND)
@@ -63,19 +60,19 @@ find_package(hpipm QUIET)
63
60
if (blasfeo_FOUND AND hpipm_FOUND)
64
61
message (STATUS "Found HPIPM and BLASFEO" )
65
62
set (HPIPM ON )
66
- add_definitions (-DHPIPM)
67
63
list (APPEND HPIPM_LIBS ${hpipm_LIBRARIES} ${blasfeo_LIBRARIES} )
64
+ list (APPEND ct_optcon_COMPILE_DEFINITIONS HPIPM)
68
65
endif ()
69
66
70
67
71
68
## include IPOPT (after installation via sudo apt-get install coinor-libipopt-dev)
72
69
find_package (IPOPT QUIET )
73
70
if (IPOPT_FOUND)
74
71
set (BUILD_WITH_IPOPT_SUPPORT ON )
75
- add_definitions (-DBUILD_WITH_IPOPT_SUPPORT)
76
- add_definitions (${IPOPT_DEFINITIONS} )
77
72
message (STATUS "Found IPOPT - building with IPOPT support" )
78
73
set (IPOPT_LIBS ipopt) # dl mumps coinhsl lapack blas gfortran m quadmath coinmetis)
74
+ list (APPEND ct_optcon_COMPILE_DEFINITIONS BUILD_WITH_IPOPT_SUPPORT)
75
+ list (APPEND ct_optcon_COMPILE_DEFINITIONS ${IPOPT_DEFINITIONS} )
79
76
endif ()
80
77
81
78
@@ -86,7 +83,7 @@ endif()
86
83
# message(STATUS "Found SNOPT - building with SNOPT support")
87
84
# include_directories( "$ENV{SNOPT_SOURCE_DIR}/include")
88
85
#
89
- # add_definitions( -DBUILD_WITH_SNOPT_SUPPORT )
86
+ # list(APPEND ct_optcon_COMPILE_DEFINITIONS BUILD_WITH_SNOPT_SUPPORT )
90
87
# find_library(SNOPT_LIBRARY1 snopt7_cpp $ENV{SNOPT_SOURCE_DIR}/lib REQUIRED)
91
88
# find_library(SNOPT_LIBRARY2 snopt7 $ENV{SNOPT_SOURCE_DIR}/lib REQUIRED)
92
89
# set(SNOPT_LIBS ${SNOPT_LIBRARY1} ${SNOPT_LIBRARY2})
@@ -105,7 +102,7 @@ endif()
105
102
###################
106
103
107
104
## define the directories to be included in all ct_optcon targets
108
- set (ct_optcon_target_include_dirs
105
+ set (ct_optcon_TARGET_INCLUDE_DIRS
109
106
${ct_core_INCLUDE_DIRS}
110
107
${matlab_cpp_interface_INCLUDE_DIRS}
111
108
${blasfeo_INCLUDE_DIRS}
@@ -127,7 +124,8 @@ if(USE_PRESPEC)
127
124
# create libraries
128
125
foreach (lib_name ${PRESPEC_LIB_NAMES} )
129
126
add_library (${lib_name} SHARED ${${lib_name} _SRCS})
130
- target_include_directories (${lib_name} PUBLIC ${ct_optcon_target_include_dirs} )
127
+ target_include_directories (${lib_name} PUBLIC ${ct_optcon_TARGET_INCLUDE_DIRS} )
128
+ target_compile_definitions (${lib_name} PUBLIC ${ct_optcon_COMPILE_DEFINITIONS} )
131
129
target_link_libraries (${lib_name}
132
130
ct_core
133
131
${matlab_cpp_interface_LIBRARIES}
@@ -141,7 +139,8 @@ endif(USE_PRESPEC)
141
139
142
140
## create ct_optcon library
143
141
add_library (ct_optcon INTERFACE )
144
- target_include_directories (ct_optcon INTERFACE ${ct_optcon_target_include_dirs} )
142
+ target_include_directories (ct_optcon INTERFACE ${ct_optcon_TARGET_INCLUDE_DIRS} )
143
+ target_compile_definitions (ct_optcon INTERFACE ${ct_optcon_COMPILE_DEFINITIONS} )
145
144
target_link_libraries (ct_optcon INTERFACE
146
145
ct_core
147
146
${matlab_cpp_interface_LIBRARIES}
@@ -181,20 +180,11 @@ include(GNUInstallDirs)
181
180
182
181
install (DIRECTORY include /ct/optcon DESTINATION include /ct)
183
182
184
- ## get all compile definitions registered so far and create variable
185
- get_directory_property ( CompileDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
186
- foreach ( d ${CompileDefs} )
187
- set (ct_optcon_compile_definitions ${ct_optcon_compile_definitions} -D${d} ) # recursively add compile definitions
188
- endforeach ()
189
-
190
- ## generate files required for installation
191
- configure_file (cmake/ct_optconConfig.cmake.in "${PROJECT_BINARY_DIR} /ct_optconConfig.cmake" @ONLY)
192
-
193
183
## copy the header files
194
184
install (DIRECTORY include /ct/optcon DESTINATION include /ct)
195
185
196
186
## copy the cmake files required for find_package()
197
- install (FILES "${PROJECT_BINARY_DIR} /ct_optconConfig.cmake" DESTINATION "share/ct_optcon/cmake" )
187
+ install (FILES "cmake /ct_optconConfig.cmake" DESTINATION "share/ct_optcon/cmake" )
198
188
199
189
## install library and targets
200
190
install (
0 commit comments