Skip to content

Commit

Permalink
Merge pull request #127 from xmos/develop
Browse files Browse the repository at this point in the history
Merge to main for release v0.2.0
  • Loading branch information
danielpieczko authored Feb 15, 2024
2 parents 82e4e4d + 5676960 commit 2f4bc4b
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
XCommon CMake Change Log
========================

0.2.0
-----

* ADDED: warning if LIB_NAME variable doesn't match module directory name
* FIXED: APP_BUILD_TARGETS variable wasn't available until XMOS_REGISTER_APP returned

0.1.0
-----

Expand Down
2 changes: 1 addition & 1 deletion settings.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
title: XCommon CMake
project: xcommon_cmake
version: 0.1.0
version: 0.2.0
documentation:
pdfs:
index:
Expand Down
1 change: 1 addition & 0 deletions tests/generated_source_file/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Application requires source file foo.c which is generated in the build directory by a cmake echo command.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(generated_source_file)

set(APP_HW_TARGET XCORE-AI-EXPLORER)

XMOS_REGISTER_APP()

file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/generated)
add_custom_target(foo.c
${CMAKE_COMMAND} -E echo \"void foo() {}\" > ${CMAKE_BINARY_DIR}/generated/foo.c
BYPRODUCTS ${CMAKE_BINARY_DIR}/generated/foo.c
)
target_sources(generated_source_file PRIVATE ${CMAKE_BINARY_DIR}/generated/foo.c)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
void foo();

int main() {
foo();
return 0;
}
Empty file.
3 changes: 3 additions & 0 deletions tests/lib_generated_source_file/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Application uses module lib_mod0, which has a source file that is generated in the build directory before
being compiled and linked. Two configs are created to check that APP_BUILD_TARGETS is correctly used as a
list in lib_mod0's lib_build_info.cmake.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(lib_generated_source_file)

set(APP_HW_TARGET XCORE-AI-EXPLORER)

set(APP_COMPILER_FLAGS_cfg0 -Os)
set(APP_COMPILER_FLAGS_cfg1 -O3)

set(APP_DEPENDENT_MODULES "lib_mod0")

set(XMOS_SANDBOX_DIR ${CMAKE_CURRENT_LIST_DIR}/..)

XMOS_REGISTER_APP()
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "mod0.h"

int main() {
mod0();
return 0;
}
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions tests/lib_generated_source_file/lib_mod0/lib_mod0/api/mod0.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef MOD0_H
#define MOD0_H
void mod0();
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(LIB_NAME lib_mod0)
set(LIB_VERSION 1.0.0)
set(LIB_INCLUDES api)
set(LIB_DEPENDENT_MODULES "")

XMOS_REGISTER_MODULE()

add_custom_target(mod0_generated.c
${CMAKE_COMMAND} -E echo \"void mod0_generated() {}\" > ${CMAKE_BINARY_DIR}/mod0_generated.c
BYPRODUCTS ${CMAKE_BINARY_DIR}/mod0_generated.c
)

foreach(_target ${APP_BUILD_TARGETS})
target_sources(${_target} PRIVATE ${CMAKE_BINARY_DIR}/mod0_generated.c)
endforeach()
7 changes: 7 additions & 0 deletions tests/lib_generated_source_file/lib_mod0/lib_mod0/src/mod0.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "mod0.h"

void mod0_generated();

void mod0() {
mod0_generated();
}
32 changes: 18 additions & 14 deletions xcommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ macro(add_file_flags prefix file_srcs)
string(COMPARE EQUAL ${FLAG_FILE} ${SRC_FILE} _cmp)
if(_cmp)
set(flags ${${prefix}_COMPILER_FLAGS_${FLAG_FILE}})
foreach(target ${BUILD_TARGETS})
foreach(target ${APP_BUILD_TARGETS})
set_source_files_properties(${SRC_FILE_PATH}
TARGET_DIRECTORY ${target}
PROPERTIES COMPILE_OPTIONS "${flags}")
Expand Down Expand Up @@ -462,7 +462,7 @@ function(XMOS_REGISTER_APP)
endif()

