2021-06-17 21:32:24 +00:00
|
|
|
# Symlink Function
|
|
|
|
function(install_symlink target link)
|
2024-11-15 20:26:33 +00:00
|
|
|
cmake_path(GET link PARENT_PATH parent)
|
2022-07-04 20:44:00 +00:00
|
|
|
if(parent STREQUAL "")
|
|
|
|
set(parent ".")
|
|
|
|
endif()
|
|
|
|
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/symlink/${parent}")
|
|
|
|
file(CREATE_LINK "${target}" "${CMAKE_BINARY_DIR}/symlink/${link}" SYMBOLIC)
|
|
|
|
install(FILES "${CMAKE_BINARY_DIR}/symlink/${link}" DESTINATION "${parent}")
|
2021-06-17 21:32:24 +00:00
|
|
|
endfunction()
|
2022-07-30 02:13:03 +00:00
|
|
|
|
|
|
|
# Embed Resources
|
2022-08-06 00:08:13 +00:00
|
|
|
set(util_list_dir "${CMAKE_CURRENT_LIST_DIR}")
|
2022-07-30 02:13:03 +00:00
|
|
|
function(embed_resource target file)
|
|
|
|
# Get C Name
|
2024-11-15 20:26:33 +00:00
|
|
|
cmake_path(GET file FILENAME name)
|
2022-07-30 02:13:03 +00:00
|
|
|
string(MAKE_C_IDENTIFIER "${name}" name)
|
2022-08-06 00:08:13 +00:00
|
|
|
# Add Command
|
2024-11-20 00:57:43 +00:00
|
|
|
set(in "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
|
|
|
|
set(out "${CMAKE_CURRENT_BINARY_DIR}/${name}.c")
|
|
|
|
set(script "${util_list_dir}/embed-resource.cmake")
|
|
|
|
add_custom_command(OUTPUT "${out}"
|
2022-08-06 00:08:13 +00:00
|
|
|
COMMAND "${CMAKE_COMMAND}"
|
2024-11-20 00:57:43 +00:00
|
|
|
ARGS "-DEMBED_IN=${in}" "-DEMBED_OUT=${out}" "-P" "${script}"
|
|
|
|
DEPENDS "${in}" "${script}"
|
|
|
|
VERBATIM
|
2022-08-06 00:08:13 +00:00
|
|
|
)
|
2022-07-30 02:13:03 +00:00
|
|
|
# Add To Target
|
2024-11-20 00:57:43 +00:00
|
|
|
target_sources("${target}" PRIVATE "${out}")
|
2022-07-30 02:13:03 +00:00
|
|
|
endfunction()
|
2024-01-20 07:10:18 +00:00
|
|
|
|
|
|
|
# Nicer Output
|
|
|
|
function(message log_level)
|
|
|
|
if((NOT MESSAGE_QUIET) OR (NOT (log_level STREQUAL "STATUS" OR log_level MATCHES "^CHECK_")))
|
|
|
|
_message("${log_level}" ${ARGN})
|
|
|
|
endif()
|
|
|
|
endfunction()
|
2024-11-20 00:57:43 +00:00
|
|
|
|
|
|
|
# Exporting Targets And Headers
|
|
|
|
macro(_get_sdk_header_dir target)
|
|
|
|
set(sdk_dir "${MCPI_SDK_INCLUDE_DIR}/${target}")
|
|
|
|
endmacro()
|
|
|
|
function(setup_header_dirs target)
|
|
|
|
_get_sdk_header_dir("${target}")
|
|
|
|
# Get Header Type
|
|
|
|
set(header_type "PUBLIC")
|
|
|
|
get_target_property(type "${target}" TYPE)
|
|
|
|
if ("${type}" STREQUAL "INTERFACE_LIBRARY")
|
|
|
|
set(header_type "INTERFACE")
|
|
|
|
endif()
|
|
|
|
# Loop
|
|
|
|
foreach(dir IN LISTS ARGN)
|
|
|
|
# Add To Target
|
|
|
|
target_include_directories("${target}" "${header_type}" "$<BUILD_INTERFACE:${dir}>")
|
|
|
|
# Add To SDK
|
|
|
|
if(BUILD_ARM_COMPONENTS)
|
|
|
|
install(
|
|
|
|
DIRECTORY "${dir}/"
|
|
|
|
DESTINATION "${sdk_dir}"
|
|
|
|
FILES_MATCHING
|
|
|
|
PATTERN "*.h"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
# Add SDK Headers To Target
|
|
|
|
if(BUILD_ARM_COMPONENTS)
|
|
|
|
target_include_directories("${target}" "${header_type}" "$<INSTALL_INTERFACE:${sdk_dir}>")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
function(setup_library target should_install should_export)
|
|
|
|
# Install
|
|
|
|
if(should_install)
|
|
|
|
install(TARGETS "${target}" DESTINATION "${MCPI_LIB_DIR}")
|
|
|
|
endif()
|
|
|
|
# SDK
|
|
|
|
if(should_export AND BUILD_ARM_COMPONENTS)
|
|
|
|
install(TARGETS "${target}" EXPORT sdk DESTINATION "${MCPI_SDK_LIB_DIR}")
|
|
|
|
endif()
|
|
|
|
endfunction()
|