Skip to content

Commit

Permalink
Fix nasa#312, CMake cleanup
Browse files Browse the repository at this point in the history
Do not clobber the CMAKE_C_FLAGS value as part of the OSAL build.
Instead, use target_compile_options and target_include_directories
as needed to set the compile options for specific targets.

This also creates a separate CMakeLists.txt file for each OS/BSP
implementation library rather than using aux_source_directory.
Each implementation-specific build can then set any additional
options as required for that platform.

Note that any entity needing to compile/link with OSAL should
now obtain the requisite compile flags and directories by querying
the INTERFACE_COMPILE_DEFINITIONS and INTERFACE_INCLUDE_DIRECTORIES
properties on the osal library target.
  • Loading branch information
jphickey committed Apr 1, 2020
1 parent 20a83c4 commit c809052
Show file tree
Hide file tree
Showing 19 changed files with 550 additions and 432 deletions.
486 changes: 241 additions & 245 deletions CMakeLists.txt

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions src/bsp/mcp750-vxworks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
######################################################################
#
# CMAKE build recipe for MCP750 Board Support Package (BSP)
#
######################################################################

add_library(osal_mcp750-vxworks_impl OBJECT
src/bsp_start.c
src/bsp_voltab.c
)

target_include_directories(osal_mcp750-vxworks_impl PUBLIC
$ENV{WIND_BASE}/target/h
$ENV{WIND_BASE}/target/h/wrn/coreip
$ENV{WIND_BASE}/target/config/mcp750
)

# NOTE: the __PPC__ and MCP750 macros are referenced in some system headers.
# therefore all code compiled for this platform should always define these symbols.
target_compile_definitions(osal_mcp750-vxworks_impl PUBLIC
"__PPC__"
"MCP750"
)

add_library(ut_bsp STATIC EXCLUDE_FROM_ALL
ut-src/bsp_ut.c
ut-src/bsp_ut_voltab.c
)
target_include_directories(ut_bsp PRIVATE ${UT_ASSERT_SOURCE_DIR}/inc)


8 changes: 8 additions & 0 deletions src/bsp/mcp750-vxworks/build_options.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
##########################################################################
#
# Build options for "mcp750-vxworks" BSP
#
##########################################################################

# This indicates where to stage target binaries created during the build
set(OSAL_BSP_STAGING_INSTALL_DIR "CF:0")
97 changes: 0 additions & 97 deletions src/bsp/mcp750-vxworks/make/compiler-opts.mak

This file was deleted.

35 changes: 0 additions & 35 deletions src/bsp/mcp750-vxworks/make/link-rules.mak

This file was deleted.

40 changes: 40 additions & 0 deletions src/bsp/pc-linux/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
######################################################################
#
# CMAKE build recipe for PC-LINUX Board Support Package (BSP)
#
######################################################################

# NOTE: Although this is traditionally called "pc-linux", it is generic
# enough to be applied to non-PC systems running embedded Linux, such
# as Raspberry Pi, BeagleBoard, Zync, or custom hardware.

add_library(osal_pc-linux_impl OBJECT
src/bsp_start.c
src/bsp_voltab.c
)

# OSAL needs conformance to at least POSIX.1c (aka POSIX 1995) - this includes all the
# real-time support and threading extensions.
#
# When compiling against glibc, using "_XOPEN_SOURCE=600" enables the X/Open 6 standard.
# XPG6 includes all necessary XPG5, POSIX.1c features as well as SUSv2/UNIX98 extensions.
# This OSAL implementation uses clock_nanosleep(), mq_timedreceive(), and
# mq_timedsend() which are enhancements added in the XPG6 standard.
#
# 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_pc-linux_impl PUBLIC
_XOPEN_SOURCE=600
)

add_library(ut_bsp STATIC EXCLUDE_FROM_ALL
ut-src/bsp_ut.c
ut-src/bsp_ut_voltab.c
)
target_include_directories(ut_bsp PRIVATE
${UT_ASSERT_SOURCE_DIR}/inc
)
target_compile_definitions(ut_bsp PUBLIC
_XOPEN_SOURCE=600
)

28 changes: 28 additions & 0 deletions src/bsp/pc-linux/build_options.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
##########################################################################
#
# Build options for "pc-linux" BSP
#
##########################################################################



# Linux system libraries required for the final link of applications using OSAL
target_link_libraries(osal
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)
set(UT_COVERAGE_COMPILE_FLAGS -pg --coverage)
set(UT_COVERAGE_LINK_FLAGS -pg --coverage)
endif()

# This indicates where to stage target binaries created during the build
# It should reflect the _real_ location of the persistent storage path used by
# the BSP which is intended to be used for runtime modules or files.
set(OSAL_BSP_STAGING_INSTALL_DIR "eeprom1")
14 changes: 0 additions & 14 deletions src/bsp/pc-linux/make/build_options.cmake

This file was deleted.

