Skip to content

Commit

Permalink
Fix #1284, add export targets and package script
Browse files Browse the repository at this point in the history
Adds optional "install" commands to CMake script, which is useful when
building OSAL as a standalone software package.  The public API and
static libraries will be installed to the specified system location, and
can then be used to compile and link external OSAL applications without
the need for the original OSAL source or build trees.

Note this also installs the "osconfig.h" file as this does affect the
binary formats of some items (i.e. size of items using OS_MAX_API_NAME
and other similar structure members).  The external application must be
compiled using the same osconfig.h after installation.
  • Loading branch information
jphickey committed Oct 12, 2022
1 parent 0bd6c42 commit 58a24bd
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
58 changes: 57 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
# Normally this setting is not needed to be configured as it is
# inferred from the BSP type.
#
# OSAL_INSTALL_LIBRARIES : Boolean, enables "install" of targets listed above such
# that libraries and public API header files are copied into the system
# location specified by CMAKE_INSTALL_PREFIX. This set of headers
# and link libraries can then be used to compile other applications
# separately from OSAL. Default is "ON" when OSAL is being compiled
# standalone (i.e. cmake called directly on the OSAL source dir).
# Default is "OFF" when OSAL is included via 'add_subdirectory' in
# a parent application project such as CFE/CFS.
#
# ENABLE_UNIT_TESTS : Boolean, enables build of the unit tests (coverage and functional)
#
# OSAL_OMIT_DEPRECATED : Boolean, Compile without deprecated or obsolete features for
Expand Down Expand Up @@ -99,8 +108,24 @@ define_property(TARGET PROPERTY OSAL_EXPECTED_OSTYPE
"This property is used to indicate the OS implementation layer that is intended to be paired with the BSP implementation"
)

# If this build is being performed as a subdirectory within a larger project,
# then the static libraries and header files will _not_ be installed by default,
# as in those cases one would typically just use the "osal" target directly.
# This behavior can be explicitly controlled via the OSAL_INSTALL_LIBRARIES option.
get_directory_property(HAS_PARENT PARENT_DIRECTORY)
if (HAS_PARENT)
set(OSAL_DEFAULT_INSTALL_LIBRARIES OFF)
else()
set(OSAL_DEFAULT_INSTALL_LIBRARIES ON)
endif()

option(OSAL_INSTALL_LIBRARIES "Whether or not to install static libraries and headers" ${OSAL_DEFAULT_INSTALL_LIBRARIES})
option(OSAL_OMIT_DEPRECATED "Compile without deprecated or obsolete features for backward compatibility testing" OFF)

if (OSAL_INSTALL_LIBRARIES)
include(CMakePackageConfigHelpers)
endif()

# 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.
Expand Down Expand Up @@ -406,7 +431,6 @@ endif (ENABLE_UNIT_TESTS)
# If this build is being performed as a subdirectory within a larger project,
# then export the important data regarding compile flags/dirs to that parent
# This is conditional to avoid warnings in a standalone build.
get_directory_property(HAS_PARENT PARENT_DIRECTORY)
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
Expand All @@ -420,3 +444,35 @@ else(HAS_PARENT)
# Note that in a CFE/integrated build, it is expected this will be built separately.
add_subdirectory(docs/src docs)
endif(HAS_PARENT)

if (OSAL_INSTALL_LIBRARIES)

# Install and also export this library, so it can be found via
# "find_package()" from some other CMake build
install(
TARGETS osal_public_api osal_bsp osal
EXPORT nasa-osal-export
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include/osal
INCLUDES DESTINATION include/osal
)
install(DIRECTORY
${OSAL_SOURCE_DIR}/src/os/inc/
${CMAKE_CURRENT_BINARY_DIR}/inc/
DESTINATION include/osal
)
install(EXPORT nasa-osal-export
FILE NasaOsalTargets.cmake
DESTINATION lib/cmake
)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/NasaOsalConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/NasaOsalConfig.cmake"
INSTALL_DESTINATION lib/cmake
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/NasaOsalConfig.cmake"
DESTINATION lib/cmake
)

endif()
6 changes: 6 additions & 0 deletions NasaOsalConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/NasaOsalTargets.cmake")

check_required_components(NasaOsal)

8 changes: 8 additions & 0 deletions src/ut-stubs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,11 @@ target_link_libraries(ut_osapi_stubs PUBLIC
ut_assert
)

if (OSAL_INSTALL_LIBRARIES)
install(
TARGETS ut_osapi_stubs
EXPORT nasa-osal-export
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
endif()
21 changes: 21 additions & 0 deletions ut_assert/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,25 @@ target_link_libraries(ut_coverage_compile INTERFACE ut_assert)
add_library(ut_coverage_link INTERFACE)
target_link_libraries(ut_coverage_link INTERFACE ut_assert)

if (OSAL_INSTALL_LIBRARIES)

install(
TARGETS ut_assert ut_coverage_compile ut_coverage_link
EXPORT nasa-osal-export
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include/ut_assert
INCLUDES DESTINATION include/ut_assert
)
install(DIRECTORY
${UT_ASSERT_SOURCE_DIR}/inc/
DESTINATION include/ut_assert
)
install(
PROGRAMS scripts/generate_stubs.pl
DESTINATION bin
RENAME utassert_generate_stubs.pl
)

endif()

0 comments on commit 58a24bd

Please sign in to comment.