Skip to content

Commit

Permalink
Adding restrict_platform support for FPRIME_HAS_XYZ flags (#3037)
Browse files Browse the repository at this point in the history
* Adding restrict_platform support for FPRIME_HAS_XYZ flags

* Rerestricting PosixTime to Posix
  • Loading branch information
LeStarch authored Nov 22, 2024
1 parent f350719 commit a819e33
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 76 deletions.
40 changes: 20 additions & 20 deletions Drv/Ip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,48 @@
# MOD_DEPS: (optional) module dependencies
#
####
restrict_platforms(Posix)
restrict_platforms(Posix SOCKETS)

set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/IpSocket.cpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpClientSocket.cpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpServerSocket.cpp"
"${CMAKE_CURRENT_LIST_DIR}/UdpSocket.cpp"
"${CMAKE_CURRENT_LIST_DIR}/SocketComponentHelper.cpp"
"${CMAKE_CURRENT_LIST_DIR}/IpSocket.cpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpClientSocket.cpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpServerSocket.cpp"
"${CMAKE_CURRENT_LIST_DIR}/UdpSocket.cpp"
"${CMAKE_CURRENT_LIST_DIR}/SocketComponentHelper.cpp"
)

set(MOD_DEPS
Os
Fw/Buffer
Os
Fw/Buffer
)

register_fprime_module()

# The PortSelector library and testing helper is only needed on Testing build
if (BUILD_TESTING)
add_library(SocketTestHelper STATIC
"${CMAKE_CURRENT_LIST_DIR}/test/ut/PortSelector.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SocketTestHelper.cpp")
target_include_directories(SocketTestHelper PUBLIC
"${FPRIME_FRAMEWORK_PATH}/STest"
"${FPRIME_FRAMEWORK_PATH}/googletest/googletest/include"
)
add_dependencies(SocketTestHelper STest Fw_Buffer)
target_link_libraries(SocketTestHelper STest Fw_Buffer)
add_library(SocketTestHelper STATIC
"${CMAKE_CURRENT_LIST_DIR}/test/ut/PortSelector.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SocketTestHelper.cpp")
target_include_directories(SocketTestHelper PUBLIC
"${FPRIME_FRAMEWORK_PATH}/STest"
"${FPRIME_FRAMEWORK_PATH}/googletest/googletest/include"
)
add_dependencies(SocketTestHelper STest Fw_Buffer)
target_link_libraries(SocketTestHelper STest Fw_Buffer)
endif()

set(UT_MOD_DEPS
SocketTestHelper
SocketTestHelper
)

### UTs ###
set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestTcp.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestTcp.cpp"
)
register_fprime_ut("Drv_Ip_Tcp_test")

set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestUdp.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestUdp.cpp"
)
register_fprime_ut("Drv_Ip_Udp_test")

22 changes: 11 additions & 11 deletions Drv/TcpClient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
# MOD_DEPS: (optional) module dependencies
#
####
restrict_platforms(Posix)
restrict_platforms(Posix SOCKETS)

set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/TcpClient.fpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpClientComponentImpl.cpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpClient.fpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpClientComponentImpl.cpp"
)

# Necessary shared helpers
set(MOD_DEPS
"Fw/Logger"
"Drv/ByteStreamDriverModel"
"Drv/Ip"
"Fw/Logger"
"Drv/ByteStreamDriverModel"
"Drv/Ip"
)

register_fprime_module()

### UTs ###
set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/TcpClient.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TcpClientTestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TcpClientTester.cpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpClient.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TcpClientTestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TcpClientTester.cpp"
)
set(UT_MOD_DEPS
STest
SocketTestHelper
STest
SocketTestHelper
)
set(UT_AUTO_HELPERS ON)
register_fprime_ut()
22 changes: 11 additions & 11 deletions Drv/TcpServer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
# MOD_DEPS: (optional) module dependencies
#
####
restrict_platforms(Posix)
restrict_platforms(Posix SOCKETS)

set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/TcpServer.fpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpServerComponentImpl.cpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpServer.fpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpServerComponentImpl.cpp"
)

# Necessary shared helpers
set(MOD_DEPS
"Fw/Logger"
"Drv/ByteStreamDriverModel"
"Drv/Ip"
"Fw/Logger"
"Drv/ByteStreamDriverModel"
"Drv/Ip"
)

register_fprime_module()

### UTs ###
set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/TcpServer.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TcpServerTestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TcpServerTester.cpp"
"${CMAKE_CURRENT_LIST_DIR}/TcpServer.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TcpServerTestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TcpServerTester.cpp"
)
set(UT_MOD_DEPS
STest
SocketTestHelper
STest
SocketTestHelper
)
set(UT_AUTO_HELPERS ON)
register_fprime_ut()
22 changes: 11 additions & 11 deletions Drv/Udp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
# MOD_DEPS: (optional) module dependencies
#
####
restrict_platforms(Posix)
restrict_platforms(Posix SOCKETS)

