Skip to content

Commit

Permalink
Merge pull request #21 from ethz-adrl/feature/cmake2
Browse files Browse the repository at this point in the history
cmake files do not need to be configured anymore, passing build flags…
  • Loading branch information
markusgft authored May 16, 2019
2 parents b0fb67f + 464d8d9 commit 5553208
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 75 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ CMakeCache.txt
!FindIPOPT.cmake
!Findblasfeo.cmake
!Findhpipm.cmake
!ct_core/cmake/ct_coreConfig.cmake
!ct_optcon/cmake/ct_optconConfig.cmake
!ct_rbd/cmake/ct_rbdConfig.cmake
!ct_models/cmake/ct_modelsConfig.cmake
*.a
*.o
*.so
Expand Down
17 changes: 4 additions & 13 deletions ct_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ endif()
find_package(PythonLibs 2.7 QUIET)
if (PYTHONLIBS_FOUND)
message(STATUS "Python found")
add_definitions(-DPLOTTING_ENABLED)
list(APPEND ct_plot_COMPILE_DEFINITIONS PLOTTING_ENABLED)
message(STATUS "Python library path ... " ${PYTHON_LIBRARY})
list(APPEND ct_core_LIBS ${PYTHON_LIBRARY})
else()
Expand Down Expand Up @@ -71,7 +71,6 @@ set(PRESPEC_LIB_NAMES "")

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

add_library(ct_core INTERFACE)
Expand Down Expand Up @@ -131,24 +131,15 @@ endif()
#################

# for correct libraries locations across platforms
include(GNUInstallDirs)