# Create app targets with config-specific options
set(BUILD_TARGETS "")
set(APP_BUILD_TARGETS "")
foreach(APP_CONFIG ${APP_CONFIGS})
# Check for the "Default" config we created if user didn't specify any configs
if(${APP_CONFIG} STREQUAL "DEFAULT")
Expand All @@ -472,7 +472,7 @@ function(XMOS_REGISTER_APP)
target_include_directories(${PROJECT_NAME} PRIVATE ${APP_INCLUDES})
target_compile_options(${PROJECT_NAME} PRIVATE ${APP_COMPILER_FLAGS} ${APP_TARGET_COMPILER_FLAG} ${APP_XSCOPE_SRCS})
target_link_options(${PROJECT_NAME} PRIVATE ${APP_COMPILER_FLAGS} ${APP_TARGET_COMPILER_FLAG} ${APP_XSCOPE_SRCS})
list(APPEND BUILD_TARGETS ${PROJECT_NAME})
list(APPEND APP_BUILD_TARGETS ${PROJECT_NAME})
else()
add_executable(${PROJECT_NAME}_${APP_CONFIG})
# If a single app is being configured, build targets can be named after the app configs; in the case of a multi-app
Expand All @@ -486,10 +486,10 @@ function(XMOS_REGISTER_APP)
target_include_directories(${PROJECT_NAME}_${APP_CONFIG} PRIVATE ${APP_INCLUDES})
target_compile_options(${PROJECT_NAME}_${APP_CONFIG} PRIVATE ${APP_COMPILER_FLAGS_${APP_CONFIG}} "-DCONFIG=${APP_CONFIG}" ${APP_TARGET_COMPILER_FLAG} ${APP_XSCOPE_SRCS})
target_link_options(${PROJECT_NAME}_${APP_CONFIG} PRIVATE ${APP_COMPILER_FLAGS_${APP_CONFIG}} ${APP_TARGET_COMPILER_FLAG} ${APP_XSCOPE_SRCS})
list(APPEND BUILD_TARGETS ${PROJECT_NAME}_${APP_CONFIG})
list(APPEND APP_BUILD_TARGETS ${PROJECT_NAME}_${APP_CONFIG})
endif()
endforeach()
set(APP_BUILD_TARGETS ${BUILD_TARGETS} PARENT_SCOPE)
set(APP_BUILD_TARGETS ${APP_BUILD_TARGETS} PARENT_SCOPE)

if(${CONFIGS_COUNT} EQUAL 0)
# Only print the default-only config at the verbose log level
Expand Down Expand Up @@ -527,7 +527,7 @@ function(XMOS_REGISTER_APP)
set(current_module ${PROJECT_NAME})
XMOS_REGISTER_DEPS()

foreach(target ${BUILD_TARGETS})
foreach(target ${APP_BUILD_TARGETS})
get_target_property(all_inc_dirs ${target} INCLUDE_DIRECTORIES)
get_target_property(all_opt_hdrs ${target} OPTIONAL_HEADERS)
set(opt_hdrs_found "")
Expand All @@ -552,7 +552,7 @@ function(XMOS_REGISTER_APP)

if(APP_PCA_ENABLE AND NOT BUILD_NATIVE)
message(STATUS "Generating commands for Pre-Compilation Analysis (PCA)")
foreach(target ${BUILD_TARGETS})
foreach(target ${APP_BUILD_TARGETS})
string(REGEX REPLACE "${PROJECT_NAME}" "" DOT_BUILD_SUFFIX ${target})
set(DOT_BUILD_DIR ${CMAKE_CURRENT_LIST_DIR}/.build${DOT_BUILD_SUFFIX})
set_directory_properties(PROPERTIES ADDITIONAL_CLEAN_FILES ${DOT_BUILD_DIR})
Expand Down Expand Up @@ -614,10 +614,14 @@ function(XMOS_REGISTER_MODULE)
message(WARNING "Expected major version ${DEP_MAJOR_VER} for ${LIB_NAME} but got ${CMAKE_MATCH_1}")
endif()
else()
message(ERROR "Invalid LIB_VERSION ${LIB_VERSION} for ${LIB_NAME}")
message(WARNING "Invalid LIB_VERSION ${LIB_VERSION} for ${LIB_NAME}")
endif()
endif()

