diff --git a/build.ps1 b/build.ps1 index 99d0d2c..5542ca8 100644 --- a/build.ps1 +++ b/build.ps1 @@ -5,7 +5,7 @@ param( [switch]$clean ## clean build, wipe out all build artifacts - , [switch]$install ## install mandatory packages + , [switch]$install ## install dependencies, only ) function Invoke-CommandLine { @@ -43,7 +43,7 @@ function Invoke-CommandLine { function Invoke-Bootstrap { # Download bootstrap scripts from external repository - Invoke-RestMethod https://raw.githubusercontent.com/avengineers/bootstrap-installer/v1.12.0/install.ps1 | Invoke-Expression + Invoke-RestMethod https://raw.githubusercontent.com/avengineers/bootstrap-installer/v1.13.0/install.ps1 | Invoke-Expression # Execute bootstrap script . .\.bootstrap\bootstrap.ps1 } diff --git a/cmake/common.cmake b/cmake/common.cmake index e3ad73a..be9963f 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -16,7 +16,10 @@ macro(spl_add_component component_path) add_subdirectory(${CMAKE_SOURCE_DIR}/${component_path}) if(BUILD_KIT STREQUAL prod) - target_link_libraries(${LINK_TARGET_NAME} ${component_name}) + # Only add the target link libraries ${component_name} if the library is defined. + if(TARGET ${component_name}) + target_link_libraries(${LINK_TARGET_NAME} ${component_name}) + endif() endif() endmacro() diff --git a/tests/cmake/common.cmake/CMakeLists.txt b/tests/cmake/common.cmake/CMakeLists.txt index 931e120..d7d6976 100644 --- a/tests/cmake/common.cmake/CMakeLists.txt +++ b/tests/cmake/common.cmake/CMakeLists.txt @@ -1,90 +1,103 @@ -# boilerplate to get CMake running -cmake_minimum_required(VERSION 3.22.0) -project(test-common-cmake C ASM) -set(VARIANT mytestvariant) - -# ## IUT #################################### -include(${CMAKE_CURRENT_LIST_DIR}/../../../cmake/common.cmake) - -# ## test: _spl_slash_to_underscore ######### -# given -set(string_with_slashes "abc/def/ghi") - -# when -_spl_slash_to_underscore(string_with_underscore ${string_with_slashes}) - -# then -if(NOT string_with_underscore STREQUAL "abc_def_ghi") - message(FATAL_ERROR "Failing Test case: string_with_slashes = ${string_with_slashes}.") -endif() - -# ## test: _spl_get_absolute_path ######### -# when -_spl_get_absolute_path(absolute_path "${PROJECT_SOURCE_DIR}/some_dir") - -# then -set(expected_path tests/cmake/common.cmake/some_dir) -string(FIND "${absolute_path}" "${expected_path}" out) - -if(NOT "${out}" GREATER 0) - message(FATAL_ERROR "Failing Test case: ${absolute_path} does not contain ${expected_path}.") -endif() - -# when -_spl_get_absolute_path(absolute_path "${PROJECT_BINARY_DIR}/some_output") - -# then -set(expected_path out/test_cmake/common.cmake/some_output) -string(FIND "${absolute_path}" "${expected_path}" out) - -if(NOT "${out}" GREATER 0) - message(FATAL_ERROR "Failing Test case: ${absolute_path} does not contain ${expected_path}.") -endif() - -# ## test: spl_add_source ######### -# given -set(source_file src/some_source_file.c) -set(other_source_file src/some_other_source_file.c) - -# when -spl_add_source(${source_file}) -spl_add_source(${other_source_file}) - -# then -_spl_get_absolute_path(expected_source_file "${source_file}") -_spl_get_absolute_path(expected_other_source_file "${other_source_file}") -_spl_get_absolute_path(unexpected_source_file "not_expected.c") - -if(NOT expected_source_file IN_LIST SOURCES) - message(FATAL_ERROR "Failing Test case: ${expected_source_file} not found inside ${SOURCES}.") -endif() - -if(NOT expected_other_source_file IN_LIST SOURCES) - message(FATAL_ERROR "Failing Test case: ${expected_other_source_file} not found inside ${SOURCES}.") -endif() - -if(unexpected_source_file IN_LIST SOURCES) - message(FATAL_ERROR "Failing Test case: ${unexpected_source_file} not found inside ${SOURCES}.") -endif() - -#cleanup -unset(SOURCES) - -# ## test: spl_add_component ############### - -# given -set(some_file src/some_file.c) -set(some_other_file src/some_other_file.c) - -# when -spl_add_component(component) -spl_add_component(some_other_component) -set_target_properties(component PROPERTIES LINKER_LANGUAGE C) - -# then -if(NOT "component" IN_LIST COMPONENT_NAMES) - message(FATAL_ERROR "Failing Test case: component not found inside ${COMPONENT_NAMES}.") -endif() - -# ## test: _spl_create_build_info_file (tests are written in test_cmake.py)##### -_spl_create_build_info_file() +# boilerplate to get CMake running +cmake_minimum_required(VERSION 3.22.0) +project(test-common-cmake C ASM) +set(VARIANT mytestvariant) + +# ## IUT #################################### +include(${CMAKE_CURRENT_LIST_DIR}/../../../cmake/common.cmake) + +# ## test: _spl_slash_to_underscore ######### +# given +set(string_with_slashes "abc/def/ghi") + +# when +_spl_slash_to_underscore(string_with_underscore ${string_with_slashes}) + +# then +if(NOT string_with_underscore STREQUAL "abc_def_ghi") + message(FATAL_ERROR "Failing Test case: string_with_slashes = ${string_with_slashes}.") +endif() + +# ## test: _spl_get_absolute_path ######### +# when +_spl_get_absolute_path(absolute_path "${PROJECT_SOURCE_DIR}/some_dir") + +# then +set(expected_path tests/cmake/common.cmake/some_dir) +string(FIND "${absolute_path}" "${expected_path}" out) + +if(NOT "${out}" GREATER 0) + message(FATAL_ERROR "Failing Test case: ${absolute_path} does not contain ${expected_path}.") +endif() + +# when +_spl_get_absolute_path(absolute_path "${PROJECT_BINARY_DIR}/some_output") + +# then +set(expected_path out/test_cmake/common.cmake/some_output) +string(FIND "${absolute_path}" "${expected_path}" out) + +if(NOT "${out}" GREATER 0) + message(FATAL_ERROR "Failing Test case: ${absolute_path} does not contain ${expected_path}.") +endif() + +# ## test: spl_add_source ######### +# given +set(source_file src/some_source_file.c) +set(other_source_file src/some_other_source_file.c) + +# when +spl_add_source(${source_file}) +spl_add_source(${other_source_file}) + +# then +_spl_get_absolute_path(expected_source_file "${source_file}") +_spl_get_absolute_path(expected_other_source_file "${other_source_file}") +_spl_get_absolute_path(unexpected_source_file "not_expected.c") + +if(NOT expected_source_file IN_LIST SOURCES) + message(FATAL_ERROR "Failing Test case: ${expected_source_file} not found inside ${SOURCES}.") +endif() + +if(NOT expected_other_source_file IN_LIST SOURCES) + message(FATAL_ERROR "Failing Test case: ${expected_other_source_file} not found inside ${SOURCES}.") +endif() + +if(unexpected_source_file IN_LIST SOURCES) + message(FATAL_ERROR "Failing Test case: ${unexpected_source_file} not found inside ${SOURCES}.") +endif() + +# cleanup +unset(SOURCES) + +# ## test: spl_add_component ############### + +# given +set(some_file src/some_file.c) +set(some_other_file src/some_other_file.c) + +# when +spl_add_component(component) +spl_add_component(some_other_component) +spl_add_component(comp_without_sources) +set_target_properties(component PROPERTIES LINKER_LANGUAGE C) + +# then +foreach(component IN ITEMS component some_other_component comp_without_sources) + if(NOT "${component}" IN_LIST COMPONENT_NAMES) + message(FATAL_ERROR "Failing Test case: ${component} not found inside ${COMPONENT_NAMES}.") + endif() + + if(NOT TARGET ${component}) + message(FATAL_ERROR "Failing Test case: ${component} not found as a target.") + endif() +endforeach() + +_spl_get_absolute_path(expected_include "comp_without_sources/src") + +if(NOT expected_include IN_LIST target_include_directories__INCLUDES) + message(FATAL_ERROR "Failing Test case: ${expected_include} not found inside ${target_include_directories__INCLUDES}.") +endif() + +# ## test: _spl_create_build_info_file (tests are written in test_cmake.py)##### +_spl_create_build_info_file() diff --git a/tests/cmake/common.cmake/comp_without_sources/CMakeLists.txt b/tests/cmake/common.cmake/comp_without_sources/CMakeLists.txt new file mode 100644 index 0000000..409650f --- /dev/null +++ b/tests/cmake/common.cmake/comp_without_sources/CMakeLists.txt @@ -0,0 +1 @@ +spl_create_component(LONG_NAME "Some component without sources") diff --git a/tests/cmake/common.cmake/comp_without_sources/src/empty.h b/tests/cmake/common.cmake/comp_without_sources/src/empty.h new file mode 100644 index 0000000..e69de29