Skip to content

Commit a819e33

Browse files
authored
Adding restrict_platform support for FPRIME_HAS_XYZ flags (#3037)
* Adding restrict_platform support for FPRIME_HAS_XYZ flags * Rerestricting PosixTime to Posix
1 parent f350719 commit a819e33

File tree

9 files changed

+79
-76
lines changed

9 files changed

+79
-76
lines changed

Drv/Ip/CMakeLists.txt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,48 @@
55
# MOD_DEPS: (optional) module dependencies
66
#
77
####
8-
restrict_platforms(Posix)
8+
restrict_platforms(Posix SOCKETS)
99

1010
set(SOURCE_FILES
11-
"${CMAKE_CURRENT_LIST_DIR}/IpSocket.cpp"
12-
"${CMAKE_CURRENT_LIST_DIR}/TcpClientSocket.cpp"
13-
"${CMAKE_CURRENT_LIST_DIR}/TcpServerSocket.cpp"
14-
"${CMAKE_CURRENT_LIST_DIR}/UdpSocket.cpp"
15-
"${CMAKE_CURRENT_LIST_DIR}/SocketComponentHelper.cpp"
11+
"${CMAKE_CURRENT_LIST_DIR}/IpSocket.cpp"
12+
"${CMAKE_CURRENT_LIST_DIR}/TcpClientSocket.cpp"
13+
"${CMAKE_CURRENT_LIST_DIR}/TcpServerSocket.cpp"
14+
"${CMAKE_CURRENT_LIST_DIR}/UdpSocket.cpp"
15+
"${CMAKE_CURRENT_LIST_DIR}/SocketComponentHelper.cpp"
1616
)
1717

1818
set(MOD_DEPS
19-
Os
20-
Fw/Buffer
19+
Os
20+
Fw/Buffer
2121
)
2222

2323
register_fprime_module()
2424

2525
# The PortSelector library and testing helper is only needed on Testing build
2626
if (BUILD_TESTING)
27-
add_library(SocketTestHelper STATIC
28-
"${CMAKE_CURRENT_LIST_DIR}/test/ut/PortSelector.cpp"
29-
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SocketTestHelper.cpp")
30-
target_include_directories(SocketTestHelper PUBLIC
31-
"${FPRIME_FRAMEWORK_PATH}/STest"
32-
"${FPRIME_FRAMEWORK_PATH}/googletest/googletest/include"
33-
)
34-
add_dependencies(SocketTestHelper STest Fw_Buffer)
35-
target_link_libraries(SocketTestHelper STest Fw_Buffer)
27+
add_library(SocketTestHelper STATIC
28+
"${CMAKE_CURRENT_LIST_DIR}/test/ut/PortSelector.cpp"
29+
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SocketTestHelper.cpp")
30+
target_include_directories(SocketTestHelper PUBLIC
31+
"${FPRIME_FRAMEWORK_PATH}/STest"
32+
"${FPRIME_FRAMEWORK_PATH}/googletest/googletest/include"
33+
)
34+
add_dependencies(SocketTestHelper STest Fw_Buffer)
35+
target_link_libraries(SocketTestHelper STest Fw_Buffer)
3636
endif()
3737

3838
set(UT_MOD_DEPS
39-
SocketTestHelper
39+
SocketTestHelper
4040
)
4141

4242
### UTs ###
4343
set(UT_SOURCE_FILES
44-
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestTcp.cpp"
44+
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestTcp.cpp"
4545
)
4646
register_fprime_ut("Drv_Ip_Tcp_test")
4747

4848
set(UT_SOURCE_FILES
49-
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestUdp.cpp"
49+
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestUdp.cpp"
5050
)
5151
register_fprime_ut("Drv_Ip_Udp_test")
5252

Drv/TcpClient/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55
# MOD_DEPS: (optional) module dependencies
66
#
77
####
8-
restrict_platforms(Posix)
8+
restrict_platforms(Posix SOCKETS)
99

1010
set(SOURCE_FILES
11-
"${CMAKE_CURRENT_LIST_DIR}/TcpClient.fpp"
12-
"${CMAKE_CURRENT_LIST_DIR}/TcpClientComponentImpl.cpp"
11+
"${CMAKE_CURRENT_LIST_DIR}/TcpClient.fpp"
12+
"${CMAKE_CURRENT_LIST_DIR}/TcpClientComponentImpl.cpp"
1313
)
1414

1515
# Necessary shared helpers
1616
set(MOD_DEPS
17-
"Fw/Logger"
18-
"Drv/ByteStreamDriverModel"
19-
"Drv/Ip"
17+
"Fw/Logger"
18+
"Drv/ByteStreamDriverModel"
19+
"Drv/Ip"
2020
)
2121

2222
register_fprime_module()
2323

2424
### UTs ###
2525
set(UT_SOURCE_FILES
26-
"${CMAKE_CURRENT_LIST_DIR}/TcpClient.fpp"
27-
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TcpClientTestMain.cpp"
28-
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TcpClientTester.cpp"
26+
"${CMAKE_CURRENT_LIST_DIR}/TcpClient.fpp"
27+
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TcpClientTestMain.cpp"
28+
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TcpClientTester.cpp"
2929
)
3030
set(UT_MOD_DEPS
31-
STest
32-
SocketTestHelper
31+
STest
32+
SocketTestHelper
3333
)
3434
set(UT_AUTO_HELPERS ON)
3535
register_fprime_ut()

Drv/TcpServer/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55
# MOD_DEPS: (optional) module dependencies
66
#
77
####
8-
restrict_platforms(Posix)
8+
restrict_platforms(Posix SOCKETS)
99

1010
set(SOURCE_FILES
11-
"${CMAKE_CURRENT_LIST_DIR}/TcpServer.fpp"
12-
"${CMAKE_CURRENT_LIST_DIR}/TcpServerComponentImpl.cpp"
11+
"${CMAKE_CURRENT_LIST_DIR}/TcpServer.fpp"
12+
"${CMAKE_CURRENT_LIST_DIR}/TcpServerComponentImpl.cpp"
1313
)
1414

1515
# Necessary shared helpers
1616
set(MOD_DEPS
17-
"Fw/Logger"
18-
"Drv/ByteStreamDriverModel"
19-
"Drv/Ip"
17+
"Fw/Logger"
18+
"Drv/ByteStreamDriverModel"
19+
"Drv/Ip"
2020
)
2121

2222
register_fprime_module()
2323

2424
### UTs ###
2525
set(UT_SOURCE_FILES
26-
"${CMAKE_CURRENT_LIST_DIR}/TcpServer.fpp"
27-
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TcpServerTestMain.cpp"
28-
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TcpServerTester.cpp"
26+
"${CMAKE_CURRENT_LIST_DIR}/TcpServer.fpp"
27+
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TcpServerTestMain.cpp"
28+
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TcpServerTester.cpp"
2929
)
3030
set(UT_MOD_DEPS
31-
STest
32-
SocketTestHelper
31+
STest
32+
SocketTestHelper
3333
)
3434
set(UT_AUTO_HELPERS ON)
3535
register_fprime_ut()

Drv/Udp/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55
# MOD_DEPS: (optional) module dependencies
66
#
77
####
8-
restrict_platforms(Posix)
8+
restrict_platforms(Posix SOCKETS)
99

1010
set(SOURCE_FILES
11-
"${CMAKE_CURRENT_LIST_DIR}/Udp.fpp"
12-
"${CMAKE_CURRENT_LIST_DIR}/UdpComponentImpl.cpp"
11+
"${CMAKE_CURRENT_LIST_DIR}/Udp.fpp"
12+
"${CMAKE_CURRENT_LIST_DIR}/UdpComponentImpl.cpp"
1313
)
1414

1515
# Necessary shared helpers
1616
set(MOD_DEPS
17-
"Fw/Logger"
18-
"Drv/ByteStreamDriverModel"
19-
"Drv/Ip"
17+
"Fw/Logger"
18+
"Drv/ByteStreamDriverModel"
19+
"Drv/Ip"
2020
)
2121

2222
register_fprime_module()
2323

2424
### UTs ###
2525
set(UT_SOURCE_FILES
26-
"${CMAKE_CURRENT_LIST_DIR}/Udp.fpp"
27-
"${CMAKE_CURRENT_LIST_DIR}/test/ut/UdpTestMain.cpp"
28-
"${CMAKE_CURRENT_LIST_DIR}/test/ut/UdpTester.cpp"
26+
"${CMAKE_CURRENT_LIST_DIR}/Udp.fpp"
27+
"${CMAKE_CURRENT_LIST_DIR}/test/ut/UdpTestMain.cpp"
28+
"${CMAKE_CURRENT_LIST_DIR}/test/ut/UdpTester.cpp"
2929
)
3030
set(UT_MOD_DEPS
31-
STest
32-
SocketTestHelper
31+
STest
32+
SocketTestHelper
3333
)
3434
set(UT_AUTO_HELPERS ON)
3535
register_fprime_ut()

cmake/API.cmake

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,36 @@ endmacro()
3333
####
3434
# Macro `restrict_platforms`:
3535
#
36-
# Restricts a CMakeLists.txt file to a given list of platforms. This prevents usage on platforms for which the module
37-
# is incapable of being used and replaces the historical pattern of an if-tree detecting unsupported platforms.
36+
# Restricts a CMakeLists.txt file to a given list of supported platforms, toolchains, and features. This prevents
37+
# usage on platforms/toolchains for which the module is incapable of being used and replaces the historical pattern of
38+
# an if-tree detecting unsupported platforms in most circumstances.
39+
#
40+
# Valid inputs include names of platforms (e.g. Linux), names of specific toolchains (e.g. aarch64-linux), and platform
41+
# supported feature sets (e.g. SOCKETS, which inspects the FPRIME_HAS_SOCKETS flag).
3842
#
3943
# Usage:
4044
# restrict_platforms(Linux Darwin) # Restricts to Linux and Darwin platforms
45+
# -or-
46+
# restrict_platforms(Posix) # Restricts to posix systems
47+
# -or-
48+
# restrict_platforms(SOCKETS) # Restricts to platforms where FPRIME_HAS_SOCKETS is TRUE
4149
#
4250
# Args:
4351
# ARGN: list of platforms that are supported
4452
#####
4553
macro(restrict_platforms)
4654
set(__CHECKER ${ARGN})
4755

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

5472
if (FPRIME_TOOLCHAIN_NAME IN_LIST __CHECKER)
5573
elseif(FPRIME_PLATFORM IN_LIST __CHECKER)
74+
# New style FPRIME_HAS_<FEATURE>
75+
elseif(__HAS_SUPPORTED_FEATURE)
76+
# Old style posix FPRIME_USE_POSIX
5677
elseif("Posix" IN_LIST __CHECKER AND FPRIME_USE_POSIX)
5778
else()
5879
get_module_name("${CMAKE_CURRENT_LIST_DIR}")

cmake/platform/Darwin.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
add_definitions(-DTGT_OS_TYPE_DARWIN)
88

99
set(FPRIME_USE_POSIX ON)
10+
set(FPRIME_HAS_SOCKETS ON)
1011
# Set platform default for stubbed drivers
1112
if (NOT DEFINED FPRIME_USE_STUBBED_DRIVERS)
1213
set(FPRIME_USE_STUBBED_DRIVERS ON)

cmake/platform/Linux.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ choose_fprime_implementation(Os/Memory Os/Memory/Linux)
2222
# Use common linux setup
2323
add_definitions(-DTGT_OS_TYPE_LINUX)
2424
set(FPRIME_USE_POSIX ON)
25+
set(FPRIME_HAS_SOCKETS ON)
2526

2627
# Add Linux specific headers into the system
2728
include_directories(SYSTEM "${CMAKE_CURRENT_LIST_DIR}/types")

cmake/platform/rtems5.cmake

Lines changed: 0 additions & 20 deletions
This file was deleted.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fprime-fpp-to-dict==2.2.1a1
3333
fprime-fpp-to-json==2.2.1a1
3434
fprime-fpp-to-xml==2.2.1a1
3535
fprime-gds==3.5.0
36-
fprime-tools==3.5.0
36+
fprime-tools==3.5.1a2
3737
fprime-visual==1.0.2
3838
gcovr==8.2
3939
idna==3.10

0 commit comments

Comments
 (0)