From da4dc9d92d3cfcb0ce2cc5a93f58e68b53450dc3 Mon Sep 17 00:00:00 2001 From: M Starch Date: Fri, 18 Jul 2025 12:56:11 -0700 Subject: [PATCH] Add CMake package file for F Prime (#3898) --- Ref/CMakeLists.txt | 45 ++++++++-------------------------------- cmake/FPrimeConfig.cmake | 9 ++++++++ cmake/settings.cmake | 23 +++++++++++--------- 3 files changed, 31 insertions(+), 46 deletions(-) create mode 100644 cmake/FPrimeConfig.cmake diff --git a/Ref/CMakeLists.txt b/Ref/CMakeLists.txt index d6ee05c470..91f73d265e 100644 --- a/Ref/CMakeLists.txt +++ b/Ref/CMakeLists.txt @@ -4,24 +4,18 @@ # This sets up the build for the 'Ref' Application, including the custom reference # components. In addition, it imports FPrime.cmake, which includes the core F Prime # components. -# -# This file has several sections. -# -# 1. Header Section: define basic properties of the build -# 2. F prime core: includes all F prime core components, and build-system properties -# 3. Local subdirectories: contains all deployment specific directory additions #### -## -# Section 1: Basic Project Setup -# -# This contains the basic project information. Specifically, a cmake version and -# project definition. -## -cmake_minimum_required(VERSION 3.16) +# Allow CMake 3.0 - 4.0 projects to set the VERSION variable in the `project` call cmake_policy(SET CMP0048 NEW) +# CMake basic setup: version consistent with requirements.txt, and define a project +cmake_minimum_required(VERSION 3.26) project(Ref VERSION 1.0.0 LANGUAGES C CXX) -## + +# Find the fprime package and include the core codebase +set(FPRIME_INCLUDE_FRAMEWORK_CODE ON) +find_package(FPrime REQUIRED PATHS "${CMAKE_CURRENT_LIST_DIR}/..") + add_compile_options( $<$:-Wold-style-cast> -Wall @@ -35,35 +29,15 @@ add_compile_options( -pedantic ) -# Section 2: F prime Core -# -# This includes all of the F prime core components, and imports the make-system. F prime core -# components will be placed in the F-Prime binary subdirectory to keep them from -# colliding with deployment specific items. -## -include("${CMAKE_CURRENT_LIST_DIR}/../cmake/FPrime.cmake") -# NOTE: register custom targets between these two lines -fprime_setup_included_code() -## -# Section 3: Components and Topology -# -# This section includes deployment specific directories. This allows use of non- -# core components in the topology, which is also added here. -## -# Add component subdirectories +# Add subdirectories for the Ref project specific components add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/PingReceiver/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/RecvBuffApp/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/SendBuffApp/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/SignalGen/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/TypeDemo/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/BlockDriver/") - -# Add Topology subdirectory add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Top/") -#set(SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/Main.cpp") -#set(MOD_DEPS ${PROJECT_NAME}/Top) - register_fprime_deployment( SOURCES "${CMAKE_CURRENT_LIST_DIR}/Main.cpp" @@ -85,4 +59,3 @@ target_compile_options("${PROJECT_NAME}" PUBLIC -Wold-style-cast) target_compile_options("${PROJECT_NAME}" PUBLIC -Woverloaded-virtual) target_compile_options("${PROJECT_NAME}" PUBLIC -Wno-unused-parameter) target_compile_options("${PROJECT_NAME}" PUBLIC -Wundef) -set_property(TARGET "${PROJECT_NAME}" PROPERTY CXX_STANDARD 11) diff --git a/cmake/FPrimeConfig.cmake b/cmake/FPrimeConfig.cmake new file mode 100644 index 0000000000..7e13c466b6 --- /dev/null +++ b/cmake/FPrimeConfig.cmake @@ -0,0 +1,9 @@ +message(STATUS "[F Prime] F Prime CMake package found at: ${CMAKE_CURRENT_LIST_FILE}") +include("${CMAKE_CURRENT_LIST_DIR}/FPrime.cmake") + +# By default the F Prime package will load the codebase. This can be set OFF by setting the variable +# FPRIME_INCLUDE_FRAMEWORK_CODE to OFF. When set OFF, the user must call fprime_setup_included_code() +# to be able to use F Prime code. +if ((NOT DEFINED FPRIME_INCLUDE_FRAMEWORK_CODE) OR (FPRIME_INCLUDE_FRAMEWORK_CODE)) + fprime_setup_included_code() +endif() diff --git a/cmake/settings.cmake b/cmake/settings.cmake index 45fbc9d0a4..5cf9500224 100644 --- a/cmake/settings.cmake +++ b/cmake/settings.cmake @@ -11,16 +11,19 @@ # - UT flags overrides #### include_guard() -# fprime framework is build with C++11 and C99 support, project may override these setting after the inclusion of -# Fprime-Code.cmake. -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - -set(CMAKE_C_STANDARD 99) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS OFF) - +# fprime framework is build with C++11 and C99 support, project may override these settings, but results are not guaranteed +# when overriding for F Prime framework code. +if (NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_CXX_EXTENSIONS OFF) +endif() +if (NOT DEFINED CMAKE_C_STANDARD) + set(CMAKE_C_STANDARD 99) + set(CMAKE_C_STANDARD_REQUIRED ON) + set(CMAKE_C_EXTENSIONS OFF) +endif() + # fprime unit testing methodology requires the following flags if (BUILD_TESTING) add_compile_options(-g -DBUILD_UT -DPROTECTED=public -DPRIVATE=public -DSTATIC=)