Skip to content

Commit 5553208

Browse files
authored
Merge pull request #21 from ethz-adrl/feature/cmake2
cmake files do not need to be configured anymore, passing build flags…
2 parents b0fb67f + 464d8d9 commit 5553208

14 files changed

+55
-75
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ CMakeCache.txt
66
!FindIPOPT.cmake
77
!Findblasfeo.cmake
88
!Findhpipm.cmake
9+
!ct_core/cmake/ct_coreConfig.cmake
10+
!ct_optcon/cmake/ct_optconConfig.cmake
11+
!ct_rbd/cmake/ct_rbdConfig.cmake
12+
!ct_models/cmake/ct_modelsConfig.cmake
913
*.a
1014
*.o
1115
*.so

ct_core/CMakeLists.txt

+4-13
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ endif()
3636
find_package(PythonLibs 2.7 QUIET)
3737
if (PYTHONLIBS_FOUND)
3838
message(STATUS "Python found")
39-
add_definitions(-DPLOTTING_ENABLED)
39+
list(APPEND ct_plot_COMPILE_DEFINITIONS PLOTTING_ENABLED)
4040
message(STATUS "Python library path ... " ${PYTHON_LIBRARY})
4141
list(APPEND ct_core_LIBS ${PYTHON_LIBRARY})
4242
else()
@@ -71,7 +71,6 @@ set(PRESPEC_LIB_NAMES "")
7171

