lestarch: refactoring toolchains to properly set and use CMAKE_SYSTEM_NAME (#686)

This commit is contained in:
M Starch 2021-06-08 20:20:25 -07:00 committed by GitHub
parent eebef10711
commit 61eb8195cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 68 additions and 124 deletions

View File

@ -11,14 +11,16 @@ if(NOT DEFINED FPRIME_USE_STUBBED_DRIVERS OR FPRIME_USE_STUBBED_DRIVERS)
"${CMAKE_CURRENT_LIST_DIR}/LinuxGpioDriverComponentImplCommon.cpp"
"${CMAKE_CURRENT_LIST_DIR}/LinuxGpioDriverComponentImplStub.cpp"
)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "arm-linux-gnueabihf")
register_fprime_module()
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/LinuxGpioDriverComponentAi.xml"
"${CMAKE_CURRENT_LIST_DIR}/LinuxGpioDriverComponentImplCommon.cpp"
"${CMAKE_CURRENT_LIST_DIR}/LinuxGpioDriverComponentImpl.cpp"
)
register_fprime_module()
else()
message(FATAL_ERROR "Cannot use ${CMAKE_CURRENT_LIST_DIR} with platform ${CMAKE_SYSTEM_NAME}. Consider using -DFPRIME_USE_STUBBED_DRIVERS=ON")
message(STATUS "Cannot use ${CMAKE_CURRENT_LIST_DIR} with platform ${CMAKE_SYSTEM_NAME}. Skipping.")
endif()
register_fprime_module()

View File

@ -11,13 +11,15 @@ if(NOT DEFINED FPRIME_USE_STUBBED_DRIVERS OR FPRIME_USE_STUBBED_DRIVERS)
"${CMAKE_CURRENT_LIST_DIR}/LinuxI2cDriverComponentAi.xml"
"${CMAKE_CURRENT_LIST_DIR}/LinuxI2cDriverComponentImplStub.cpp"
)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "arm-linux-gnueabihf")
register_fprime_module()
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/LinuxI2cDriverComponentAi.xml"
"${CMAKE_CURRENT_LIST_DIR}/LinuxI2cDriverComponentImpl.cpp"
)
register_fprime_module()
else()
message(FATAL_ERROR "Cannot use ${CMAKE_CURRENT_LIST_DIR} with platform ${CMAKE_SYSTEM_NAME}. Consider using -DFPRIME_USE_STUBBED_DRIVERS=ON")
message(STATUS "Cannot use ${CMAKE_CURRENT_LIST_DIR} with platform ${CMAKE_SYSTEM_NAME}. Skipping.")
endif()
register_fprime_module()

View File

@ -5,22 +5,19 @@
# MOD_DEPS: (optional) module dependencies
#
####
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "arm-linux-gnueabihf" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(MOD_DEPS Os)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/LinuxSerialDriverComponentAi.xml"
"${CMAKE_CURRENT_LIST_DIR}/LinuxSerialDriverComponentImplCommon.cpp"
"${CMAKE_CURRENT_LIST_DIR}/LinuxSerialDriverComponentImpl.cpp"
)
register_fprime_module()
else()
message(FATAL_ERROR "Cannot use ${CMAKE_CURRENT_LIST_DIR} with platform ${CMAKE_SYSTEM_NAME}.")
message(STATUS "Cannot use ${CMAKE_CURRENT_LIST_DIR} with platform ${CMAKE_SYSTEM_NAME}. Skipping.")
endif()
set(MOD_DEPS
Os
)
register_fprime_module()
### UTs ###
# Note: this UT expects user input
#set(UT_MOD_DEPS

View File

