From d212ead5643d5f519f8daf62c1612693214fd8f9 Mon Sep 17 00:00:00 2001 From: M Starch Date: Wed, 6 Dec 2023 13:21:00 -0500 Subject: [PATCH] Library UTs correctly added with messaging. Fixes #2392 (#2393) --- cmake/FPrime.cmake | 36 +++++++++++++++++++++--------------- cmake/utilities.cmake | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/cmake/FPrime.cmake b/cmake/FPrime.cmake index 236c0a0c79..32af875747 100644 --- a/cmake/FPrime.cmake +++ b/cmake/FPrime.cmake @@ -65,30 +65,31 @@ endfunction(fprime_setup_global_includes) # 4. Add option() to disable library UTs #### macro(fprime_detect_libraries) - foreach (LIBRARY_DIR IN LISTS FPRIME_LIBRARY_LOCATIONS) - get_filename_component(LIBRARY_NAME "${LIBRARY_DIR}" NAME) + foreach (LIBRARY_DIRECTORY IN LISTS FPRIME_LIBRARY_LOCATIONS) + get_filename_component(LIBRARY_NAME "${LIBRARY_DIRECTORY}" NAME) + get_fprime_library_option_string(LIBRARY_OPTION "${LIBRARY_NAME}") # Detect manifest file: # 1. library.cmake (preferred) # 2. .cmake (old standard) - if (EXISTS "${LIBRARY_DIR}/library.cmake") - set(MANIFEST_FILE "${LIBRARY_DIR}/library.cmake") - elseif (EXISTS "${LIBRARY_DIR}/${LIBRARY_NAME}.cmake") - set(MANIFEST_FILE "${LIBRARY_DIR}/${LIBRARY_NAME}.cmake") + if (EXISTS "${LIBRARY_DIRECTORY}/library.cmake") + set(MANIFEST_FILE "${LIBRARY_DIRECTORY}/library.cmake") + elseif (EXISTS "${LIBRARY_DIRECTORY}/${LIBRARY_NAME}.cmake") + set(MANIFEST_FILE "${LIBRARY_DIRECTORY}/${LIBRARY_NAME}.cmake") else() - message(WARNING "[LIBRARY] ${LIBRARY_DIR} does not define library.cmake nor ${LIBRARY_NAME}.cmake. Skipping.") + message(WARNING "[LIBRARY] ${LIBRARY_DIRECTORY} does not define library.cmake nor ${LIBRARY_NAME}.cmake. Skipping.") continue() endif() - message(STATUS "[LIBRARY] Including library ${LIBRARY_NAME} at ${LIBRARY_DIR}") + message(STATUS "[LIBRARY] Including library ${LIBRARY_NAME} at ${LIBRARY_DIRECTORY}") if (CMAKE_DEBUG_OUTPUT) message(STATUS "[LIBRARY] ${LIBRARY_NAME} using manifest ${MANIFEST_FILE}") endif() append_list_property("${MANIFEST_FILE}" GLOBAL PROPERTY FPRIME_LIBRARY_MANIFESTS) # Check to see if the cmake directory exists and add it - if (IS_DIRECTORY "${LIBRARY_DIR}/cmake") - list(APPEND CMAKE_MODULE_PATH "${LIBRARY_DIR}/cmake") + if (IS_DIRECTORY "${LIBRARY_DIRECTORY}/cmake") + list(APPEND CMAKE_MODULE_PATH "${LIBRARY_DIRECTORY}/cmake") endif() - include_directories("${LIBRARY_DIR}") - option(FPRIME_ENABLE_${LIBRARY_NAME}_UTS "Enable UT generation for ${LIBRARY_NAME}" ON) + include_directories("${LIBRARY_DIRECTORY}") + option(FPRIME_ENABLE_${LIBRARY_OPTION}_UTS "Enable UT generation for ${LIBRARY_NAME}" ON) endforeach() endmacro(fprime_detect_libraries) @@ -176,6 +177,7 @@ function(fprime_setup_included_code) if (FPRIME_ENABLE_FRAMEWORK_UTS) set(__FPRIME_NO_UT_GEN__ OFF) endif() + message(STATUS "[LIBRARY] Adding modules from F´ framework") # Faux libraries used as interfaces to non-autocoded fpp items add_library(Fpp INTERFACE) @@ -189,15 +191,19 @@ function(fprime_setup_included_code) add_subdirectory("${FPRIME_FRAMEWORK_PATH}/${_FP_PACKAGE_DIR}/" "${CMAKE_BINARY_DIR}/F-Prime/${_FP_PACKAGE_DIR}") endforeach () unset(FPRIME_CURRENT_MODULE) + message(STATUS "[LIBRARY] Adding modules from F´ framework - DONE") get_property(FPRIME_LIBRARY_MANIFESTS GLOBAL PROPERTY FPRIME_LIBRARY_MANIFESTS) foreach (LIBRARY_MANIFEST IN LISTS FPRIME_LIBRARY_MANIFESTS) set(__FPRIME_NO_UT_GEN__ OFF) - get_filename_component(LIB_DIR "${LIBRARY_MANIFEST}" DIRECTORY) - get_filename_component(LIBRARY_NAME "${LIB_DIR}" NAME) - if (FPRIME_ENABLE_${LIBRARY_NAME}_UTS) + get_filename_component(LIBRARY_DIRECTORY "${LIBRARY_MANIFEST}" DIRECTORY) + get_filename_component(LIBRARY_NAME "${LIBRARY_DIRECTORY}" NAME) + get_fprime_library_option_string(LIBRARY_OPTION "${LIBRARY_NAME}") + if (NOT FPRIME_ENABLE_${LIBRARY_OPTION}_UTS) set(__FPRIME_NO_UT_GEN__ ON) endif() + message(STATUS "[LIBRARY] Adding modules from ${LIBRARY_NAME}") include("${LIBRARY_MANIFEST}") + message(STATUS "[LIBRARY] Adding modules from ${LIBRARY_NAME} - DONE") endforeach() # Always enable UTs for a project set(__FPRIME_NO_UT_GEN__ OFF) diff --git a/cmake/utilities.cmake b/cmake/utilities.cmake index d4bba20bb8..107a7386cd 100644 --- a/cmake/utilities.cmake +++ b/cmake/utilities.cmake @@ -626,3 +626,21 @@ function (filter_lists EXCLUDE_LIST) set(${SOURCE_LIST}_FILTERED "${${SOURCE_LIST}_FILTERED}" PARENT_SCOPE) endforeach() endfunction(filter_lists) + +#### +# Function `get_fprime_library_option_string`: +# +# Returns a standard library option string from a name. Library option strings are derived from the directory and +# converted to a set of valid characters: [A-Z0-9_]. Alphabetic characters are made uppercase, numeric characters are +# maintained, and other characters are replaced with _. +# +# If multiple directories convert to the same name, these are effectively merged with respect to library options. +# +# OUTPUT_VAR: output variable to be set in parent scope +# LIBRARY_NAME: library name to convert to option +#### +function(get_fprime_library_option_string OUTPUT_VAR LIBRARY_NAME) + string(TOUPPER "${LIBRARY_NAME}" LIBRARY_NAME_UPPER) + string(REGEX REPLACE "[^A-Z0-9_]" "_" LIBRARY_OPTION "${LIBRARY_NAME_UPPER}") + set("${OUTPUT_VAR}" "${LIBRARY_OPTION}" PARENT_SCOPE) +endfunction(get_fprime_library_option_string)