Skip to content

Commit

Permalink
Library UTs correctly added with messaging. Fixes #2392 (#2393)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStarch authored Dec 6, 2023
1 parent 0ed8e0b commit d212ead
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
36 changes: 21 additions & 15 deletions cmake/FPrime.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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. <library>.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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions cmake/utilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit d212ead

Please sign in to comment.