@ -11,14 +11,15 @@ if(NOT DEFINED FPRIME_USE_STUBBED_DRIVERS OR FPRIME_USE_STUBBED_DRIVERS)
"${CMAKE_CURRENT_LIST_DIR}/LinuxSpiDriverComponentImplCommon.cpp"
"${CMAKE_CURRENT_LIST_DIR}/LinuxSpiDriverComponentImplStub.cpp"
)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "arm-linux-gnueabihf")
register_fprime_module()
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/LinuxSpiDriverComponentAi.xml"
"${CMAKE_CURRENT_LIST_DIR}/LinuxSpiDriverComponentImplCommon.cpp"
"${CMAKE_CURRENT_LIST_DIR}/LinuxSpiDriverComponentImpl.cpp"
)
register_fprime_module()
else()
message(FATAL_ERROR "Cannot use ${CMAKE_CURRENT_LIST_DIR} with platform ${CMAKE_SYSTEM_NAME}. Consider using -DFPRIME_USE_STUBBED_DRIVERS=ON")
message(STATUS "Cannot use ${CMAKE_CURRENT_LIST_DIR} with platform ${CMAKE_SYSTEM_NAME}. Skipping.")
endif()
register_fprime_module()

View File

@ -59,7 +59,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
"${CMAKE_CURRENT_LIST_DIR}/MacOs/IPCQueueStub.cpp"
)
# Linux IPC queues implementation
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "arm-linux-gnueabihf")
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
list(APPEND SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/Posix/IPCQueue.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Posix/LocklessQueue.cpp"

View File

@ -19,18 +19,6 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
"${CMAKE_CURRENT_LIST_DIR}/LinuxTimerComponentImplTimerFd.cpp"
"${CMAKE_CURRENT_LIST_DIR}/LinuxTimerComponentImplCommon.cpp"
)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "CygWin")
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/LinuxTimerComponentAi.xml"
"${CMAKE_CURRENT_LIST_DIR}/LinuxTimerComponentImplTaskDelay.cpp"
"${CMAKE_CURRENT_LIST_DIR}/LinuxTimerComponentImplCommon.cpp"
)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "arm-linux-gnueabihf")
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/LinuxTimerComponentAi.xml"
"${CMAKE_CURRENT_LIST_DIR}/LinuxTimerComponentImplTimerFd.cpp"
"${CMAKE_CURRENT_LIST_DIR}/LinuxTimerComponentImplCommon.cpp"
)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "RTEMS5")
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/LinuxTimerComponentAi.xml"

View File

@ -154,16 +154,6 @@ endif()
# e.g. `-DCMAKE_TOOLCHAIN_FILE=/path/to/cmake/toolchain`
####
####
# `PLATFORM:`
#
# Specifies the platform used when building the F prime using the CMake system. See:
# [platform.md](platform.md) for more information. Default: automatically detect platform file.
#
# e.g. `-DPLATFORM=/path/to/platform/cmake`
####
####
# Locations `FPRIME_FRAMEWORK_PATH`, `FPRIME_PROJECT_ROOT`, `FPRIME_LIBRARY_LOCATIONS`
# `FPRIME_AC_CONSTANTS_FILE`, and `FPRIME_CONFIG_DIR`:

View File

@ -7,7 +7,7 @@ ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG a3460d1
SOURCE_DIR "${FPRIME_FRAMEWORK_PATH}/gtest/googletest-src"
BINARY_DIR "${FPRIME_FRAMEWORK_PATH}/gtest/googletest-build-${PLATFORM}"
BINARY_DIR "${FPRIME_FRAMEWORK_PATH}/gtest/googletest-build-${TOOLCHAIN_NAME}"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""

View File

@ -1,5 +1,5 @@
# Download and unpack googletest at configure time if it doesn't exit already
if (NOT IS_DIRECTORY "${FPRIME_FRAMEWORK_PATH}/gtest/googletest-build-${PLATFORM}/googletest")
if (NOT IS_DIRECTORY "${FPRIME_FRAMEWORK_PATH}/gtest/googletest-build-${TOOLCHAIN_NAME}/googletest")
configure_file("${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt.in" googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
@ -21,7 +21,7 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${FPRIME_FRAMEWORK_PATH}/gtest/googletest-src
${FPRIME_FRAMEWORK_PATH}/gtest/googletest-build-${PLATFORM}
${FPRIME_FRAMEWORK_PATH}/gtest/googletest-build-${TOOLCHAIN_NAME}
EXCLUDE_FROM_ALL)
# The gtest/gtest_main targets carry header search path

