|
| 1 | +# |
| 2 | +# Core Flight Software CMake / GNU make wrapper |
| 3 | +# |
| 4 | +# ABOUT THIS MAKEFILE: |
| 5 | +# It is a GNU-make wrapper that calls the CMake tools appropriately |
| 6 | +# so that setting up a new build is fast and easy with no need to |
| 7 | +# learn the CMake commands. It also makes it easier to integrate |
| 8 | +# the build with IDE tools such as Eclipse by providing a default |
| 9 | +# makefile that has the common targets such as all/clean/etc. |
| 10 | +# |
| 11 | +# Use of this file is optional. |
| 12 | +# |
| 13 | +# This file is intended to be placed at the TOP-MOST level of the mission |
| 14 | +# source tree, i.e. a level above "cfe". Note this is outside the cfe |
| 15 | +# repository which is why it cannot be delivered directly in place. |
| 16 | +# To use it, simply copy it to the top directory. As this just contains |
| 17 | +# wrappers for the CMake targets, it is unlikely to change. Projects |
| 18 | +# are also free to customize this file and add their own targets after |
| 19 | +# copying it to the top of the source tree. |
| 20 | +# |
| 21 | +# For _ALL_ targets defined in this file the build tree location may |
| 22 | +# be specified via the "O" variable (i.e. make O=<my-build-dir> all). |
| 23 | +# If not specified then the "build" subdirectory will be assumed. |
| 24 | +# |
| 25 | +# This wrapper defines the following major targets: |
| 26 | +# prep -- Runs CMake to create a new or re-configure an existing build tree |
| 27 | +# Note that multiple build trees can exist from a single source |
| 28 | +# Other control options (such as "SIMULATION") may be passed to CMake via |
| 29 | +# make variables depending on the mission build scripts. These will be |
| 30 | +# cached in the build tree so they do not need to be set again thereafter. |
| 31 | +# |
| 32 | +# all -- Build all targets in the CMake build tree |
| 33 | +# |
| 34 | +# install -- Copy all files to the installation tree and run packaging scripts |
| 35 | +# The "DESTDIR" environment variable controls where the files are copied |
| 36 | +# |
| 37 | +# clean -- Clean all targets in the CMake build tree, but not the build tree itself. |
| 38 | +# |
| 39 | +# distclean -- Entirely remove the build directory specified by "O" |
| 40 | +# Note that after this the "prep" step must be run again in order to build. |
| 41 | +# Use caution with this as it does an rm -rf - don't set O to your home dir! |
| 42 | +# |
| 43 | +# doc -- Build all doxygen source documentation. The HTML documentation will be |
| 44 | +# generated under the build tree specified by "O". |
| 45 | +# |
| 46 | +# usersguide -- Build all API/Cmd/Tlm doxygen documentation. The HTML documentation |
| 47 | +# will be generated under the build tree specified by "O". |
| 48 | +# |
| 49 | +# osalguide -- Build OSAL API doxygen documentation. The HTML documentation will |
| 50 | +# be generated under the build tree specified by "O". |
| 51 | +# |
| 52 | +# test -- Run all unit tests defined in the build. Unit tests will typically only |
| 53 | +# be executable when building with the "SIMULATION=native" option. Otherwise |
| 54 | +# it is up to the user to copy the executables to the target and run them. |
| 55 | +# |
| 56 | +# lcov -- Runs the "lcov" tool on the build tree to collect all code coverage |
| 57 | +# analysis data and build the reports. Code coverage data may be output by |
| 58 | +# the "make test" target above. |
| 59 | +# |
| 60 | + |
| 61 | +# Establish default values for critical variables. Any of these may be overridden |
| 62 | +# on the command line or via the make environment configuration in an IDE |
| 63 | +O ?= build |
| 64 | +ARCH ?= native/default_cpu1 |
| 65 | +BUILDTYPE ?= debug |
| 66 | +INSTALLPREFIX ?= /exe |
| 67 | +DESTDIR ?= $(O) |
| 68 | + |
| 69 | +# The "DESTDIR" variable is a bit more complicated because it should be an absolute |
| 70 | +# path for CMake, but we want to accept either absolute or relative paths. So if |
| 71 | +# the path does NOT start with "/", prepend it with the current directory. |
| 72 | +ifeq ($(filter /%, $(DESTDIR)),) |
| 73 | +DESTDIR := $(CURDIR)/$(DESTDIR) |
| 74 | +endif |
| 75 | + |
| 76 | +# The "LOCALTGTS" defines the top-level targets that are implemented in this makefile |
| 77 | +# Any other target may also be given, in that case it will simply be passed through. |
| 78 | +LOCALTGTS := doc usersguide osalguide prep all clean install distclean test lcov |
| 79 | +OTHERTGTS := $(filter-out $(LOCALTGTS),$(MAKECMDGOALS)) |
| 80 | + |
| 81 | +# As this makefile does not build any real files, treat everything as a PHONY target |
| 82 | +# This ensures that the rule gets executed even if a file by that name does exist |
| 83 | +.PHONY: $(LOCALTGTS) $(OTHERTGTS) |
| 84 | + |
| 85 | +# If the target name appears to be a directory (ends in /), do a make all in that directory |
| 86 | +DIRTGTS := $(filter %/,$(OTHERTGTS)) |
| 87 | +ifneq ($(DIRTGTS),) |
| 88 | +$(DIRTGTS): |
| 89 | + $(MAKE) -C $(O)/$(patsubst $(O)/%,%,$(@)) all |
| 90 | +endif |
| 91 | + |
| 92 | +# For any other goal that is not one of the known local targets, pass it to the arch build |
| 93 | +# as there might be a target by that name. For example, this is useful for rebuilding |
| 94 | +# single unit test executable files while debugging from the IDE |
| 95 | +FILETGTS := $(filter-out $(DIRTGTS),$(OTHERTGTS)) |
| 96 | +ifneq ($(FILETGTS),) |
| 97 | +$(FILETGTS): |
| 98 | + $(MAKE) -C $(O)/$(ARCH) $(@) |
| 99 | +endif |
| 100 | + |
| 101 | +# The "prep" step requires extra options that are specified via environment variables. |
| 102 | +# Certain special ones should be passed via cache (-D) options to CMake. |
| 103 | +# These are only needed for the "prep" target but they are computed globally anyway. |
| 104 | +PREP_OPTS := |
| 105 | + |
| 106 | +ifneq ($(INSTALLPREFIX),) |
| 107 | +PREP_OPTS += -DCMAKE_INSTALL_PREFIX=$(INSTALLPREFIX) |
| 108 | +endif |
| 109 | + |
| 110 | +ifneq ($(VERBOSE),) |
| 111 | +PREP_OPTS += --trace |
| 112 | +endif |
| 113 | + |
| 114 | +ifneq ($(BUILDTYPE),) |
| 115 | +PREP_OPTS += -DCMAKE_BUILD_TYPE=$(BUILDTYPE) |
| 116 | +endif |
| 117 | + |
| 118 | +ifneq ($(CMAKE_PREFIX_PATH),) |
| 119 | +PREP_OPTS += -DCMAKE_PREFIX_PATH=$(CMAKE_PREFIX_PATH) |
| 120 | +endif |
| 121 | + |
| 122 | +all: |
| 123 | + $(MAKE) --no-print-directory -C "$(O)" mission-all |
| 124 | + |
| 125 | +install: |
| 126 | + $(MAKE) --no-print-directory -C "$(O)" DESTDIR="$(DESTDIR)" mission-install |
| 127 | + |
| 128 | +prep $(O)/.prep: |
| 129 | + mkdir -p "$(O)" |
| 130 | + (cd "$(O)" && cmake $(PREP_OPTS) "$(CURDIR)/cfe") |
| 131 | + echo "$(PREP_OPTS)" > "$(O)/.prep" |
| 132 | + |
| 133 | +clean: |
| 134 | + $(MAKE) --no-print-directory -C "$(O)" mission-clean |
| 135 | + |
| 136 | +distclean: |
| 137 | + rm -rf "$(O)" |
| 138 | + |
| 139 | +# Grab lcov baseline before running tests |
| 140 | +test: |
| 141 | + lcov --capture --initial --directory $(O)/$(ARCH) --output-file $(O)/$(ARCH)/coverage_base.info |
| 142 | + (cd $(O)/$(ARCH) && ctest -O ctest.log) |
| 143 | + |
| 144 | +lcov: |
| 145 | + lcov --capture --rc lcov_branch_coverage=1 --directory $(O)/$(ARCH) --output-file $(O)/$(ARCH)/coverage_test.info |
| 146 | + lcov --rc lcov_branch_coverage=1 --add-tracefile $(O)/$(ARCH)/coverage_base.info --add-tracefile $(O)/$(ARCH)/coverage_test.info --output-file $(O)/$(ARCH)/coverage_total.info |
| 147 | + genhtml $(O)/$(ARCH)/coverage_total.info --branch-coverage --output-directory $(O)/$(ARCH)/lcov |
| 148 | + @/bin/echo -e "\n\nCoverage Report Link: file:$(CURDIR)/$(O)/$(ARCH)/lcov/index.html\n" |
| 149 | + |
| 150 | +doc: |
| 151 | + $(MAKE) --no-print-directory -C "$(O)" mission-doc |
| 152 | + |
| 153 | +usersguide: |
| 154 | + $(MAKE) --no-print-directory -C "$(O)" cfe-usersguide |
| 155 | + |
| 156 | +osalguide: |
| 157 | + $(MAKE) --no-print-directory -C "$(O)" osal-apiguide |
| 158 | + |
| 159 | +# Make all the commands that use the build tree depend on a flag file |
| 160 | +# that is used to indicate the prep step has been done. This way |
| 161 | +# the prep step does not need to be done explicitly by the user |
| 162 | +# as long as the default options are sufficient. |
| 163 | +$(filter-out prep distclean,$(LOCALTGTS)): $(O)/.prep |
0 commit comments