set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/Udp.fpp"
"${CMAKE_CURRENT_LIST_DIR}/UdpComponentImpl.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Udp.fpp"
"${CMAKE_CURRENT_LIST_DIR}/UdpComponentImpl.cpp"
)

# Necessary shared helpers
set(MOD_DEPS
"Fw/Logger"
"Drv/ByteStreamDriverModel"
"Drv/Ip"
"Fw/Logger"
"Drv/ByteStreamDriverModel"
"Drv/Ip"
)

register_fprime_module()

### UTs ###
set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/Udp.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/UdpTestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/UdpTester.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Udp.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/UdpTestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/UdpTester.cpp"
)
set(UT_MOD_DEPS
STest
SocketTestHelper
STest
SocketTestHelper
)
set(UT_AUTO_HELPERS ON)
register_fprime_ut()
25 changes: 23 additions & 2 deletions cmake/API.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,36 @@ endmacro()
####
# Macro `restrict_platforms`:
#
# Restricts a CMakeLists.txt file to a given list of platforms. This prevents usage on platforms for which the module
# is incapable of being used and replaces the historical pattern of an if-tree detecting unsupported platforms.
# Restricts a CMakeLists.txt file to a given list of supported platforms, toolchains, and features. This prevents
# usage on platforms/toolchains for which the module is incapable of being used and replaces the historical pattern of
# an if-tree detecting unsupported platforms in most circumstances.
#
# Valid inputs include names of platforms (e.g. Linux), names of specific toolchains (e.g. aarch64-linux), and platform
# supported feature sets (e.g. SOCKETS, which inspects the FPRIME_HAS_SOCKETS flag).
#
# Usage:
# restrict_platforms(Linux Darwin) # Restricts to Linux and Darwin platforms
# -or-
# restrict_platforms(Posix) # Restricts to posix systems
# -or-
# restrict_platforms(SOCKETS) # Restricts to platforms where FPRIME_HAS_SOCKETS is TRUE
#
# Args:
# ARGN: list of platforms that are supported
#####
macro(restrict_platforms)
set(__CHECKER ${ARGN})

# Determine if any of the restrict-tos maps to a fprime feature flag of the form FPRIME_HAS_XYZ as set in the
# platform support file. If this feature is set and true, then the restriction block may pass.
set(__HAS_SUPPORTED_FEATURE FALSE)
foreach (__RESTRICTION IN LISTS __CHECKER)
string(TOUPPER "${__RESTRICTION}" __RESTRICTION_UPPER)
if (FPRIME_HAS_${__RESTRICTION_UPPER})
set(__HAS_SUPPORTED_FEATURE TRUE)
break()
endif()
endforeach()
# Each of these empty if blocks are the valid-case, that is, the platform is supported.
# However, the reason why this is necessary is that this function is a macro and not a function.
# Macros copy-paste the code into the calling context. Thus, all these valid cases want to avoid calling return.
Expand All @@ -53,6 +71,9 @@ macro(restrict_platforms)

if (FPRIME_TOOLCHAIN_NAME IN_LIST __CHECKER)
elseif(FPRIME_PLATFORM IN_LIST __CHECKER)
# New style FPRIME_HAS_<FEATURE>
elseif(__HAS_SUPPORTED_FEATURE)
# Old style posix FPRIME_USE_POSIX
elseif("Posix" IN_LIST __CHECKER AND FPRIME_USE_POSIX)
else()
get_module_name("${CMAKE_CURRENT_LIST_DIR}")
Expand Down
1 change: 1 addition & 0 deletions cmake/platform/Darwin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
add_definitions(-DTGT_OS_TYPE_DARWIN)

set(FPRIME_USE_POSIX ON)
set(FPRIME_HAS_SOCKETS ON)
# Set platform default for stubbed drivers
if (NOT DEFINED FPRIME_USE_STUBBED_DRIVERS)
set(FPRIME_USE_STUBBED_DRIVERS ON)
Expand Down
1 change: 1 addition & 0 deletions cmake/platform/Linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ choose_fprime_implementation(Os/Memory Os/Memory/Linux)
# Use common linux setup
add_definitions(-DTGT_OS_TYPE_LINUX)
set(FPRIME_USE_POSIX ON)
set(FPRIME_HAS_SOCKETS ON)

# Add Linux specific headers into the system
include_directories(SYSTEM "${CMAKE_CURRENT_LIST_DIR}/types")
Expand Down
20 changes: 0 additions & 20 deletions cmake/platform/rtems5.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fprime-fpp-to-dict==2.2.1a1
fprime-fpp-to-json==2.2.1a1
fprime-fpp-to-xml==2.2.1a1
fprime-gds==3.5.0
fprime-tools==3.5.0
fprime-tools==3.5.1a2
fprime-visual==1.0.2
gcovr==8.2
idna==3.10
Expand Down

0 comments on commit a819e33

Please sign in to comment.