16 changes: 16 additions & 0 deletions src/bsp/pc-rtems/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
######################################################################
#
# CMAKE build recipe for PC-RTEMS Board Support Package (BSP)
#
######################################################################

add_library(osal_pc-rtems_impl OBJECT
src/bsp_start.c
src/bsp_voltab.c
)

add_library(ut_bsp STATIC EXCLUDE_FROM_ALL
ut-src/bsp_ut.c
ut-src/bsp_ut_voltab.c
)
target_include_directories(ut_bsp PRIVATE ${UT_ASSERT_SOURCE_DIR}/inc)
15 changes: 15 additions & 0 deletions src/bsp/pc-rtems/build_options.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
##########################################################################
#
# Build options for "pc-rtems" BSP
#
##########################################################################

# Link the RTEMS BSP with the "rtemscpu" system library
target_link_libraries(osal
rtemscpu
)

# This indicates where to stage target binaries created during the build
# It should reflect the _real_ location of the persistent storage path used by
# the BSP which is intended to be used for runtime modules or files.
set(OSAL_BSP_STAGING_INSTALL_DIR "eeprom")
3 changes: 0 additions & 3 deletions src/bsp/pc-rtems/make/build_options.cmake

This file was deleted.

19 changes: 19 additions & 0 deletions src/os/posix/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
######################################################################
#
# CMAKE build recipe for POSIX OSAL implementation
#
######################################################################

# This CMake script generates targets specific to the POSIX implementation
# It defines an OBJECT target named "osal_posix_impl"

add_library(osal_posix_impl OBJECT
osapi.c
osfileapi.c
osfilesys.c
osloader.c
osnetwork.c
osselect.c
ostimer.c
)

33 changes: 6 additions & 27 deletions src/os/posix/build_options.cmake
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
##########################################################################
#
# For POSIX systems based on glibc (i.e. Linux) certain features must be enabled
# Glibc headers support multiple standards and multiple versions of the standards,
# so the definitions of these macros determine which standard we will use
# Build options for "posix" implementation layer
#
# OSAL needs conformance to at least POSIX.1c (aka POSIX 1995) - this includes all the
# real-time support and threading extensions.
#
# When compiling against glibc, using "_XOPEN_SOURCE=600" enables the X/Open 6 standard.
# XPG6 includes all necessary XPG5, POSIX.1c features as well as SUSv2/UNIX98 extensions.
# This OSAL implementation uses clock_nanosleep(), mq_timedreceive(), and
# mq_timedsend() which are enhancements added in the XPG6 standard. (The previous OSAL
# POSIX implementation needed only XPG5). It may be possible to conditionally compile
# these calls in case of a C library that does not have XPG6.
#
# Note that this definition assumes glibc -- in case of compiling OSAL for some platform
# that supports POSIX but does not use glibc (e.g. uclibc) this definition shouldn't
# harm anything, but it may need to be tweaked.
#
# 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
#
set(OSAL_COMMON_COMPILE_DEFS "${OSAL_COMMON_COMPILE_DEFS} -D_XOPEN_SOURCE=600")

# OSAL_LINK_LIBS determines which system-level libraries must be included in the
# link command in order to produce the final binary. These libs will be used for
# ALL targets that utilize the POSIX OS layer. Additional target-specific libraries
# may also be specified in the BSP or the cross-compile toolchain.
set (OSAL_LINK_LIBS ${OSAL_LINK_LIBS} pthread dl rt)
##########################################################################

# this file is a placeholder for POSIX-specific compile tuning
# currently no extra flags/definitions needed

17 changes: 17 additions & 0 deletions src/os/rtems/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
######################################################################
#
# CMAKE build recipe for RTEMS OSAL implementation
#
######################################################################

# This CMake script generates targets specific to the RTEMS implementation
# It defines an OBJECT target named "osal_rtems_impl"
add_library(osal_rtems_impl OBJECT
osapi.c
osfileapi.c
osfilesys.c
osloader.c
osnetwork.c
osselect.c
ostimer.c
)
17 changes: 8 additions & 9 deletions src/os/rtems/build_options.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
##########################################################################
#
# Build options for "rtems" implementation layer
#
##########################################################################

# Some upper-level code may be gated on _RTEMS_OS_ being defined
set(OSAL_COMMON_COMPILE_DEFS "${OSAL_COMMON_COMPILE_DEFS} -D_RTEMS_OS_")

# OSAL_LINK_LIBS determines which system-level libraries must be included in the
# link command in order to produce the final binary. These libs will be used for
# ALL targets that utilize the RTEMS OS layer. Additional target-specific libraries
# may also be specified in the BSP or the cross-compile toolchain.
SET(OSAL_LINK_LIBS rtemscpu)

# this file is a placeholder for RTEMS-specific compile tuning
# currently no extra flags/definitions needed

Loading

0 comments on commit c809052

Please sign in to comment.