Skip to content
This repository was archived by the owner on Jan 15, 2021. It is now read-only.

Commit 727fb2f

Browse files
committed
Merge pull request #272 from autopulated/master
Build system improvements
2 parents 98959be + a24a9c3 commit 727fb2f

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

yotta/lib/templates/base_CMakeLists.txt

+29-4
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,37 @@ cmake_policy(SET CMP0017 OLD)
1919
# toolchain file for {{ target_name }}
2020
set(CMAKE_TOOLCHAIN_FILE "{{ toolchain_file | replaceBackslashes }}")
2121

22+
# provide function for post-processing executables
23+
function (yotta_postprocess_target target_type_ target_name_)
24+
if(COMMAND yotta_apply_target_rules)
25+
yotta_apply_target_rules(${target_type_} ${target_name_})
26+
endif()
27+
28+
# For backwards compatibility, support YOTTA_POSTPROCESS_COMMAND.
29+
if(DEFINED YOTTA_POSTPROCESS_COMMAND AND ${target_type_} STREQUAL "EXECUTABLE")
30+
#message(AUTHOR_WARNING "This target defines a YOTTA_POSTPROCESS_COMMAND for which support has been deprecated. Please define a CMake function yotta_apply_target_rules(build_object_type build_object) instead.")
31+
string(REPLACE YOTTA_CURRENT_EXE_NAME "${target_name_}" LOCAL_POSTPROCESS_COMMAND "${YOTTA_POSTPROCESS_COMMAND}")
32+
separate_arguments(LOCAL_POSTPROCESS_COMMAND_SEPARATED UNIX_COMMAND ${LOCAL_POSTPROCESS_COMMAND})
33+
add_custom_command(
34+
TARGET ${target_name_}
35+
POST_BUILD
36+
COMMAND ${LOCAL_POSTPROCESS_COMMAND_SEPARATED}
37+
)
38+
endif()
39+
endfunction()
40+
41+
# set target-defined definitions
2242
{{ set_definitions }}
2343
{% endif %}
2444

2545
project({{ component_name }})
2646

2747
{% if toplevel %}
2848
# Definitions provided by the target configuration info:
29-
if("${CMAKE_C_COMPILER_ID}" STREQUAL "ARMCC")
30-
add_definitions("--preinclude \"{{ config_include_file | replaceBackslashes }}\"")
31-
else()
32-
add_definitions("-include \"{{ config_include_file | replaceBackslashes }}\"")
49+
if(NOT DEFINED YOTTA_FORCE_INCLUDE_FLAG)
50+
set(YOTTA_FORCE_INCLUDE_FLAG "-include")
3351
endif()
52+
add_definitions("${YOTTA_FORCE_INCLUDE_FLAG} \"{{ config_include_file | replaceBackslashes }}\"")
3453
{% endif %}
3554

3655
# include root directories of all components we depend on (directly and
@@ -54,6 +73,12 @@ endif()
5473
{{ include_other_dirs }}
5574
{% endif %}
5675

76+
# modules with custom CMake build systems may append to the
77+
# YOTTA_GLOBAL_INCLUDE_DIRS property to add compile-time-determined include
78+
# directories:
79+
get_property(GLOBAL_INCLUDE_DIRS GLOBAL PROPERTY YOTTA_GLOBAL_INCLUDE_DIRS)
80+
include_directories(${GLOBAL_INCLUDE_DIRS})
81+
5782
# Provide the version of the component being built, in case components want to
5883
# embed this into compiled libraries
5984
set(YOTTA_COMPONENT_VERSION "{{ component_version }}")

yotta/lib/templates/subdir_CMakeLists.txt

+3-10
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,9 @@ add_library({{ object_name }}
4848
{% endif %}
4949

5050
{% if executable %}
51-
# if the target has defined a post-processing step, perform it:
52-
if(YOTTA_POSTPROCESS_COMMAND)
53-
string(REPLACE YOTTA_CURRENT_EXE_NAME "{{ object_name }}" LOCAL_POSTPROCESS_COMMAND "${YOTTA_POSTPROCESS_COMMAND}")
54-
separate_arguments(LOCAL_POSTPROCESS_COMMAND_SEPARATED UNIX_COMMAND ${LOCAL_POSTPROCESS_COMMAND})
55-
add_custom_command(
56-
TARGET {{ object_name }}
57-
POST_BUILD
58-
COMMAND ${LOCAL_POSTPROCESS_COMMAND_SEPARATED}
59-
)
60-
endif()
51+
yotta_postprocess_target(EXECUTABLE {{ object_name }})
52+
{% else %}
53+
yotta_postprocess_target(LIBRARY {{ object_name }})
6154
{% endif %}
6255

6356
{% if resource_files %}

yotta/lib/templates/test_CMakeLists.txt

+1-10
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,7 @@ set_target_properties({{ object_name }} PROPERTIES
3838
target_link_libraries({{ object_name }}
3939
{{ link_dependencies | join('\n ') }}
4040
)
41-
# if the target has defined a post-processing step, perform it:
42-
if(YOTTA_POSTPROCESS_COMMAND)
43-
string(REPLACE YOTTA_CURRENT_EXE_NAME "{{ object_name }}" LOCAL_POSTPROCESS_COMMAND "${YOTTA_POSTPROCESS_COMMAND}")
44-
separate_arguments(LOCAL_POSTPROCESS_COMMAND_SEPARATED UNIX_COMMAND ${LOCAL_POSTPROCESS_COMMAND})
45-
add_custom_command(
46-
TARGET {{ object_name }}
47-
POST_BUILD
48-
COMMAND ${LOCAL_POSTPROCESS_COMMAND_SEPARATED}
49-
)
50-
endif()
41+
yotta_postprocess_target(EXECUTABLE {{ object_name }})
5142
add_test({{ object_name }} {{ object_name }})
5243
add_dependencies(all_tests {{ object_name }})
5344

0 commit comments

Comments
 (0)