# DEP_NAME was set in XMOS_REGISTER_DEPS as the expected name of the module
if(NOT LIB_NAME STREQUAL DEP_NAME)
message(WARNING "Module ${DEP_NAME} has mismatched LIB_NAME: ${LIB_NAME}")
endif()
set(current_module ${LIB_NAME})
XMOS_REGISTER_DEPS()

Expand All @@ -629,7 +633,7 @@ function(XMOS_REGISTER_MODULE)
glob_srcs("LIB" ${module_dir})

set_source_files_properties(${LIB_XC_SRCS} ${LIB_CXX_SRCS} ${LIB_ASM_SRCS} ${LIB_C_SRCS}
TARGET_DIRECTORY ${BUILD_TARGETS}
TARGET_DIRECTORY ${APP_BUILD_TARGETS}
PROPERTIES COMPILE_OPTIONS "${LIB_COMPILER_FLAGS}")

GET_ALL_VARS_STARTING_WITH("LIB_COMPILER_FLAGS_" LIB_COMPILER_FLAGS_VARS)
Expand All @@ -638,7 +642,7 @@ function(XMOS_REGISTER_MODULE)

list(TRANSFORM LIB_INCLUDES PREPEND ${module_dir}/)

foreach(target ${BUILD_TARGETS})
foreach(target ${APP_BUILD_TARGETS})
target_sources(${target} PRIVATE ${ALL_LIB_SRCS_PATH})
target_include_directories(${target} PRIVATE ${LIB_INCLUDES})

Expand Down Expand Up @@ -693,7 +697,7 @@ function(XMOS_REGISTER_DEPS)
message(VERBOSE "Adding static library ${DEP_NAME}-${APP_BUILD_ARCH}")
include(${dep_dir}/${DEP_NAME}/lib/${DEP_NAME}-${APP_BUILD_ARCH}.cmake)
get_target_property(DEP_VERSION ${DEP_NAME} VERSION)
foreach(target ${BUILD_TARGETS})
foreach(target ${APP_BUILD_TARGETS})
target_include_directories(${target} PRIVATE ${LIB_INCLUDES})
target_link_libraries(${target} PRIVATE ${DEP_NAME})
endforeach()
Expand Down Expand Up @@ -740,7 +744,7 @@ function(XMOS_STATIC_LIBRARY)

glob_srcs("LIB" ${CMAKE_CURRENT_SOURCE_DIR})

set(BUILD_TARGETS "")
set(APP_BUILD_TARGETS "")
foreach(lib_arch ${LIB_ARCH})
add_library(${LIB_NAME}-${lib_arch} STATIC)
set_property(TARGET ${LIB_NAME}-${lib_arch} PROPERTY VERSION ${LIB_VERSION})
Expand All @@ -753,9 +757,9 @@ function(XMOS_STATIC_LIBRARY)
set_property(TARGET ${LIB_NAME}-${lib_arch} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib/${lib_arch})
# Set output name so that static library filename does not include architecture
set_property(TARGET ${LIB_NAME}-${lib_arch} PROPERTY ARCHIVE_OUTPUT_NAME ${LIB_NAME})
list(APPEND BUILD_TARGETS ${LIB_NAME}-${lib_arch})
list(APPEND APP_BUILD_TARGETS ${LIB_NAME}-${lib_arch})
endforeach()
set(APP_BUILD_TARGETS ${BUILD_TARGETS} PARENT_SCOPE)
set(APP_BUILD_TARGETS ${APP_BUILD_TARGETS} PARENT_SCOPE)

if(DEFINED XMOS_DEPS_ROOT_DIR)
message(WARNING "XMOS_DEPS_ROOT_DIR is deprecated; please use XMOS_SANDBOX_DIR instead")
Expand Down

0 comments on commit 2f4bc4b

Please sign in to comment.