forked from robotology/whole-body-controllers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
108 lines (90 loc) · 4.25 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
# Author: Gabriele Nava, Diego Ferigo
# CopyPolicy: Released under the terms of the GNU GPL v2.0.
cmake_minimum_required(VERSION 3.5)
project(whole-body-controllers)
option(WBC_EXPORT_AUTOGENERATED "Enable the target to export code generated with Simulink Coder" OFF)
option(WBC_INSTALL_ALL_HOME_POS "Installation of all available home positions" ON)
# ======================================
# Install home positions and WBC library
# ======================================
find_package(YARP REQUIRED)
yarp_configure_external_installation(wbc)
add_subdirectory(utilities)
add_subdirectory(library)
add_subdirectory(config)
# Install the example controller model (YOGA+matlab-simulator)
set(FLOATING_BASE_BALANCING_TORQCTRL_INSTALL_MATLAB_FILESDIR ${CMAKE_INSTALL_PREFIX}/mex/+wbc/examples CACHE
STRING "Location (relative to the install prefix) in which the Matlab .m files and simulink .mdl models are installed.")
set(M_FILES_DIR ${whole-body-controllers_SOURCE_DIR}/controllers/+floatingBaseBalancingTorqueControlWithSimulator)
install(
DIRECTORY ${M_FILES_DIR}
DESTINATION ${FLOATING_BASE_BALANCING_TORQCTRL_INSTALL_MATLAB_FILESDIR}
USE_SOURCE_PERMISSIONS
FILES_MATCHING
PATTERN "*.m"
PATTERN "*.jpeg"
PATTERN "*.mdl")
# ======================
# Autogeneration routine
# ======================
if(NOT WBC_EXPORT_AUTOGENERATED)
# Fake installation.
install(CODE "MESSAGE(\"Disabled exporting of autogenerated c++ code from Simulink.\")")
return()
endif()
# Load custom macro and functions
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(RegisterMdl)
initialize_mdl_set(NAME WHOLE_BODY_CONTROLLERS)
add_subdirectory(controllers)
# ============================
# EXPORT AUTOGENERATED SOURCES
# ============================
# Custom target for exporting the autogenerated sources
add_custom_target(copy-autogenerated-models)
set(AUTOGENERATED_WBC_SOURCE_DIR "" CACHE STRING
"Location of the autogenerated-whole-body-controllers repository source code")
# Prepare the autogenerated folder
get_property(AUTOGENERATED_FOLDERS GLOBAL PROPERTY WHOLE_BODY_CONTROLLERS)
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/autogenerated")
file(WRITE "${CMAKE_BINARY_DIR}/autogenerated/CMakeLists.txt" "# Exported controllers\n\n")
# Find clang-format
find_program(ClangFormat_EXECUTABLE
DOC "Path to the clang-format executable."
NAMES clang-format clang-format-9 clang-format-8 clang-format-7 clang-format-6.0 clang-format-5.0 clang-format-4.0)
configure_file(${CMAKE_SOURCE_DIR}/.clang-format ${CMAKE_BINARY_DIR}/.clang-format COPYONLY)
# Copy only h and cpp files
foreach(SOURCEDIR ${AUTOGENERATED_FOLDERS})
get_filename_component(MDLDIRNAME ${SOURCEDIR} NAME)
set(MDLDESTDIR "${CMAKE_BINARY_DIR}/autogenerated/${MDLDIRNAME}")
file(APPEND "${CMAKE_BINARY_DIR}/autogenerated/CMakeLists.txt" "add_subdirectory(${MDLDIRNAME})\n")
file(MAKE_DIRECTORY "${MDLDESTDIR}")
string(REGEX MATCH "[^_]*" MDL_NAME ${MDLDIRNAME}) # Remove _gtw_rtw
# Create the CMakeLists.txt of the model
configure_file(
"${CMAKE_SOURCE_DIR}/cmake/CreateAutogeneratedCodeTargets.cmake.in"
"${MDLDESTDIR}/CMakeLists.txt"
@ONLY)
# Copy the main file
configure_file(
"${PROJECT_SOURCE_DIR}/src/driver.cpp.in"
"${MDLDESTDIR}/driver.cpp"
@ONLY)
# Copy sources to the build directory
add_custom_command(TARGET copy-autogenerated-models
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${SOURCEDIR}/*.h" "${SOURCEDIR}/*.cpp" "${SOURCEDIR}/defines.txt" "${MDLDESTDIR}"
COMMENT "Copying ${MDLDIRNAME} to the build folder.")
# Apply clang-format style
if(NOT ${ClangFormat_EXECUTABLE} STREQUAL "ClangFormat_EXECUTABLE-NOTFOUND")
add_custom_command(TARGET copy-autogenerated-models
PRE_BUILD
WORKING_DIRECTORY "${MDLDESTDIR}"
COMMAND ${ClangFormat_EXECUTABLE} -i -style=file *.cpp *.h)
endif()
endforeach()
# Move the directory to the autogenerated-whole-body-controllers repository
add_custom_command(TARGET copy-autogenerated-models
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_BINARY_DIR}/autogenerated" "${AUTOGENERATED_WBC_SOURCE_DIR}/autogenerated"
COMMENT "Copying generated files to ${AUTOGENERATED_WBC_SOURCE_DIR}/autogenerated")