diff --git a/CMakeLists.txt b/CMakeLists.txt index 470a04f2b..a3d6b5d40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,10 +4,16 @@ # ###################################################################### # -# This defines the following static library target(s): +# This defines the following target(s): # -# osal : The main library containing the OSAL binary code -# This is based off the OSAL_SYSTEM_OSTYPE selection +# osal_public_api : Interface library that refers to the OSAL public API only. +# This may be used for applications that need to use the +# OSAL-provided types (such as common-types.h) but do not +# make any OSAL API calls. +# +# osal : The main library containing the OSAL binary code. This is +# the normal library that applications should link to. +# This is built based off the OSAL_SYSTEM_OSTYPE selection # # osal_bsp : The board support library containing the system- # specific entry point function (e.g. main) and the @@ -21,6 +27,37 @@ # Linking with this library also links with osal_bsp, # but not necessarily the osal library itself. # +# ut_coverage_compile : an interface target that contains the +# compiler options/definitions to enable coverage +# instrumentation in the generated objects. It should +# be specified on files compiled for coverage analysis. +# +# ut_coverage_link : an interface target that contains options/definitions +# and any link libraries to enable coverage instrumentation in +# the final executable. It should be specified on coverage +# test executable targets. +# +# +# The following options and variables will customize the build: +# +# OSAL_SYSTEM_BSPTYPE: Should be set by the caller to indicate the type of +# BSP to build. This is a minimal platform-specific shim +# layer to aid with startup and shutdown. This implies a +# value for OSTYPE (see below). +# +# OSAL_SYSTEM_OSTYPE: The selected OS abstraction type (posix, vxworks, rtems). +# Normally this setting is not needed to be configured as it is +# inferred from the BSP type. +# +# ENABLE_UNIT_TESTS : Boolean, enables build of the unit tests (coverage and functional) +# +# OSAL_OMIT_DEPRECATED : Boolean, Compile without deprecated or obsolete features for +# forward compatibility testing. Any features marked as deprecated +# will be disabled, allowing developers to test software based +# only on currently-supported software features and patterns. +# +# OSAL_EXT_SOURCE_DIR : External source directory to check for BSP/OS implementation +# # Additionally the following target is defined if ENABLE_UNIT_TESTS # is set TRUE: # @@ -28,7 +65,9 @@ # This is for unit testing OSAL-based applications # It operates in conjunction with the ut_assert library. # -# This also exports the following variables: +# For backward compatibility with previous versions, this also exports the following +# variables. Code which is depending on these values should migrate to using the +# interfaces of the provide ut_coverage_compile/link targets instead. # # UT_COVERAGE_COMPILE_FLAGS : Compiler flags that must be used to # instrument code for coverage testing @@ -41,8 +80,27 @@ # ###################################################################### cmake_minimum_required(VERSION 3.5) + +# Set the policy dictating use of target_link_libraries across directories +# Either OLD or NEW should work here but setting it to something avoids a +# warning when using newer versions of the tool. +if (CMAKE_VERSION VERSION_GREATER 3.13) + cmake_policy(SET CMP0079 NEW) +endif() + project(OSAL C) +# define a custom property to track relationship between BSP and OS +# this should be set on BSP "impl" targets to indicate the correct OS impl to go with it +define_property(TARGET PROPERTY OSAL_EXPECTED_OSTYPE + BRIEF_DOCS + "The expected OS type for an OSAL BSP implementation" + FULL_DOCS + "This property is used to indicate the OS implementation layer that is intended to be paired with the BSP implementation" +) + +option(OSAL_OMIT_DEPRECATED "Compile without deprecated or obsolete features for backward compatibility testing" OFF) + # The "OSAL_EXT_SOURCE_DIR" cache variable may be set to a path # on the host containing extra OS/BSP implementations which are not # part of the open source release. @@ -65,10 +123,10 @@ endforeach(CONFIG OSAL_CONFIGURATION_FILE) # Use the supplied configuration to generate the osconfig.h file # which can be referenced by the code. This will be stored in the top level # "inc" directory of the binary output directory -file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/inc") +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/inc") configure_file( "${OSAL_SOURCE_DIR}/osconfig.h.in" - "${OSAL_BINARY_DIR}/osconfig.gen" + "${CMAKE_CURRENT_BINARY_DIR}/osconfig.gen" @ONLY ) @@ -76,15 +134,41 @@ configure_file( # This avoids unnecessarily rebuilding all code in case cmake was re-run # and but generated the same file. execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${OSAL_BINARY_DIR}/osconfig.gen" - "${CMAKE_BINARY_DIR}/inc/osconfig.h" + "${CMAKE_CURRENT_BINARY_DIR}/osconfig.gen" + "${CMAKE_CURRENT_BINARY_DIR}/inc/osconfig.h" ) +# The "osal_public_api" is an interface target that will always be defined by this script, +# and refers to the complete set of public API header files for OSAL +add_library(osal_public_api INTERFACE) + +# The initial set of directories that define the OSAL API +# This is used to initialize the interface include directory property of external targets +target_include_directories(osal_public_api INTERFACE + $ + $ + $ +) +if (OSAL_OMIT_DEPRECATED) + target_compile_definitions(osal_public_api INTERFACE OSAL_OMIT_DEPRECATED) +endif (OSAL_OMIT_DEPRECATED) + + +# OSAL_SYSTEM_BSPTYPE indicate which of the BSP packages +# to build. If not defined then no OSAL implementation will be built, however +# the api interface target (osal_public_api) is still usable. Therefore +# this is not considered a fatal error for that reason. If called with no BSP type, +# then only the osal_public_api interface target will be defined, and the script ends here. +if (NOT DEFINED OSAL_SYSTEM_BSPTYPE) + message(STATUS "OSAL_SYSTEM_BSPTYPE not defined, no OSAL implementation will be compiled") + return() +endif () + # The initial set of directories that define the OSAL API # This is used to initialize the interface include directory property of external targets set(OSAL_API_INCLUDE_DIRECTORIES "${OSAL_SOURCE_DIR}/src/os/inc" - "${CMAKE_BINARY_DIR}/inc" + "${CMAKE_CURRENT_BINARY_DIR}/inc" ) include_directories(${OSAL_API_INCLUDE_DIRECTORIES}) @@ -97,6 +181,8 @@ add_definitions(${OSAL_USER_C_FLAGS}) # but flagged using "EXCLUDE_FROM_ALL" so they won't be built unless actually used. This # is because the library is usable with functional tests, not just unit (coverage) tests. # This is done early, so that other targets may reference UT_ASSERT_SOURCE_DIR if needed +# Note that UT assert is only usable with an OSAL BSP implementation, thus this target +# cannot be compiled unless a specific BSP is selected. add_subdirectory(ut_assert) # @@ -104,13 +190,6 @@ add_subdirectory(ut_assert) # Build the BSP layer # - -# OSAL_SYSTEM_BSPTYPE indicate which of the BSP packages -# to build. This is required and must be defined. Confirm that this exists -# and error out now if it does not. -if (NOT DEFINED OSAL_SYSTEM_BSPTYPE) - message(FATAL_ERROR "OSAL_SYSTEM_BSPTYPE must be set to the appropriate BSP") -endif () if (OSAL_EXT_SOURCE_DIR AND IS_DIRECTORY "${OSAL_EXT_SOURCE_DIR}/${OSAL_SYSTEM_BSPTYPE}") set(OSAL_BSP_SOURCE_DIR "${OSAL_EXT_SOURCE_DIR}/${OSAL_SYSTEM_BSPTYPE}") elseif(IS_DIRECTORY "${OSAL_SOURCE_DIR}/src/bsp/${OSAL_SYSTEM_BSPTYPE}") @@ -131,12 +210,20 @@ message(STATUS "BSP Selection: ${OSAL_SYSTEM_BSPTYPE} at ${OSAL_BSP_SOURCE_DIR}" # The Implementation-Specific BSP subdirectory should define # an OBJECT target named "osal_${OSAL_SYSTEM_BSPTYPE}_impl" add_subdirectory(${OSAL_BSP_SOURCE_DIR} ${OSAL_SYSTEM_BSPTYPE}_impl) + +target_compile_definitions(osal_${OSAL_SYSTEM_BSPTYPE}_impl PRIVATE + $ +) +target_compile_options(osal_${OSAL_SYSTEM_BSPTYPE}_impl PRIVATE + $ +) target_include_directories(osal_${OSAL_SYSTEM_BSPTYPE}_impl PRIVATE ${OSAL_SOURCE_DIR}/src/bsp/shared/inc ) # Confirm that the selected OS is compatible with the selected BSP. -if (DEFINED OSAL_EXPECTED_OSTYPE) +get_target_property(OSAL_EXPECTED_OSTYPE osal_${OSAL_SYSTEM_BSPTYPE}_impl OSAL_EXPECTED_OSTYPE) +if (OSAL_EXPECTED_OSTYPE) if (NOT DEFINED OSAL_SYSTEM_OSTYPE) # In the event that OSAL_SYSTEM_OSTYPE was not specified at all, # implicitly assume the expected OSTYPE. @@ -146,29 +233,7 @@ if (DEFINED OSAL_EXPECTED_OSTYPE) # Not calling this a fatal error because it could possibly be intended during development message(WARNING "Mismatched BSP/OS: ${OSAL_SYSTEM_BSPTYPE} implies ${OSAL_EXPECTED_OSTYPE}, but ${OSAL_SYSTEM_OSTYPE} is configured") endif(NOT DEFINED OSAL_SYSTEM_OSTYPE) -endif (DEFINED OSAL_EXPECTED_OSTYPE) - -# Propagate the BSP-specific compile definitions and include directories -# Apply these to the directory-scope COMPILE_DEFINITIONS and INCLUDE_DIRECTORIES -# Note this needs to append to the directory property, not overwrite it. -get_directory_property(OSAL_BASE_COMPILE_DEFINITIONS COMPILE_DEFINITIONS) -get_target_property(OSAL_BSP_COMPILE_DEFINITIONS osal_${OSAL_SYSTEM_BSPTYPE}_impl INTERFACE_COMPILE_DEFINITIONS) -set(OSAL_COMPILE_DEFINITIONS) -if (OSAL_BASE_COMPILE_DEFINITIONS) - list(APPEND OSAL_COMPILE_DEFINITIONS ${OSAL_BASE_COMPILE_DEFINITIONS}) -endif (OSAL_BASE_COMPILE_DEFINITIONS) -if (OSAL_BSP_COMPILE_DEFINITIONS) - list(APPEND OSAL_COMPILE_DEFINITIONS ${OSAL_BSP_COMPILE_DEFINITIONS}) -endif (OSAL_BSP_COMPILE_DEFINITIONS) -set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "${OSAL_COMPILE_DEFINITIONS}") -message(STATUS "OSAL Compile Definitions: ${OSAL_COMPILE_DEFINITIONS}") - -# The include directories is simpler, as the include_directories() function -# appends to the directory property -get_target_property(OSAL_BSP_INCLUDE_DIRECTORIES osal_${OSAL_SYSTEM_BSPTYPE}_impl INTERFACE_INCLUDE_DIRECTORIES) -if (OSAL_BSP_INCLUDE_DIRECTORIES) - include_directories(${OSAL_BSP_INCLUDE_DIRECTORIES}) -endif (OSAL_BSP_INCLUDE_DIRECTORIES) +endif (OSAL_EXPECTED_OSTYPE) set(BSP_SRCLIST src/bsp/shared/src/osapi-bsp.c @@ -184,8 +249,8 @@ add_library(osal_bsp STATIC $ ) -target_include_directories(osal_bsp INTERFACE - ${OSAL_API_INCLUDE_DIRECTORIES} +target_link_libraries(osal_bsp PUBLIC + osal_public_api ) target_include_directories(osal_bsp PRIVATE @@ -220,6 +285,12 @@ message(STATUS "OSAL Selection: ${OSAL_SYSTEM_OSTYPE} at ${OSAL_OS_SOURCE_DIR}") # an OBJECT target named "osal_${OSAL_SYSTEM_OSTYPE}_impl" add_subdirectory(${OSAL_OS_SOURCE_DIR} ${OSAL_SYSTEM_OSTYPE}_impl) +target_compile_definitions(osal_${OSAL_SYSTEM_OSTYPE}_impl PRIVATE + $ +) +target_compile_options(osal_${OSAL_SYSTEM_OSTYPE}_impl PRIVATE + $ +) # The "shared" directory contains internal components which # are referenced in implementation OSAL modules, but should _NOT_ # be referenced outside the OSAL code @@ -269,33 +340,16 @@ add_library(osal STATIC $ ) -target_include_directories(osal INTERFACE - ${OSAL_API_INCLUDE_DIRECTORIES} -) - target_include_directories(osal PRIVATE ${OSAL_SOURCE_DIR}/src/os/shared/inc ${OSAL_SOURCE_DIR}/src/bsp/shared/inc ) # Link the OSAL with the BSP -target_link_libraries(osal osal_bsp) - -# propagate the BSP-specific compile flags to OSAL external library target, if defined -if (OSAL_BSP_COMPILE_DEFINITIONS) - target_compile_definitions(osal INTERFACE - ${OSAL_BSP_COMPILE_DEFINITIONS} - ) -endif(OSAL_BSP_COMPILE_DEFINITIONS) - -# propagate the BSP-specific include directories OSAL all external library target, if defined -if (OSAL_BSP_INCLUDE_DIRECTORIES) - target_include_directories(osal INTERFACE - ${OSAL_BSP_INCLUDE_DIRECTORIES} - ) -endif(OSAL_BSP_INCLUDE_DIRECTORIES) - - +target_link_libraries(osal PUBLIC + osal_public_api + osal_bsp +) # The "build_options.cmake" file within each component may # fine-tune the library for this particular build. This is included @@ -304,6 +358,12 @@ endif(OSAL_BSP_INCLUDE_DIRECTORIES) include("${OSAL_BSP_SOURCE_DIR}/build_options.cmake" OPTIONAL) include("${OSAL_OS_SOURCE_DIR}/build_options.cmake" OPTIONAL) +# Report the full set of compile definitions after processing all modules +get_target_property(OSAL_PUBLIC_API_COMPILE_DEFINITIONS osal_public_api INTERFACE_COMPILE_DEFINITIONS) +message(STATUS "OSAL Compile Definitions: ${OSAL_PUBLIC_API_COMPILE_DEFINITIONS}") + + + # # UNIT TEST SUPPORT # @@ -317,7 +377,7 @@ if (ENABLE_UNIT_TESTS) function(add_osal_ut_exe TGTNAME) add_executable(${TGTNAME} ${ARGN}) - target_link_libraries(${TGTNAME} ut_assert osal) + target_link_libraries(${TGTNAME} PUBLIC ut_assert osal) add_test(${TGTNAME} ${TGTNAME}) foreach(TGT ${INSTALL_TARGET_LIST}) install(TARGETS ${TGTNAME} DESTINATION ${TGT}/${UT_INSTALL_SUBDIR}) @@ -351,8 +411,10 @@ if (HAS_PARENT) # Export the UT coverage compiler/linker flags to the parent build. # These flags are based on the target system type and should be used # when building code intended for coverage analysis. - set(UT_COVERAGE_COMPILE_FLAGS "${UT_COVERAGE_COMPILE_FLAGS}" PARENT_SCOPE) - set(UT_COVERAGE_LINK_FLAGS "${UT_COVERAGE_LINK_FLAGS}" PARENT_SCOPE) + if (NOT OSAL_OMIT_DEPRECATED) + set(UT_COVERAGE_COMPILE_FLAGS "${UT_COVERAGE_COMPILE_FLAGS}" PARENT_SCOPE) + set(UT_COVERAGE_LINK_FLAGS "${UT_COVERAGE_LINK_FLAGS}" PARENT_SCOPE) + endif() else(HAS_PARENT) # In a standalone build, also add the documentation target(s) # Note that in a CFE/integrated build, it is expected this will be built separately. diff --git a/docs/src/CMakeLists.txt b/docs/src/CMakeLists.txt index fc837ad43..0637529bc 100644 --- a/docs/src/CMakeLists.txt +++ b/docs/src/CMakeLists.txt @@ -49,16 +49,35 @@ foreach(SRC ${OSAL_DOCFILE_LIST}) string(APPEND OSAL_NATIVE_APIGUIDE_SOURCEFILES " \\\n ${SRC}") endforeach() -foreach(DIR ${OSAL_API_INCLUDE_DIRECTORIES}) - file(GLOB OSAL_HEADERFILE_LIST ${DIR}/*.h) - foreach(HDR ${OSAL_HEADERFILE_LIST}) - list(APPEND OSAL_DOC_DEPENDENCY_LIST ${HDR}) - file(TO_NATIVE_PATH "${HDR}" HDR) - string(APPEND OSAL_NATIVE_APIGUIDE_SOURCEFILES " \\\n ${HDR}") - endforeach() - file(TO_NATIVE_PATH "${DIR}" DIR) - string(APPEND OSAL_NATIVE_INCLUDE_DIRS " \\\n ${DIR}") -endforeach() +# The complete list of public API include directories may be determined by reading the property of +# the "osal_public_api" interface target. However, the CFE documentation build may want to influence +# this and provide an alternate path, mainly to provide its own alternate version of "osconfig.h" for +# docs. It should be preferred to pull this info from the actual source such that it will track any +# changes made within OSAL as far as header organization goes. +if (TARGET osal_public_api AND NOT OSAL_API_INCLUDE_DIRECTORIES) + get_target_property(OSAL_API_INCLUDE_DIRECTORIES osal_public_api INTERFACE_INCLUDE_DIRECTORIES) + if (NOT OSAL_API_INCLUDE_DIRECTORIES) + set (OSAL_API_INCLUDE_DIRECTORIES) + endif() + get_target_property(OSAL_API_COMPILE_DEFINITIONS osal_public_api INTERFACE_COMPILE_DEFINITIONS) + if (NOT OSAL_API_COMPILE_DEFINITIONS) + set (OSAL_API_COMPILE_DEFINITIONS) + endif() +endif () + +# Generate the list of actual header files from the directories specified. This is done +# as a target that runs a separate script such that generator expressions can be evaluated. +# This is done as a custom target such that it runs and gets updated every build +add_custom_target(osal_public_api_headerlist + COMMAND ${CMAKE_COMMAND} + -DINCLUDE_DIRECTORIES="${OSAL_API_INCLUDE_DIRECTORIES}" + -DCOMPILE_DEFINITIONS="${OSAL_API_COMPILE_DEFINITIONS}" + -DINPUT_TEMPLATE="${CMAKE_CURRENT_SOURCE_DIR}/osal-public-api.doxyfile.in" + -DOUTPUT_FILE="${CMAKE_BINARY_DIR}/docs/osal-public-api.doxyfile" + -P "${CMAKE_CURRENT_SOURCE_DIR}/generate-public-api-doxyfile.cmake" + BYPRODUCTS "${CMAKE_BINARY_DIR}/docs/osal-public-api.doxyfile" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" +) file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/osal-apiguide-warnings.log OSAL_NATIVE_LOGFILE) file(TO_NATIVE_PATH ${CMAKE_BINARY_DIR}/docs/osal-common.doxyfile OSAL_NATIVE_COMMON_CFGFILE) @@ -85,7 +104,9 @@ configure_file( add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/html/index.html" COMMAND doxygen ${OSAL_NATIVE_APIGUIDE_CFGFILE} - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/osal-apiguide.doxyfile ${CMAKE_BINARY_DIR}/docs/osal-common.doxyfile + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/osal-apiguide.doxyfile" + "${CMAKE_BINARY_DIR}/docs/osal-common.doxyfile" + "${CMAKE_BINARY_DIR}/docs/osal-public-api.doxyfile" ${OSAL_DOCFILE_LIST} ${OSAL_DOC_DEPENDENCY_LIST} WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" ) diff --git a/docs/src/generate-public-api-doxyfile.cmake b/docs/src/generate-public-api-doxyfile.cmake new file mode 100644 index 000000000..1a5797966 --- /dev/null +++ b/docs/src/generate-public-api-doxyfile.cmake @@ -0,0 +1,39 @@ +################################################################# +# +# CMake helper script to generate list of header for API guide +# +################################################################# + +# This helper script is needed to evaluate the "INTERFACE_INCLUDE_DIRECTORIES" and +# "INTERFACE_COMPILE_DEFINITIONS" properties on the osal_public_api target properly. +# Note that either of these property values may contain generator expressions, and +# thus can only be correctly evaluated in the context of a target command, hence the +# need for this helper script. +# +# The property values are passed in via the command line, and this converts it into +# a doxygen snippet containing of header files and predefined macro values. + +message(STATUS "Generating OSAL API documentation input list") +set(OSAL_HEADERFILE_LIST) +set(OSALDOC_PREDEFINED) +separate_arguments(INCLUDE_DIRECTORIES) +separate_arguments(COMPILE_DEFINITIONS) +foreach(INPUT ${INCLUDE_DIRECTORIES}) + if (IS_DIRECTORY ${INPUT}) + message(STATUS "OSAL API: Scanning directory ${INPUT}") + file(GLOB INPUT "${INPUT}/*.h") + endif() + list(APPEND OSAL_HEADERFILE_LIST ${INPUT}) +endforeach() + +foreach(HDR ${OSAL_HEADERFILE_LIST}) + list(APPEND OSAL_DOC_DEPENDENCY_LIST ${HDR}) + file(TO_NATIVE_PATH "${HDR}" HDR) + string(APPEND OSAL_NATIVE_APIGUIDE_SOURCEFILES " \\\n ${HDR}") +endforeach() + +foreach(INPUT ${COMPILE_DEFINITIONS}) + string(APPEND OSALDOC_PREDEFINED " \\\n ${INPUT}") +endforeach() + +configure_file(${INPUT_TEMPLATE} ${OUTPUT_FILE} @ONLY) diff --git a/docs/src/osal-common.doxyfile.in b/docs/src/osal-common.doxyfile.in index ce327fb37..83ee529e2 100644 --- a/docs/src/osal-common.doxyfile.in +++ b/docs/src/osal-common.doxyfile.in @@ -8,11 +8,11 @@ # Default settings @INCLUDE = @OSAL_NATIVE_DEFAULT_SETTINGS@ -# Include any passed in predefines -PREDEFINED += @OSALDOC_PREDEFINED@ - # Minimum set of source files (includes *.dox, followed by public headers) INPUT += @OSAL_NATIVE_APIGUIDE_SOURCEFILES@ +# Public header list is generated from the interface includes of the osal_public_api target +@INCLUDE = @CMAKE_BINARY_DIR@/docs/osal-public-api.doxyfile + # Strip source dir from path STRIP_FROM_PATH += @MISSION_SOURCE_DIR@ diff --git a/docs/src/osal-public-api.doxyfile.in b/docs/src/osal-public-api.doxyfile.in new file mode 100644 index 000000000..19d19b88c --- /dev/null +++ b/docs/src/osal-public-api.doxyfile.in @@ -0,0 +1,9 @@ +#--------------------------------------------------------------------------- +# OSAL API Documentation Input List (generated from build system) +#--------------------------------------------------------------------------- + +# List of compile definitions from osal_public_api +PREDEFINED += @OSALDOC_PREDEFINED@ + +# List of header files from osal_public_api +INPUT += @OSAL_NATIVE_APIGUIDE_SOURCEFILES@ diff --git a/src/bsp/generic-linux/CMakeLists.txt b/src/bsp/generic-linux/CMakeLists.txt index 180e73840..deaef00f6 100644 --- a/src/bsp/generic-linux/CMakeLists.txt +++ b/src/bsp/generic-linux/CMakeLists.txt @@ -21,11 +21,26 @@ add_library(osal_generic-linux_impl OBJECT # # See http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html # for a more detailed description of the feature test macros and available values -target_compile_definitions(osal_generic-linux_impl PUBLIC +target_compile_definitions(osal_public_api INTERFACE _XOPEN_SOURCE=600 ) +# Linux system libraries required for the final link of applications using OSAL +target_link_libraries(osal_public_api INTERFACE + pthread dl rt +) # This BSP only works with "posix" OS layer. # Confirming this reduces risk of accidental misconfiguration -set(OSAL_EXPECTED_OSTYPE "posix" PARENT_SCOPE) +set_property(TARGET osal_generic-linux_impl PROPERTY OSAL_EXPECTED_OSTYPE "posix") + +# Configure the ut_coverage_compile and ut_coverage_link for enabling coverage +# testing on this platform. +if (NOT CMAKE_CROSSCOMPILING AND ENABLE_UNIT_TESTS) + # Support for other compilers/coverage tools could be added here. + # for now only the GNU "gcov" will be enabled + if (CMAKE_C_COMPILER_ID STREQUAL GNU) + target_compile_options(ut_coverage_compile INTERFACE -pg -ftest-coverage -fprofile-arcs) + target_link_libraries(ut_coverage_link INTERFACE gcov) + endif() +endif() diff --git a/src/bsp/generic-linux/build_options.cmake b/src/bsp/generic-linux/build_options.cmake index dcffd5a57..dd37ffb7a 100644 --- a/src/bsp/generic-linux/build_options.cmake +++ b/src/bsp/generic-linux/build_options.cmake @@ -4,20 +4,15 @@ # ########################################################################## - - -# Linux system libraries required for the final link of applications using OSAL -target_link_libraries(osal_bsp - pthread dl rt -) - # C flags that should be used when (re-) compiling code for unit testing. # Note: --coverage is just a shortcut for "-ftest-coverage" and "-fprofile-arcs" # This also does not work well when cross compiling since paths to the _compile_ dir # are baked into the executables, so they will not be there when copied to the target # Note - although GCC understands the same flags for compile and link here, this may # not be true on all platforms so the compile and link flags are specified separately. -if (NOT CMAKE_CROSSCOMPILING) +if (NOT CMAKE_CROSSCOMPILING AND NOT OSAL_OMIT_DEPRECATED) + # The variables here (UT_COVERAGE_COMPILE_FLAGS/LINK_FLAGS) should be phased out, prefer + # to use the interface libraries (ut_coverage_compile/link) instead, which are more flexible. set(UT_COVERAGE_COMPILE_FLAGS -pg --coverage) set(UT_COVERAGE_LINK_FLAGS -pg --coverage) endif() diff --git a/src/bsp/generic-vxworks/CMakeLists.txt b/src/bsp/generic-vxworks/CMakeLists.txt index 8e638b930..257b426bb 100644 --- a/src/bsp/generic-vxworks/CMakeLists.txt +++ b/src/bsp/generic-vxworks/CMakeLists.txt @@ -9,6 +9,9 @@ add_library(osal_generic-vxworks_impl OBJECT src/bsp_console.c ) +# The "-u" switch is required to ensure that the linker pulls in the OS_BSPMain entry point +target_link_libraries(osal_public_api INTERFACE -uOS_BSPMain) + # This BSP only works with "vxworks" OS layer. # Confirming this reduces risk of accidental misconfiguration -set(OSAL_EXPECTED_OSTYPE "vxworks" PARENT_SCOPE) +set_property(TARGET osal_generic-vxworks_impl PROPERTY OSAL_EXPECTED_OSTYPE "vxworks") diff --git a/src/bsp/generic-vxworks/build_options.cmake b/src/bsp/generic-vxworks/build_options.cmake deleted file mode 100644 index 5ba936aba..000000000 --- a/src/bsp/generic-vxworks/build_options.cmake +++ /dev/null @@ -1,8 +0,0 @@ -########################################################################## -# -# Build options for "generic-vxworks" BSP -# -########################################################################## - -# The "-u" switch is required to ensure that the linker pulls in the OS_BSPMain entry point -target_link_libraries(osal_bsp -uOS_BSPMain) diff --git a/src/bsp/pc-rtems/CMakeLists.txt b/src/bsp/pc-rtems/CMakeLists.txt index c6f6a1b29..83c74461e 100644 --- a/src/bsp/pc-rtems/CMakeLists.txt +++ b/src/bsp/pc-rtems/CMakeLists.txt @@ -12,10 +12,13 @@ add_library(osal_pc-rtems_impl OBJECT # This definition is needed for the gethostname call # By defining this, it avoids the need to use the -std=gnu99 # instead of the preferred -std=c99 GCC switch -target_compile_definitions(osal_pc-rtems_impl PUBLIC +target_compile_definitions(osal_public_api INTERFACE _BSD_SOURCE ) -# This BSP only works with "rtems" OS layer. -# Confirming this reduces risk of accidental misconfiguration -set(OSAL_EXPECTED_OSTYPE "rtems" PARENT_SCOPE) +# Link the RTEMS BSP with the "rtemscpu" system library +target_link_libraries(osal_public_api INTERFACE + rtemscpu +) + +set_property(TARGET osal_pc-rtems_impl PROPERTY OSAL_EXPECTED_OSTYPE "rtems") diff --git a/src/bsp/pc-rtems/build_options.cmake b/src/bsp/pc-rtems/build_options.cmake deleted file mode 100644 index 909fe8b7e..000000000 --- a/src/bsp/pc-rtems/build_options.cmake +++ /dev/null @@ -1,17 +0,0 @@ -########################################################################## -# -# Build options for "pc-rtems" BSP -# -########################################################################## - -# Link the RTEMS BSP with the "rtemscpu" system library -target_link_libraries(osal_bsp - rtemscpu -) - -# Add the networking library for RTEMS 6+ -if(CMAKE_SYSTEM_VERSION GREATER 5) - target_link_libraries(osal_bsp - networking - ) -endif(CMAKE_SYSTEM_VERSION GREATER 5) diff --git a/src/os/posix/CMakeLists.txt b/src/os/posix/CMakeLists.txt index e3c92c270..9b7c1e3e5 100644 --- a/src/os/posix/CMakeLists.txt +++ b/src/os/posix/CMakeLists.txt @@ -5,7 +5,6 @@ ###################################################################### # This CMake script generates targets specific to the POSIX implementation -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) # The basic set of files which are always built set(POSIX_BASE_SRCLIST @@ -80,3 +79,10 @@ add_library(osal_posix_impl OBJECT ${POSIX_BASE_SRCLIST} ${POSIX_IMPL_SRCLIST} ) + +target_include_directories(osal_posix_impl PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/inc +) +target_compile_definitions(osal_public_api INTERFACE + _POSIX_OS_ +) diff --git a/src/os/posix/build_options.cmake b/src/os/posix/build_options.cmake deleted file mode 100644 index 15f3ad03e..000000000 --- a/src/os/posix/build_options.cmake +++ /dev/null @@ -1,8 +0,0 @@ -########################################################################## -# -# Build options for "posix" implementation layer -# -########################################################################## - -# this file is a placeholder for POSIX-specific compile tuning -add_definitions(-D_POSIX_OS_) diff --git a/src/os/rtems/CMakeLists.txt b/src/os/rtems/CMakeLists.txt index a1eeec855..ad624cf2a 100644 --- a/src/os/rtems/CMakeLists.txt +++ b/src/os/rtems/CMakeLists.txt @@ -5,7 +5,6 @@ ###################################################################### # This CMake script generates targets specific to the RTEMS implementation -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) # The basic set of files which are always built set(RTEMS_BASE_SRCLIST @@ -63,6 +62,15 @@ if (OSAL_CONFIG_INCLUDE_NETWORK) ../portable/os-impl-bsd-sockets.c ../portable/os-impl-bsd-select.c ) + + # In RTEMS 6+ the networking subsystem is not included with the defualt libs, + # it needs to be explicitly added to the final link. Note the "VERSION_GREATER_EQUAL" + # operation was not added until CMake 3.7, so this uses not "VERSION_LESS" instead. + if(NOT CMAKE_SYSTEM_VERSION VERSION_LESS 6.0) + target_link_libraries(osal_public_api INTERFACE + networking + ) + endif() else() list(APPEND RTEMS_IMPL_SRCLIST ../portable/os-impl-no-network.c @@ -76,3 +84,10 @@ add_library(osal_rtems_impl OBJECT ${RTEMS_BASE_SRCLIST} ${RTEMS_IMPL_SRCLIST} ) + +target_include_directories(osal_rtems_impl PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/inc +) +target_compile_definitions(osal_public_api INTERFACE + _RTEMS_OS_ +) diff --git a/src/os/rtems/build_options.cmake b/src/os/rtems/build_options.cmake deleted file mode 100644 index 0a457e1e9..000000000 --- a/src/os/rtems/build_options.cmake +++ /dev/null @@ -1,8 +0,0 @@ -########################################################################## -# -# Build options for "rtems" implementation layer -# -########################################################################## - -# this file is a placeholder for RTEMS-specific compile tuning -add_definitions(-D_RTEMS_OS_) diff --git a/src/os/vxworks/CMakeLists.txt b/src/os/vxworks/CMakeLists.txt index d6d8d3515..5bcc7f4d3 100644 --- a/src/os/vxworks/CMakeLists.txt +++ b/src/os/vxworks/CMakeLists.txt @@ -5,7 +5,6 @@ ###################################################################### # This CMake script generates targets specific to the VxWorks implementation -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) # The basic set of files which are always built set(VXWORKS_BASE_SRCLIST @@ -81,7 +80,16 @@ add_library(osal_vxworks_impl OBJECT ${VXWORKS_IMPL_SRCLIST} ) +target_include_directories(osal_vxworks_impl PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/inc +) + if (CMAKE_SYSTEM_VERSION VERSION_LESS 7.0) - target_compile_definitions(osal_vxworks_impl PRIVATE OSAL_VXWORKS6_COMPATIBILITY) + target_compile_definitions(osal_vxworks_impl PRIVATE + OSAL_VXWORKS6_COMPATIBILITY + ) endif () +target_compile_definitions(osal_public_api INTERFACE + _VXWORKS_OS_ +) diff --git a/src/os/vxworks/build_options.cmake b/src/os/vxworks/build_options.cmake deleted file mode 100644 index c3e9553a0..000000000 --- a/src/os/vxworks/build_options.cmake +++ /dev/null @@ -1,8 +0,0 @@ -########################################################################## -# -# Build options for "vxworks" implementation layer -# -########################################################################## - -# this file is a placeholder for VxWorks-specific compile tuning -add_definitions(-D_VXWORKS_OS_) diff --git a/src/unit-test-coverage/CMakeLists.txt b/src/unit-test-coverage/CMakeLists.txt index 6ec040168..34be9e245 100644 --- a/src/unit-test-coverage/CMakeLists.txt +++ b/src/unit-test-coverage/CMakeLists.txt @@ -40,11 +40,9 @@ endforeach(OSTYPE ${OSALCOVERAGE_TARGET_OSTYPE}) message(STATUS "Coverage Test Target OS: ${OSALCOVERAGE_TARGET_OSTYPE}") -# Utilize the shared UT assert library, along with the standard OSAL includes -include_directories(${UT_ASSERT_SOURCE_DIR}/inc) -include_directories(${OSAL_SOURCE_DIR}/src/os/inc) +# This unit test is allowed to directly include any internal file in +# the respective set under test. include_directories(${OSAL_SOURCE_DIR}/src/os/shared/inc) -include_directories(${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/inc) add_subdirectory(ut-stubs) @@ -58,14 +56,18 @@ function (add_coverage_testrunner TESTNAME FSW_SRCFILE TESTCASE_SRCFILE) ${FSW_SRCFILE} ) - # only the actual FSW src file gets the coverage instrumentation - target_compile_options(utobj_${TESTNAME} PRIVATE - ${UT_COVERAGE_COMPILE_FLAGS} - ) - # both the FSW src file and the adaptor file get compiled with override includes target_include_directories(utobj_${TESTNAME} BEFORE PRIVATE ${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc + $ + ) + + target_compile_options(utobj_${TESTNAME} PRIVATE + $ + ) + + target_compile_definitions(utobj_${TESTNAME} PRIVATE + $ ) # the testcase is compiled with no special flags or override includes @@ -74,9 +76,10 @@ function (add_coverage_testrunner TESTNAME FSW_SRCFILE TESTCASE_SRCFILE) $ ) - target_link_libraries(${TESTNAME}-testrunner - ${UT_COVERAGE_LINK_FLAGS} + target_link_libraries(${TESTNAME}-testrunner PUBLIC ${ARGN} + osal_public_api + ut_coverage_link ut_assert ) @@ -92,4 +95,3 @@ endfunction() foreach(SETNAME ${OSALCOVERAGE_TARGET_OSTYPE}) add_subdirectory(${SETNAME}) endforeach(SETNAME ${OSALCOVERAGE_TARGET_OSTYPE}) - diff --git a/src/unit-test-coverage/shared/CMakeLists.txt b/src/unit-test-coverage/shared/CMakeLists.txt index 8b41672a7..2b3b98eb4 100644 --- a/src/unit-test-coverage/shared/CMakeLists.txt +++ b/src/unit-test-coverage/shared/CMakeLists.txt @@ -42,6 +42,10 @@ add_library(os-shared-coverage-support STATIC src/os-shared-coverage-support.c ) +target_link_libraries(os-shared-coverage-support PUBLIC + ut_osapi_stub_headers +) + add_subdirectory(adaptors) diff --git a/src/unit-test-coverage/shared/adaptors/CMakeLists.txt b/src/unit-test-coverage/shared/adaptors/CMakeLists.txt index 19a620d04..3da5f88b2 100644 --- a/src/unit-test-coverage/shared/adaptors/CMakeLists.txt +++ b/src/unit-test-coverage/shared/adaptors/CMakeLists.txt @@ -19,3 +19,7 @@ target_include_directories(ut-adaptor-${SETNAME} BEFORE PRIVATE target_include_directories(ut-adaptor-${SETNAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc ) + +target_link_libraries(ut-adaptor-${SETNAME} PUBLIC + ut_osapi_stub_headers +) diff --git a/src/unit-test-coverage/ut-stubs/CMakeLists.txt b/src/unit-test-coverage/ut-stubs/CMakeLists.txt index 866ff89e3..b970cf8a2 100644 --- a/src/unit-test-coverage/ut-stubs/CMakeLists.txt +++ b/src/unit-test-coverage/ut-stubs/CMakeLists.txt @@ -17,6 +17,14 @@ # any coverage test referencing on the shared/ng OSAL layer. # +add_library(ut_osapi_stub_headers INTERFACE) +target_include_directories(ut_osapi_stub_headers INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/inc +) +target_link_libraries(ut_osapi_stub_headers INTERFACE + ut_assert +) + # The "ut_libc_stubs" target provides stub versions of C library calls. # They are prefixed with "OCS_" and target code must be recompiled to # call the OCS_ version of the syscall instead of the regular syscall. @@ -73,10 +81,11 @@ add_library(ut_libc_stubs STATIC EXCLUDE_FROM_ALL src/vxworks-sysLib-stubs.c src/vxworks-taskLib-stubs.c src/vxworks-taskVarLib-stubs.c - src/vxworks-xbdBlkDev-stubs.c) + src/vxworks-xbdBlkDev-stubs.c +) -target_include_directories(ut_libc_stubs PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/inc +target_link_libraries(ut_libc_stubs PUBLIC + ut_osapi_stub_headers ) # About the generated UT stub sources @@ -181,6 +190,10 @@ add_library(ut_osapi_impl_stubs STATIC EXCLUDE_FROM_ALL src/os-shared-timebase-impl-stubs.c ) +target_link_libraries(ut_osapi_impl_stubs PUBLIC + ut_osapi_stub_headers +) + # The "ut_osapi_init_stubs" provides stub functions for the # initialization function calls that are declared under os/shared/inc # header directory. These are the functions that all end in an "_Init" suffix, @@ -203,6 +216,10 @@ add_library(ut_osapi_init_stubs STATIC EXCLUDE_FROM_ALL src/os-shared-time-init-stubs.c ) +target_link_libraries(ut_osapi_init_stubs PUBLIC + ut_osapi_stub_headers +) + # The "ut_osapi_shared_stubs" provides stub functions for the # all other function calls that are declared under os/shared/inc # header directory. These are the non-public functions that do @@ -222,6 +239,9 @@ add_library(ut_osapi_shared_stubs STATIC EXCLUDE_FROM_ALL src/os-shared-timebase-stubs.c ) +target_link_libraries(ut_osapi_shared_stubs PUBLIC + ut_osapi_stub_headers +) # The "ut_osapi_table_stubs" provides stub objects for shared # table objects used by the implementation layer. These @@ -244,6 +264,15 @@ add_library(ut_osapi_table_stubs STATIC EXCLUDE_FROM_ALL src/osapi-shared-timecb-table-stubs.c ) +target_link_libraries(ut_osapi_table_stubs PUBLIC + ut_osapi_stub_headers +) + add_library(ut_bsp_impl_stubs STATIC EXCLUDE_FROM_ALL src/bsp-console-impl-stubs.c ) + +target_link_libraries(ut_bsp_impl_stubs PUBLIC + ut_osapi_stub_headers +) + diff --git a/src/unit-test-coverage/vxworks/adaptors/CMakeLists.txt b/src/unit-test-coverage/vxworks/adaptors/CMakeLists.txt index b0789bdb6..9c1e6bc5f 100644 --- a/src/unit-test-coverage/vxworks/adaptors/CMakeLists.txt +++ b/src/unit-test-coverage/vxworks/adaptors/CMakeLists.txt @@ -39,3 +39,7 @@ target_include_directories(ut-adaptor-${SETNAME} PUBLIC ${OSALCOVERAGE_SOURCE_DIR}/portable/adaptors/inc ${CMAKE_CURRENT_SOURCE_DIR}/inc ) + +target_link_libraries(ut-adaptor-${SETNAME} PUBLIC + ut_osapi_stub_headers +) diff --git a/src/unit-test-coverage/vxworks/ut-stubs/CMakeLists.txt b/src/unit-test-coverage/vxworks/ut-stubs/CMakeLists.txt index c24c1d8e5..5d09cd107 100644 --- a/src/unit-test-coverage/vxworks/ut-stubs/CMakeLists.txt +++ b/src/unit-test-coverage/vxworks/ut-stubs/CMakeLists.txt @@ -12,3 +12,7 @@ add_library(ut_vxworks_impl_stubs src/vxworks-os-impl-task-stubs.c src/vxworks-os-impl-timer-stubs.c ) + +target_link_libraries(ut_vxworks_impl_stubs PUBLIC + ut_osapi_stub_headers +) diff --git a/src/unit-tests/CMakeLists.txt b/src/unit-tests/CMakeLists.txt index 6cd0f641d..813c94a68 100644 --- a/src/unit-tests/CMakeLists.txt +++ b/src/unit-tests/CMakeLists.txt @@ -1,19 +1,12 @@ # CMake snippet for OSAL unit tests # -# NOTE: -# This set of unit tests only includes platform support where -# one of OSP_ARINC653, _LINUX_OS_ or _VXWORKS_OS_ are defined. -# -# It does not include support for other options like _RTEMS_OS_ -# These test do not currently use the same UT assert framework -# that the other tests use. If/when these tests migrate to using the -# same framework then this style of platform support via macros is -# not necessary and other OS's like RTEMS should work. +# This is a set of functional tests for certain OSAL subsystems, +# focused on API responses and implemented as black-box tests (i.e. +# linked to normal OSAL, only using public API). # enable_testing() -include_directories(${UTASSERT_SOURCE_DIR}/inc) include_directories(inc) add_subdirectory(oscore-test) @@ -22,4 +15,3 @@ add_subdirectory(osfilesys-test) add_subdirectory(osfile-test) add_subdirectory(osnetwork-test) add_subdirectory(ostimer-test) - diff --git a/src/ut-stubs/CMakeLists.txt b/src/ut-stubs/CMakeLists.txt index dda556c09..fdd8ab61d 100644 --- a/src/ut-stubs/CMakeLists.txt +++ b/src/ut-stubs/CMakeLists.txt @@ -99,12 +99,10 @@ add_library(ut_osapi_stubs STATIC osapi-version-handlers.c ) -# Some of the internal API definitions in stubs are based on -# types/definitions in the shared layer internal header file. -target_include_directories(ut_osapi_stubs PRIVATE - ${OSAL_SOURCE_DIR}/src/os/shared/inc -) - # These stubs must always link to UT Assert. # This also implicitly adds the path to the UT Assert header files. -target_link_libraries(ut_osapi_stubs ut_assert) +target_link_libraries(ut_osapi_stubs PUBLIC + osal_public_api + ut_assert +) + diff --git a/src/ut-stubs/osapi-idmap-handlers.c b/src/ut-stubs/osapi-idmap-handlers.c index 3c733bdaf..70e0eaa50 100644 --- a/src/ut-stubs/osapi-idmap-handlers.c +++ b/src/ut-stubs/osapi-idmap-handlers.c @@ -35,7 +35,6 @@ #include "osapi-idmap.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" -#include "os-shared-idmap.h" /* * ----------------------------------------------------------------- diff --git a/ut_assert/CMakeLists.txt b/ut_assert/CMakeLists.txt index 5570be30a..e834aa0e7 100644 --- a/ut_assert/CMakeLists.txt +++ b/ut_assert/CMakeLists.txt @@ -9,6 +9,14 @@ # project(UT_ASSERT C) +set(UT_ASSERT_SOURCE_LIST + src/utassert.c + src/utlist.c + src/utstubs.c + src/uttest.c + src/uttools.c +) + # The "ut_assert" library is usable by ANY and ALL subsystem(s) that need # to do unit testing of any kind. This library implements an OSAL application # that contains APIs to aid in unit testing. It provides the OS_Application_Startup @@ -21,25 +29,25 @@ project(UT_ASSERT C) # of stubs vs. real implementations are specific to the unit being tested. All # stub functions are compiled as separate libraries. -add_library(ut_assert STATIC EXCLUDE_FROM_ALL - src/utassert.c +add_library(ut_assert STATIC + ${UT_ASSERT_SOURCE_LIST} src/utbsp.c - src/utlist.c - src/utstubs.c - src/uttest.c - src/uttools.c ) -target_include_directories(ut_assert PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/inc" -) target_include_directories(ut_assert PRIVATE - "${OSAL_SOURCE_DIR}/src/bsp/shared/inc" + ${OSAL_SOURCE_DIR}/src/bsp/shared/inc +) + +target_include_directories(ut_assert PUBLIC + $ + $ ) target_compile_definitions(ut_assert PUBLIC "_UNIT_TEST_" ) -target_link_libraries(ut_assert osal_bsp) +target_link_libraries(ut_assert PUBLIC + osal_bsp +) # The "pic" variant of ut_assert is compiled as an @@ -48,19 +56,30 @@ target_link_libraries(ut_assert osal_bsp) # It is compiled as position independent code (PIC) # to support dynamic loading. add_library(ut_assert_pic OBJECT EXCLUDE_FROM_ALL - src/utassert.c - src/utlist.c - src/utstubs.c - src/uttest.c - src/uttools.c + ${UT_ASSERT_SOURCE_LIST} ) - set_target_properties(ut_assert_pic PROPERTIES POSITION_INDEPENDENT_CODE TRUE ) - target_include_directories(ut_assert_pic PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/inc" + $ + $ ) +target_compile_definitions(ut_assert_pic PUBLIC + $ +) + +# The "ut_coverage_compile" is an interface target that contains the +# compiler options/definitions to enable coverage instrumentation in the +# generated objects. It should be specified on files compiled for coverage +# analysis. +add_library(ut_coverage_compile INTERFACE) +target_link_libraries(ut_coverage_compile INTERFACE ut_assert) + +# The "ut_coverage_link" is an interface target that contains options/definitions +# and any link libraries to enable coverage instrumentation in the final executable. +# It should be specified on coverage test executable targets. +add_library(ut_coverage_link INTERFACE) +target_link_libraries(ut_coverage_link INTERFACE ut_assert)