7272
## define list of libraries that contain prespecified templates
7373
if(USE_PRESPEC)
74-
add_definitions(-DUSE_PRESPEC)
7574
# extract the prespec parameters from user-input
7675
ct_configure_explicit_templates("${CMAKE_CURRENT_SOURCE_DIR}/../ct/config/explicit_templates.cfg"
7776
"${CMAKE_CURRENT_SOURCE_DIR}/prespec/"
@@ -89,6 +88,7 @@ endif()
8988
## create ct_core libraries
9089
add_library(ct_plot SHARED src/core/plot/plot.cpp)
9190
target_include_directories(ct_plot PUBLIC ${ct_core_target_include_dirs})
91+
target_compile_definitions(ct_plot PUBLIC ${ct_plot_COMPILE_DEFINITIONS})
9292
target_link_libraries(ct_plot ${ct_core_LIBS})
9393

9494
add_library(ct_core INTERFACE)
@@ -131,24 +131,15 @@ endif()
131131
#################
132132

133133
# for correct libraries locations across platforms
134-
include(GNUInstallDirs)
135-
136-
## get all compile definitions registered so far and create variable
137-
get_directory_property( CompileDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
138-
foreach( d ${CompileDefs} )
139-
set(ct_core_compile_definitions ${ct_core_compile_definitions} -D${d} ) # recursively add compile definitions
140-
endforeach()
141-
142-
## generate files required for installation
143-
configure_file(cmake/ct_coreConfig.cmake.in "${PROJECT_BINARY_DIR}/ct_coreConfig.cmake" @ONLY)
134+
include(GNUInstallDirs)
144135

145136
## copy the header files
146137
install(DIRECTORY include/ct/core DESTINATION include/ct)
147138
install(DIRECTORY include/ct/external DESTINATION include/ct)
148139
install(DIRECTORY examples/include/ct/core DESTINATION include/ct)
149140

150141
## copy the cmake files required for find_package()
151-
install(FILES "${PROJECT_BINARY_DIR}/ct_coreConfig.cmake" DESTINATION "share/ct_core/cmake")
142+
install(FILES "cmake/ct_coreConfig.cmake" DESTINATION "share/ct_core/cmake")
152143

153144
## install library and targets
154145
install(

ct_core/cmake/ct_coreConfig.cmake.in renamed to ct_core/cmake/ct_coreConfig.cmake

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
## cmake-config file for the ct_core package
2-
3-
set(ct_core_COMPILE_DEFINITIONS "@ct_core_compile_definitions@")
42

53
include(${CMAKE_CURRENT_LIST_DIR}/ct_core_export.cmake)
64

ct_core/examples/CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ target_link_libraries(ex_MasspointIntegration ct_core)
1111
list(APPEND core_ex_TARGETS ex_MasspointIntegration)
1212

1313
add_executable(plotTest src/plot/plotTest.cpp)
14-
target_link_libraries(plotTest ct_core
14+
target_link_libraries(plotTest ct_core)
1515
list(APPEND core_ex_TARGETS plotTest)
1616

1717
if(QWT_ENABLED)
@@ -25,5 +25,4 @@ include(GNUInstallDirs)
2525
install(
2626
TARGETS ${core_ex_TARGETS}
2727
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/ct_core
28-
)
29-
28+
)

ct_core/test/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@ add_custom_command(TARGET run_tests
4040
POST_BUILD COMMAND ${PROJECT_SOURCE_DIR}/test/run_tests.py ${CMAKE_CURRENT_BINARY_DIR} ${UNIT_TEST_TARGETS}
4141
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
4242
)
43+
44+
## install tests
45+
include(GNUInstallDirs)
46+
install(
47+
TARGETS ${UNIT_TEST_TARGETS}
48+
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/ct_core
49+
)

ct_models/CMakeLists.txt

+1-13
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
1313
find_package(ct_rbd REQUIRED)
1414
find_package(Boost REQUIRED system filesystem)
1515

16-
## add compiler definitions exported by ct_optcon
17-
add_definitions(${ct_rbd_COMPILE_DEFINITIONS})
18-
1916

2017
## define the directories to be included in all ct_rbd targets
2118
set(ct_models_target_include_dirs
@@ -226,20 +223,11 @@ endif()
226223
# for correct libraries locations across platforms
227224
include(GNUInstallDirs)
228225

229-
## get all compile definitions registered so far and create variable
230-
get_directory_property( CompileDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
231-
foreach( d ${CompileDefs} )
232-
set(ct_models_compile_definitions ${ct_models_compile_definitions} -D${d} ) # recursively add compile definitions
233-
endforeach()
234-
235-
## generate files required for installation
236-
configure_file(cmake/ct_modelsConfig.cmake.in "${PROJECT_BINARY_DIR}/ct_modelsConfig.cmake" @ONLY)
237-
238226
## copy the header files
239227
install(DIRECTORY include/ct/models DESTINATION include/ct)
240228

241229
## copy the cmake files required for find_package()
242-
install(FILES "${PROJECT_BINARY_DIR}/ct_modelsConfig.cmake" DESTINATION "share/ct_models/cmake")
230+
install(FILES "cmake/ct_modelsConfig.cmake" DESTINATION "share/ct_models/cmake")
243231

244232
## install library and targets
245233
install(

ct_models/cmake/ct_modelsConfig.cmake.in renamed to ct_models/cmake/ct_modelsConfig.cmake

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
find_package(ct_rbd REQUIRED)
44

5-
set(ct_models_COMPILE_DEFINITIONS "@ct_models_compile_definitions@")
6-
75
include(${CMAKE_CURRENT_LIST_DIR}/ct_models_export.cmake)
86

97
#define includes in legacy mode

ct_models/test/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@ add_custom_command(TARGET run_tests
2929
COMMENT "Running tests"
3030
POST_BUILD COMMAND ${PROJECT_SOURCE_DIR}/test/run_tests.py ${CMAKE_CURRENT_BINARY_DIR} ${UNIT_TEST_TARGETS}
3131
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
32+
)
33+
34+
## install tests
35+
include(GNUInstallDirs)
36+
install(
37+
TARGETS ${UNIT_TEST_TARGETS}
38+
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/ct_models
3239
)

ct_optcon/CMakeLists.txt

+14-24
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
1717
## find and include required dependencies
1818
find_package(ct_core REQUIRED)
1919

20-
## add compiler definitions exported by ct_core
21-
add_definitions(${ct_core_COMPILE_DEFINITIONS})
22-
2320

2421
## find and include optional dependencies
2522
option(MATLAB "Compile with matlab support" OFF)
@@ -29,19 +26,19 @@ option(DEBUG_PRINT "Print debug messages" OFF)
2926

3027
if(DEBUG_PRINT)
3128
message(STATUS "Debug Print ON")
32-
add_definitions (-DDEBUG_PRINT)
29+
list(APPEND ct_optcon_COMPILE_DEFINITIONS DEBUG_PRINT)
3330
endif(DEBUG_PRINT)
3431

3532
if(MATLAB_FULL_LOG)
3633
message(WARNING "Compiling with full log to matlab. Execution will be very slow.")
3734
set(MATLAB ON)
38-
add_definitions (-DMATLAB_FULL_LOG)
35+
list(APPEND ct_optcon_COMPILE_DEFINITIONS MATLAB_FULL_LOG)
3936
endif(MATLAB_FULL_LOG)
4037

4138
if(MATLAB)
4239
message(STATUS "MATLAB support ON")
4340
find_package(matlab_cpp_interface REQUIRED)
44-
add_definitions( -DMATLAB )
41+
list(APPEND ct_optcon_COMPILE_DEFINITIONS MATLAB)
4542
endif(MATLAB)
4643

4744

@@ -50,8 +47,8 @@ find_package(LAPACK QUIET)
5047
set(LAPACK_LIBS "")
5148
if(LAPACK_FOUND)
5249
message(STATUS "Found LAPACK library")
53-
add_definitions (-DCT_USE_LAPACK)
5450
list(APPEND LAPACK_LIBS lapack)
51+
list(APPEND ct_optcon_COMPILE_DEFINITIONS CT_USE_LAPACK)
5552
else(LAPACK_FOUND)
5653
message(STATUS "Could not find LAPACK library")
5754
endif(LAPACK_FOUND)
@@ -63,19 +60,19 @@ find_package(hpipm QUIET)
6360
if(blasfeo_FOUND AND hpipm_FOUND)
6461
message(STATUS "Found HPIPM and BLASFEO")
6562
set(HPIPM ON)
66-
add_definitions(-DHPIPM)
6763
list(APPEND HPIPM_LIBS ${hpipm_LIBRARIES} ${blasfeo_LIBRARIES})
64+
list(APPEND ct_optcon_COMPILE_DEFINITIONS HPIPM)
6865
endif()
6966

7067

7168
## include IPOPT (after installation via sudo apt-get install coinor-libipopt-dev)
7269
find_package(IPOPT QUIET)
7370
if(IPOPT_FOUND)
7471
set(BUILD_WITH_IPOPT_SUPPORT ON)
75-
add_definitions(-DBUILD_WITH_IPOPT_SUPPORT)
76-
add_definitions(${IPOPT_DEFINITIONS})
7772
message(STATUS "Found IPOPT - building with IPOPT support")
7873
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})
7976
endif()
8077

8178

@@ -86,7 +83,7 @@ endif()
8683
# message(STATUS "Found SNOPT - building with SNOPT support")
8784
# include_directories( "$ENV{SNOPT_SOURCE_DIR}/include")
8885
#
89-
# add_definitions( -DBUILD_WITH_SNOPT_SUPPORT )
86+
# list(APPEND ct_optcon_COMPILE_DEFINITIONS BUILD_WITH_SNOPT_SUPPORT)
9087
# find_library(SNOPT_LIBRARY1 snopt7_cpp $ENV{SNOPT_SOURCE_DIR}/lib REQUIRED)
9188
# find_library(SNOPT_LIBRARY2 snopt7 $ENV{SNOPT_SOURCE_DIR}/lib REQUIRED)
9289
# set(SNOPT_LIBS ${SNOPT_LIBRARY1} ${SNOPT_LIBRARY2})
@@ -105,7 +102,7 @@ endif()
105102
###################
106103

107104
## 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
109106
${ct_core_INCLUDE_DIRS}
110107
${matlab_cpp_interface_INCLUDE_DIRS}
111108
${blasfeo_INCLUDE_DIRS}
@@ -127,7 +124,8 @@ if(USE_PRESPEC)
127124
# create libraries
128125
foreach(lib_name ${PRESPEC_LIB_NAMES})
129126
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})
131129
target_link_libraries(${lib_name}
132130
ct_core
133131
${matlab_cpp_interface_LIBRARIES}
@@ -141,7 +139,8 @@ endif(USE_PRESPEC)
141139

142140
## create ct_optcon library
143141
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})
145144
target_link_libraries(ct_optcon INTERFACE
146145
ct_core
147146
${matlab_cpp_interface_LIBRARIES}
@@ -181,20 +180,11 @@ include(GNUInstallDirs)
181180

182181
install(DIRECTORY include/ct/optcon DESTINATION include/ct)
183182

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-
193183
## copy the header files
194184
install(DIRECTORY include/ct/optcon DESTINATION include/ct)
195185

196186
## 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")
198188

199189
## install library and targets
200190
install(

ct_optcon/cmake/ct_optconConfig.cmake.in renamed to ct_optcon/cmake/ct_optconConfig.cmake

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
# cmake-onfig file for the ct_optcon package
1+
# cmake-config file for the ct_optcon package
22

33
find_package(ct_core REQUIRED)
44

5-
set(ct_optcon_COMPILE_DEFINITIONS "@ct_optcon_compile_definitions@")
6-
75
include(${CMAKE_CURRENT_LIST_DIR}/ct_optcon_export.cmake)
86

97
#define includes in legacy mode

ct_optcon/test/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,11 @@ add_custom_command(TARGET run_tests
8181
COMMENT "Running tests"
8282
POST_BUILD COMMAND ${PROJECT_SOURCE_DIR}/test/run_tests.py ${CMAKE_CURRENT_BINARY_DIR} ${UNIT_TEST_TARGETS}
8383
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
84+
)
85+
86+
## install tests
87+
include(GNUInstallDirs)
88+
install(
89+
TARGETS ${UNIT_TEST_TARGETS}
90+
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/ct_optcon
8491
)

ct_rbd/CMakeLists.txt

+1-13
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ SET(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
1414
find_package(kindr REQUIRED)
1515
find_package(ct_optcon REQUIRED)
1616

17-
## add compiler definitions exported by ct_optcon
18-
add_definitions(${ct_optcon_COMPILE_DEFINITIONS})
19-
2017

2118
###################
2219
# BUILD LIBRARIES #
@@ -61,21 +58,12 @@ endif()
6158
# for correct libraries locations across platforms
6259
include(GNUInstallDirs)
6360

64-
## get all compile definitions registered so far and create variable
65-
get_directory_property( CompileDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
66-
foreach( d ${CompileDefs} )
67-
set(ct_rbd_compile_definitions ${ct_rbd_compile_definitions} -D${d} ) # recursively add compile definitions
68-
endforeach()
69-
70-
## generate files required for installation
71-
configure_file(cmake/ct_rbdConfig.cmake.in "${PROJECT_BINARY_DIR}/ct_rbdConfig.cmake" @ONLY)
72-
7361
## copy the header files
7462
install(DIRECTORY include/ct/rbd DESTINATION include/ct)
7563
install(DIRECTORY include/ct/iit DESTINATION include/ct)
7664

7765
## copy the cmake files required for find_package()
78-
install(FILES "${PROJECT_BINARY_DIR}/ct_rbdConfig.cmake" DESTINATION "share/ct_rbd/cmake")
66+
install(FILES "cmake/ct_rbdConfig.cmake" DESTINATION "share/ct_rbd/cmake")
7967

8068
## install library and targets
8169
install(

ct_rbd/cmake/ct_rbdConfig.cmake.in renamed to ct_rbd/cmake/ct_rbdConfig.cmake

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
find_package(ct_optcon REQUIRED)
44

5-
set(ct_rbd_COMPILE_DEFINITIONS "@ct_rbd_compile_definitions@")
6-
75
include(${CMAKE_CURRENT_LIST_DIR}/ct_rbd_export.cmake)
86

97
#define includes in legacy mode

ct_rbd/test/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,11 @@ add_custom_command(TARGET run_tests
6363
COMMENT "Running tests"
6464
POST_BUILD COMMAND ${PROJECT_SOURCE_DIR}/test/run_tests.py ${CMAKE_CURRENT_BINARY_DIR} ${UNIT_TEST_TARGETS}
6565
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
66+
)
67+
68+
## install tests
69+
include(GNUInstallDirs)
70+
install(
71+
TARGETS ${UNIT_TEST_TARGETS}
72+
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/ct_rbd
6673
)

0 commit comments

Comments
 (0)