View File

@ -1,34 +1,38 @@
####
# platforms:
#
# Platforms in F prime's CMake system setup f prime specific items. This file loads those platforms
# Platforms in F prime's CMake system setup f prime specific items w.r.t the OS. This file loads those platforms
# file and uses it to setup F prime's build. See: [Platform Template](./platform/platform-template.md) for how to
# generate these files.
#
####
if (NOT DEFINED PLATFORM)
set(PLATFORM "${CMAKE_SYSTEM_NAME}")
# Basic definitions
get_filename_component(TOOLCHAIN_NAME "${CMAKE_TOOLCHAIN_FILE}" NAME_WE)
# Setup fallback toolchain name
if ("${TOOLCHAIN_NAME}" STREQUAL "")
set(TOOLCHAIN_NAME "${CMAKE_SYSTEM_NAME}")
endif()
# Include platform file based on system name
message(STATUS "Target build platform: ${PLATFORM}")
message(STATUS "Target build toolchain/platform: ${TOOLCHAIN_NAME}/${CMAKE_SYSTEM_NAME}")
# Output directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${PLATFORM}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/${PLATFORM}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${PLATFORM}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${TOOLCHAIN_NAME}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/${TOOLCHAIN_NAME}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${TOOLCHAIN_NAME}")
set(EXPECTED_PLATFORM_FILE "")
string(REGEX REPLACE ".cmake" "" PLATFORM_NO_SUFFIX "${PLATFORM}")
get_filename_component(TOOLCHAIN_DIR "${CMAKE_TOOLCHAIN_FILE}" DIRECTORY)
if ("${TOOLCHAIN_DIR}" STREQUAL "")
set(TOOLCHAIN_DIR "${CMAKE_CURRENT_LIST_DIR}")
endif()
set(EXPECTED_PLATFORM_FILE "${TOOLCHAIN_DIR}/../platform/${PLATFORM_NO_SUFFIX}.cmake")
# Include host machine settings
if (EXISTS "${EXPECTED_PLATFORM_FILE}")
message(STATUS "Including ${EXPECTED_PLATFORM_FILE}")
include("${EXPECTED_PLATFORM_FILE}")
else()
message(FATAL_ERROR "\n[F-PRIME] No platform config for '${PLATFORM_NO_SUFFIX}'. Please create: '${EXPECTED_PLATFORM_FILE}'\n")
# Loop over locations of platform files in order: project, libraries, then framework
foreach(ROOT ${FPRIME_PROJECT_ROOT};${FPRIME_LIBRARY_LOCATIONS};${FPRIME_FRAMEWORK_PATH} )
set(EXPECTED_PLATFORM_FILE "${ROOT}/cmake/platform/${CMAKE_SYSTEM_NAME}.cmake")
# Include host machine settings
if (EXISTS "${EXPECTED_PLATFORM_FILE}")
message(STATUS "Including ${EXPECTED_PLATFORM_FILE}")
include("${EXPECTED_PLATFORM_FILE}")
break()
endif()
endforeach()
# Ensure the last attempt for the platform file was successful, otherwise error.
if (NOT EXISTS "${EXPECTED_PLATFORM_FILE}")
message(FATAL_ERROR "\n[F-PRIME] No platform config for '${CMAKE_SYSTEM_NAME}'. Please create: '${CMAKE_SYSTEM_NAME}.cmake'\n")
endif()

View File

@ -1,13 +0,0 @@
####
# Linux-common.cmake:
#
# Platform setup for all Linux based targets. This can be used for Linux, raspberry pi, and other linux-like hosts. This
# file represents all common linux functions.
####
# Set linux target
add_definitions(-DTGT_OS_TYPE_LINUX)
set(FPRIME_USE_POSIX ON)
# Add Linux specific headers into the system
include_directories(SYSTEM "${FPRIME_FRAMEWORK_PATH}/Fw/Types/Linux")

