diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e310755..8264d3f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 ----- diff --git a/settings.yml b/settings.yml index 403e04e..602cfdf 100644 --- a/settings.yml +++ b/settings.yml @@ -1,6 +1,6 @@ title: XCommon CMake project: xcommon_cmake -version: 0.1.0 +version: 0.2.0 documentation: pdfs: index: diff --git a/tests/generated_source_file/README.txt b/tests/generated_source_file/README.txt new file mode 100644 index 0000000..2a3c77b --- /dev/null +++ b/tests/generated_source_file/README.txt @@ -0,0 +1 @@ +Application requires source file foo.c which is generated in the build directory by a cmake echo command. diff --git a/tests/generated_source_file/app_generated_source_file/CMakeLists.txt b/tests/generated_source_file/app_generated_source_file/CMakeLists.txt new file mode 100644 index 0000000..8c70e15 --- /dev/null +++ b/tests/generated_source_file/app_generated_source_file/CMakeLists.txt @@ -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) diff --git a/tests/generated_source_file/app_generated_source_file/src/main.c b/tests/generated_source_file/app_generated_source_file/src/main.c new file mode 100644 index 0000000..bb4036b --- /dev/null +++ b/tests/generated_source_file/app_generated_source_file/src/main.c @@ -0,0 +1,6 @@ +void foo(); + +int main() { + foo(); + return 0; +} diff --git a/tests/generated_source_file/generated_source_file.expect b/tests/generated_source_file/generated_source_file.expect new file mode 100644 index 0000000..e69de29 diff --git a/tests/lib_generated_source_file/README.txt b/tests/lib_generated_source_file/README.txt new file mode 100644 index 0000000..b4ea371 --- /dev/null +++ b/tests/lib_generated_source_file/README.txt @@ -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. diff --git a/tests/lib_generated_source_file/app_lib_generated_source_file/CMakeLists.txt b/tests/lib_generated_source_file/app_lib_generated_source_file/CMakeLists.txt new file mode 100644 index 0000000..71751ff --- /dev/null +++ b/tests/lib_generated_source_file/app_lib_generated_source_file/CMakeLists.txt @@ -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() diff --git a/tests/lib_generated_source_file/app_lib_generated_source_file/src/main.c b/tests/lib_generated_source_file/app_lib_generated_source_file/src/main.c new file mode 100644 index 0000000..537baa2 --- /dev/null +++ b/tests/lib_generated_source_file/app_lib_generated_source_file/src/main.c @@ -0,0 +1,6 @@ +#include "mod0.h" + +int main() { + mod0(); + return 0; +} diff --git a/tests/lib_generated_source_file/lib_generated_source_file_cfg0.expect b/tests/lib_generated_source_file/lib_generated_source_file_cfg0.expect new file mode 100644 index 0000000..e69de29 diff --git a/tests/lib_generated_source_file/lib_generated_source_file_cfg1.expect b/tests/lib_generated_source_file/lib_generated_source_file_cfg1.expect new file mode 100644 index 0000000..e69de29 diff --git a/tests/lib_generated_source_file/lib_mod0/lib_mod0/api/mod0.h b/tests/lib_generated_source_file/lib_mod0/lib_mod0/api/mod0.h new file mode 100644 index 0000000..c3df73a --- /dev/null +++ b/tests/lib_generated_source_file/lib_mod0/lib_mod0/api/mod0.h @@ -0,0 +1,4 @@ +#ifndef MOD0_H +#define MOD0_H +void mod0(); +#endif diff --git a/tests/lib_generated_source_file/lib_mod0/lib_mod0/lib_build_info.cmake b/tests/lib_generated_source_file/lib_mod0/lib_mod0/lib_build_info.cmake new file mode 100644 index 0000000..6c440eb --- /dev/null +++ b/tests/lib_generated_source_file/lib_mod0/lib_mod0/lib_build_info.cmake @@ -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() diff --git a/tests/lib_generated_source_file/lib_mod0/lib_mod0/src/mod0.c b/tests/lib_generated_source_file/lib_mod0/lib_mod0/src/mod0.c new file mode 100644 index 0000000..c970058 --- /dev/null +++ b/tests/lib_generated_source_file/lib_mod0/lib_mod0/src/mod0.c @@ -0,0 +1,7 @@ +#include "mod0.h" + +void mod0_generated(); + +void mod0() { + mod0_generated(); +} diff --git a/xcommon.cmake b/xcommon.cmake index a5480e7..9c4f90f 100644 --- a/xcommon.cmake +++ b/xcommon.cmake @@ -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}") @@ -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") @@ -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 @@ -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 @@ -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 "") @@ -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}) @@ -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() @@ -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) @@ -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}) @@ -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() @@ -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}) @@ -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")