-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
76 lines (64 loc) · 3.02 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
# 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)
if(NOT WBC_EXPORT_AUTOGENERATED)
# Fake installation.
install(CODE "MESSAGE(\"This repository simply acts as a container\")")
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-7.0 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
configure_file(
"${CMAKE_SOURCE_DIR}/cmake/CreateAutogeneratedCodeTargets.cmake.in"
"${MDLDESTDIR}/CMakeLists.txt"
@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"
)