## get all compile definitions registered so far and create variable
get_directory_property( CompileDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
foreach( d ${CompileDefs} )
set(ct_core_compile_definitions ${ct_core_compile_definitions} -D${d} ) # recursively add compile definitions
endforeach()

## generate files required for installation
configure_file(cmake/ct_coreConfig.cmake.in "${PROJECT_BINARY_DIR}/ct_coreConfig.cmake" @ONLY)
include(GNUInstallDirs)

## copy the header files
install(DIRECTORY include/ct/core DESTINATION include/ct)
install(DIRECTORY include/ct/external DESTINATION include/ct)
install(DIRECTORY examples/include/ct/core DESTINATION include/ct)

## copy the cmake files required for find_package()
install(FILES "${PROJECT_BINARY_DIR}/ct_coreConfig.cmake" DESTINATION "share/ct_core/cmake")
install(FILES "cmake/ct_coreConfig.cmake" DESTINATION "share/ct_core/cmake")

## install library and targets
install(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
## cmake-config file for the ct_core package

set(ct_core_COMPILE_DEFINITIONS "@ct_core_compile_definitions@")

include(${CMAKE_CURRENT_LIST_DIR}/ct_core_export.cmake)

Expand Down
5 changes: 2 additions & 3 deletions ct_core/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ target_link_libraries(ex_MasspointIntegration ct_core)
list(APPEND core_ex_TARGETS ex_MasspointIntegration)

add_executable(plotTest src/plot/plotTest.cpp)
target_link_libraries(plotTest ct_core
target_link_libraries(plotTest ct_core)
list(APPEND core_ex_TARGETS plotTest)

if(QWT_ENABLED)
Expand All @@ -25,5 +25,4 @@ include(GNUInstallDirs)
install(
TARGETS ${core_ex_TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/ct_core
)

)
7 changes: 7 additions & 0 deletions ct_core/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ add_custom_command(TARGET run_tests
POST_BUILD COMMAND ${PROJECT_SOURCE_DIR}/test/run_tests.py ${CMAKE_CURRENT_BINARY_DIR} ${UNIT_TEST_TARGETS}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)

## install tests
include(GNUInstallDirs)
install(
TARGETS ${UNIT_TEST_TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/ct_core
)
14 changes: 1 addition & 13 deletions ct_models/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
find_package(ct_rbd REQUIRED)
find_package(Boost REQUIRED system filesystem)

## add compiler definitions exported by ct_optcon
add_definitions(${ct_rbd_COMPILE_DEFINITIONS})


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

## get all compile definitions registered so far and create variable
get_directory_property( CompileDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
foreach( d ${CompileDefs} )
set(ct_models_compile_definitions ${ct_models_compile_definitions} -D${d} ) # recursively add compile definitions
endforeach()

## generate files required for installation
configure_file(cmake/ct_modelsConfig.cmake.in "${PROJECT_BINARY_DIR}/ct_modelsConfig.cmake" @ONLY)

## copy the header files
install(DIRECTORY include/ct/models DESTINATION include/ct)

## copy the cmake files required for find_package()
install(FILES "${PROJECT_BINARY_DIR}/ct_modelsConfig.cmake" DESTINATION "share/ct_models/cmake")
install(FILES "cmake/ct_modelsConfig.cmake" DESTINATION "share/ct_models/cmake")

## install library and targets
install(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

find_package(ct_rbd REQUIRED)

set(ct_models_COMPILE_DEFINITIONS "@ct_models_compile_definitions@")

include(${CMAKE_CURRENT_LIST_DIR}/ct_models_export.cmake)

#define includes in legacy mode
Expand Down
7 changes: 7 additions & 0 deletions ct_models/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@ add_custom_command(TARGET run_tests
COMMENT "Running tests"
POST_BUILD COMMAND ${PROJECT_SOURCE_DIR}/test/run_tests.py ${CMAKE_CURRENT_BINARY_DIR} ${UNIT_TEST_TARGETS}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)

## install tests
include(GNUInstallDirs)
install(
TARGETS ${UNIT_TEST_TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/ct_models
)
38 changes: 14 additions & 24 deletions ct_optcon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
## find and include required dependencies
find_package(ct_core REQUIRED)

## add compiler definitions exported by ct_core
add_definitions(${ct_core_COMPILE_DEFINITIONS})


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

if(DEBUG_PRINT)
message(STATUS "Debug Print ON")
add_definitions (-DDEBUG_PRINT)
list(APPEND ct_optcon_COMPILE_DEFINITIONS DEBUG_PRINT)
endif(DEBUG_PRINT)

if(MATLAB_FULL_LOG)
message(WARNING "Compiling with full log to matlab. Execution will be very slow.")
set(MATLAB ON)
add_definitions (-DMATLAB_FULL_LOG)
list(APPEND ct_optcon_COMPILE_DEFINITIONS MATLAB_FULL_LOG)
endif(MATLAB_FULL_LOG)

if(MATLAB)
message(STATUS "MATLAB support ON")
find_package(matlab_cpp_interface REQUIRED)
add_definitions( -DMATLAB )
list(APPEND ct_optcon_COMPILE_DEFINITIONS MATLAB)
endif(MATLAB)


Expand All @@ -50,8 +47,8 @@ find_package(LAPACK QUIET)
set(LAPACK_LIBS "")
if(LAPACK_FOUND)
message(STATUS "Found LAPACK library")
add_definitions (-DCT_USE_LAPACK)
list(APPEND LAPACK_LIBS lapack)
list(APPEND ct_optcon_COMPILE_DEFINITIONS CT_USE_LAPACK)
else(LAPACK_FOUND)
message(STATUS "Could not find LAPACK library")
endif(LAPACK_FOUND)
Expand All @@ -63,19 +60,19 @@ find_package(hpipm QUIET)
if(blasfeo_FOUND AND hpipm_FOUND)
message(STATUS "Found HPIPM and BLASFEO")
set(HPIPM ON)
add_definitions(-DHPIPM)
list(APPEND HPIPM_LIBS ${hpipm_LIBRARIES} ${blasfeo_LIBRARIES})
list(APPEND ct_optcon_COMPILE_DEFINITIONS HPIPM)
endif()


## include IPOPT (after installation via sudo apt-get install coinor-libipopt-dev)
find_package(IPOPT QUIET)
if(IPOPT_FOUND)
set(BUILD_WITH_IPOPT_SUPPORT ON)
add_definitions(-DBUILD_WITH_IPOPT_SUPPORT)
add_definitions(${IPOPT_DEFINITIONS})
message(STATUS "Found IPOPT - building with IPOPT support")
set(IPOPT_LIBS ipopt) # dl mumps coinhsl lapack blas gfortran m quadmath coinmetis)
list(APPEND ct_optcon_COMPILE_DEFINITIONS BUILD_WITH_IPOPT_SUPPORT)
list(APPEND ct_optcon_COMPILE_DEFINITIONS ${IPOPT_DEFINITIONS})
endif()


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

## define the directories to be included in all ct_optcon targets
set(ct_optcon_target_include_dirs
set(ct_optcon_TARGET_INCLUDE_DIRS
${ct_core_INCLUDE_DIRS}
${matlab_cpp_interface_INCLUDE_DIRS}
${blasfeo_INCLUDE_DIRS}
Expand All @@ -127,7 +124,8 @@ if(USE_PRESPEC)
# create libraries
foreach(lib_name ${PRESPEC_LIB_NAMES})
add_library(${lib_name} SHARED ${${lib_name}_SRCS})
target_include_directories(${lib_name} PUBLIC ${ct_optcon_target_include_dirs})
target_include_directories(${lib_name} PUBLIC ${ct_optcon_TARGET_INCLUDE_DIRS})
target_compile_definitions(${lib_name} PUBLIC ${ct_optcon_COMPILE_DEFINITIONS})
target_link_libraries(${lib_name}
ct_core
${matlab_cpp_interface_LIBRARIES}
Expand All @@ -141,7 +139,8 @@ endif(USE_PRESPEC)

## create ct_optcon library
add_library(ct_optcon INTERFACE)
target_include_directories(ct_optcon INTERFACE ${ct_optcon_target_include_dirs})
target_include_directories(ct_optcon INTERFACE ${ct_optcon_TARGET_INCLUDE_DIRS})
target_compile_definitions(ct_optcon INTERFACE ${ct_optcon_COMPILE_DEFINITIONS})
target_link_libraries(ct_optcon INTERFACE
ct_core
${matlab_cpp_interface_LIBRARIES}
Expand Down Expand Up @@ -181,20 +180,11 @@ include(GNUInstallDirs)

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

## get all compile definitions registered so far and create variable
get_directory_property( CompileDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
foreach( d ${CompileDefs} )
set(ct_optcon_compile_definitions ${ct_optcon_compile_definitions} -D${d} ) # recursively add compile definitions
endforeach()

## generate files required for installation
configure_file(cmake/ct_optconConfig.cmake.in "${PROJECT_BINARY_DIR}/ct_optconConfig.cmake" @ONLY)

## copy the header files
install(DIRECTORY include/ct/optcon DESTINATION include/ct)

## copy the cmake files required for find_package()
install(FILES "${PROJECT_BINARY_DIR}/ct_optconConfig.cmake" DESTINATION "share/ct_optcon/cmake")
install(FILES "cmake/ct_optconConfig.cmake" DESTINATION "share/ct_optcon/cmake")

## install library and targets
install(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# cmake-onfig file for the ct_optcon package
# cmake-config file for the ct_optcon package

find_package(ct_core REQUIRED)

set(ct_optcon_COMPILE_DEFINITIONS "@ct_optcon_compile_definitions@")

include(${CMAKE_CURRENT_LIST_DIR}/ct_optcon_export.cmake)

#define includes in legacy mode
Expand Down
7 changes: 7 additions & 0 deletions ct_optcon/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,11 @@ add_custom_command(TARGET run_tests
COMMENT "Running tests"
POST_BUILD COMMAND ${PROJECT_SOURCE_DIR}/test/run_tests.py ${CMAKE_CURRENT_BINARY_DIR} ${UNIT_TEST_TARGETS}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)

## install tests
include(GNUInstallDirs)
install(
TARGETS ${UNIT_TEST_TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/ct_optcon
)
14 changes: 1 addition & 13 deletions ct_rbd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ SET(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
find_package(kindr REQUIRED)
find_package(ct_optcon REQUIRED)

## add compiler definitions exported by ct_optcon
add_definitions(${ct_optcon_COMPILE_DEFINITIONS})


###################
# BUILD LIBRARIES #
Expand Down Expand Up @@ -61,21 +58,12 @@ endif()
# for correct libraries locations across platforms
include(GNUInstallDirs)

## get all compile definitions registered so far and create variable
get_directory_property( CompileDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
foreach( d ${CompileDefs} )
set(ct_rbd_compile_definitions ${ct_rbd_compile_definitions} -D${d} ) # recursively add compile definitions
endforeach()

## generate files required for installation
configure_file(cmake/ct_rbdConfig.cmake.in "${PROJECT_BINARY_DIR}/ct_rbdConfig.cmake" @ONLY)

## copy the header files
install(DIRECTORY include/ct/rbd DESTINATION include/ct)
install(DIRECTORY include/ct/iit DESTINATION include/ct)

## copy the cmake files required for find_package()
install(FILES "${PROJECT_BINARY_DIR}/ct_rbdConfig.cmake" DESTINATION "share/ct_rbd/cmake")
install(FILES "cmake/ct_rbdConfig.cmake" DESTINATION "share/ct_rbd/cmake")

## install library and targets
install(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

find_package(ct_optcon REQUIRED)

set(ct_rbd_COMPILE_DEFINITIONS "@ct_rbd_compile_definitions@")

include(${CMAKE_CURRENT_LIST_DIR}/ct_rbd_export.cmake)

#define includes in legacy mode
Expand Down
7 changes: 7 additions & 0 deletions ct_rbd/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,11 @@ add_custom_command(TARGET run_tests
COMMENT "Running tests"
POST_BUILD COMMAND ${PROJECT_SOURCE_DIR}/test/run_tests.py ${CMAKE_CURRENT_BINARY_DIR} ${UNIT_TEST_TARGETS}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)

## install tests
include(GNUInstallDirs)
install(
TARGETS ${UNIT_TEST_TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/ct_rbd
)

0 comments on commit 5553208

Please sign in to comment.