This repository has been archived by the owner on Sep 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
hFramework.cmake
100 lines (79 loc) · 2.75 KB
/
hFramework.cmake
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
get_filename_component(HFRAMEWORK_DIR ${CMAKE_CURRENT_LIST_FILE} PATH) # for cmake before 2.8.3
if(WIN32)
set(TOOLS_ARCH_NAME win)
elseif(APPLE)
set(TOOLS_ARCH_NAME macos)
else()
set(TOOLS_ARCH_NAME amd64-linux)
endif()
set(HFRAMEWORK_BASE_DIR "${HFRAMEWORK_DIR}")
if ("${BOARD_TYPE}" STREQUAL robocore)
set(HFRAMEWORK_DIR "${HFRAMEWORK_DIR}/robocore")
endif()
set(HFRAMEWORK_DIR_Q "\"${HFRAMEWORK_DIR}\"")
include("${HFRAMEWORK_BASE_DIR}/hFrameworkPort.cmake")
set(compiler_flags "-g")
macro(add_component_lib name)
enable_module(${name})
endmacro()
macro(enable_module name)
if (NOT ((${name} STREQUAL hModules) AND ("${BOARD_TYPE}" STREQUAL robocore)))
if (USES_SDK)
include_directories("${HFRAMEWORK_DIR}/include/${name}")
set(module_libraries "${module_libraries} -l${name}")
else()
execute_process(
COMMAND "${HFRAMEWORK_PATH}/../hcommon/hdev-findmodule" ${name}
OUTPUT_VARIABLE module_path
RESULT_VARIABLE err)
if(${err})
message(FATAL_ERROR "cannot find module")
endif()
string(STRIP ${module_path} module_path)
message("-- Using module from workspace: ${module_path}")
include_directories("${module_path}/include/")
set(ADDITIONAL_LINK_DIRS "${ADDITIONAL_LINK_DIRS} -L${module_path}/build/${PORT}_${BOARD_TYPE}_${BOARD_VERSION_DOT}")
set(module_libraries "${module_libraries} -l${name}")
endif()
endif()
endmacro()
macro(add_hexecutable name)
if (NOT ${PORT} STREQUAL esp32)
list(APPEND ADDITIONAL_LIBS "${module_libraries} -lhFramework")
endif()
update_flags()
add_executable("${name}.elf" ${ARGN})
add_hexecutable_port(${name})
set_target_properties("${name}.elf" PROPERTIES
LINKER_LANGUAGE CXX
SUFFIX "")
if(NOT DEFINED ${main_executable})
set(main_executable ${name})
add_custom_target("flash"
DEPENDS "flash_${name}")
printvars_target_done()
endif()
endmacro()
### Support for printvars
get_property(include_spaces DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
set(vars_info "")
foreach(v IN LISTS include_spaces)
set(vars_info "${vars_info}::include=${v}")
endforeach(v)
function(printvars_target_done)
add_custom_target(
printvars
COMMAND
cmake -E echo 'VARS${vars_info}::sdk=${HFRAMEWORK_PATH}::main_executable=${main_executable}::none=')
endfunction()
### End printvars
include_directories("${HFRAMEWORK_DIR}/include")
if (USES_SDK OR "${BOARD_TYPE}" STREQUAL robocore)
set(ADDITIONAL_LINK_DIRS "-L${HFRAMEWORK_DIR_Q}/libs/${PORT}_${BOARD_TYPE}_${BOARD_VERSION}")
else()
string(REPLACE _ . BOARD_VERSION_DOT ${BOARD_VERSION})
set(ADDITIONAL_LINK_DIRS "-L${HFRAMEWORK_DIR_Q}/build/${PORT}_${BOARD_TYPE}_${BOARD_VERSION_DOT}")
endif()
update_flags()
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")