View File

@ -3,12 +3,6 @@
#
# Linux platform file for standard linux targets. Merely defers to [./Linux-common.cmake](Linux-common.cmake).
####
# Set platform default for stubbed drivers
if (NOT DEFINED FPRIME_USE_STUBBED_DRIVERS)
set(FPRIME_USE_STUBBED_DRIVERS ON)
endif()
# Set platform default for baremetal scheduler drivers
if (NOT DEFINED FPRIME_USE_BAREMETAL_SCHEDULER)
set(FPRIME_USE_BAREMETAL_SCHEDULE OFF)
@ -17,4 +11,8 @@ if (NOT DEFINED FPRIME_USE_BAREMETAL_SCHEDULER)
endif()
# Use common linux setup
include("${CMAKE_CURRENT_LIST_DIR}/Linux-common.cmake")
add_definitions(-DTGT_OS_TYPE_LINUX)
set(FPRIME_USE_POSIX ON)
# Add Linux specific headers into the system
include_directories(SYSTEM "${FPRIME_FRAMEWORK_PATH}/Fw/Types/Linux")

View File

@ -1,21 +0,0 @@
##
# arm-linux-gnueabihf.cmake:
#
# A platform file supporting the raspberry pi. This is the F prime platform support file that combines with the
# toolchain file found at [../toolchain/raspberrypi.cmake](../toolchain/raspberrypi.cmake).
##
# Set platform default for stubbed drivers
if (NOT DEFINED FPRIME_USE_STUBBED_DRIVERS)
set(FPRIME_USE_STUBBED_DRIVERS OFF)
endif()
# Set platform default for baremetal scheduler drivers
if (NOT DEFINED FPRIME_USE_BAREMETAL_SCHEDULER)
set(FPRIME_USE_BAREMETAL_SCHEDULER OFF)
message(STATUS "Requiring thread library")
FIND_PACKAGE ( Threads REQUIRED )
endif()
# RPI is Linux based, so include the common Linux items
include("${CMAKE_CURRENT_LIST_DIR}/Linux-common.cmake")

View File

@ -17,14 +17,11 @@
# in the chosen Toolchain file, or by the CMake system itself. However, if the user wants to control
# which platform file is used, the load is specified by the following rules:
#
# If the user specifies the platform from the command line using the command line option
# `-DPLATFORM=<NAME>` then that platform file will be used e.g. `-DPLATFORM=Darwin` will load the
# Darwin.cmake regardless of the Host system. This is usually used only in the case of running UTs.
#
# If the user specifies a CMake Toolchain file, then the platform file `${CMAKE_SYSTEM_NAME}.cmake`
# will be used. `${CMAKE_SYSTEM_NAME}` is set in the toolchain file.
# will be used. `${CMAKE_SYSTEM_NAME}` is set in the toolchain file and is typically set to a name like Linux, or Darwin
# but may be more specific if required.
#
# Otherwise, CMake sets the `${CMAKE_SYSTEM_NAME}` to be that of the Host system, and that platform
# Otherwise, CMake sets the `${CMAKE_SYSTEM_NAME}` automatically to be that of the Host system, and that platform
# will be used. e.g. when building on Linux, the platform file "Linux.cmake" will be used.
#
# ### Filling In CMake Platform by Example ###
@ -63,8 +60,12 @@ set(CMAKE_CXX_FLAGS
# STEP 4: Specify that a thread package should be searched in the toolchain
# directory. NOTE: when running without threads, remove this line.
message(STATUS "Requiring thread library")
FIND_PACKAGE ( Threads REQUIRED )
# Here there is a check for the using baremetal scheduler
if (NOT DEFINED FPRIME_USE_BAREMETAL_SCHEDULER)
set(FPRIME_USE_BAREMETAL_SCHEDULE OFF)
message(STATUS "Requiring thread library")
FIND_PACKAGE ( Threads REQUIRED )
endif()
# STEP 5: Specify a directory containing the "StandardTypes.hpp" headers, as well
# as other system headers. Other global headers can be placed here.

View File

@ -22,7 +22,7 @@ function(dictgen MODULE_NAME AI_XML DEPS)
get_filename_component(DICT_XML_NAME ${DICT_XML} NAME)
get_filename_component(ID_CSV_XML_NAME ${ID_CSV_XML} NAME)
get_filename_component(ID_LOG_XML_NAME ${ID_LOG_XML} NAME)
set(DICT_ROOT "${FPRIME_INSTALL_DEST}/${PLATFORM}/dict")
set(DICT_ROOT "${FPRIME_INSTALL_DEST}/${TOOLCHAIN_NAME}/dict")
set(DICTIONARY_OUTPUT_FILE "${DICT_ROOT}/${DICT_XML_NAME}")
add_custom_command(

View File

@ -51,15 +51,15 @@ function(add_module_target MODULE_NAME TARGET_NAME GLOBAL_TARGET_NAME AC_INPUTS
if ("${FPRIME_OBJECT_TYPE}" STREQUAL "Library")
add_custom_target(
${TARGET_NAME}
COMMAND ${CMAKE_COMMAND} -E make_directory "${FPRIME_INSTALL_DEST}/${PLATFORM}/lib/static/"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${MODULE_NAME}> "${FPRIME_INSTALL_DEST}/${PLATFORM}/lib/static/"
COMMAND ${CMAKE_COMMAND} -E make_directory "${FPRIME_INSTALL_DEST}/${TOOLCHAIN_NAME}/lib/static/"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${MODULE_NAME}> "${FPRIME_INSTALL_DEST}/${TOOLCHAIN_NAME}/lib/static/"
DEPENDS ${PKG_DEPS}
)
elseif("${FPRIME_OBJECT_TYPE}" STREQUAL "Executable")
add_custom_target(
${TARGET_NAME}
COMMAND ${CMAKE_COMMAND} -E make_directory "${FPRIME_INSTALL_DEST}/${PLATFORM}/bin/"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${MODULE_NAME}> "${FPRIME_INSTALL_DEST}/${PLATFORM}/bin/"
COMMAND ${CMAKE_COMMAND} -E make_directory "${FPRIME_INSTALL_DEST}/${TOOLCHAIN_NAME}/bin/"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${MODULE_NAME}> "${FPRIME_INSTALL_DEST}/${TOOLCHAIN_NAME}/bin/"
DEPENDS ${PKG_DEPS}
)
add_dependencies("${GLOBAL_TARGET_NAME}" "${TARGET_NAME}")

View File

@ -11,13 +11,10 @@
#
# e.g. should the user install the tools in ``/home/user1` then the environment variable might be set using
# `export RPI_TOOLCHAIN_DIR=/home/user/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/`
#
# **Note:** this toolchain file sets the system name to `arm-linux-gnueabihf` to be similar to other raspberry pi
# toolchain files while providing a cleaner name of `raspberrypi`. Its parallel platform file is therefore named
# `arm-linux-gnueabihf.cmake` in the platforms directory.
####
# Set system name
set(CMAKE_SYSTEM_NAME "arm-linux-gnueabihf")
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_PROCESSOR "arm")
# Location of pi toolchain
set(RPI_TOOLCHAIN "$ENV{RPI_TOOLCHAIN_DIR}")

View File

@ -24,9 +24,7 @@ define types and headers needed for F´ for any embedded system they desire.
[Platform Template](../api/cmake/platform/platform-template.md): Platform file template documentation
[Linux](../api/cmake/platform/Linux.md): Linux platform support
[Darwin](../api/cmake/platform/Darwin.md): Darwin (macOS) platform support
[arm-linux-gnueabihf](../api/cmake/platform/arm-linux-gnueabihf.md): Raspberry PI platform support
[rtems5](../api/cmake/platform/rtems5.md): RTEMS 5 initial support
[Linux-common](./platform/Linux-common.md): Common Linux platform support included above
[CMakeLists.txt](./platform/CMakeLists.txt.md)
## Target Documentation