|
| 1 | +# ############################################################################## |
| 2 | +# testing/cxx-oot-build/CMakeLists.txt |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | +# |
| 6 | +# Licensed to the Apache Software Foundation (ASF) under one or more contributor |
| 7 | +# license agreements. See the NOTICE file distributed with this work for |
| 8 | +# additional information regarding copyright ownership. The ASF licenses this |
| 9 | +# file to you under the Apache License, Version 2.0 (the "License"); you may not |
| 10 | +# use this file except in compliance with the License. You may obtain a copy of |
| 11 | +# the License at |
| 12 | +# |
| 13 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +# |
| 15 | +# Unless required by applicable law or agreed to in writing, software |
| 16 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 17 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 18 | +# License for the specific language governing permissions and limitations under |
| 19 | +# the License. |
| 20 | +# |
| 21 | +# ############################################################################## |
| 22 | + |
| 23 | +cmake_minimum_required(VERSION 3.12...3.31) |
| 24 | + |
| 25 | +# --- Guard option --- |
| 26 | +option(BUILD_OOTCPP "Build the Out Of Tree C++ project" OFF) |
| 27 | + |
| 28 | +if(BUILD_OOTCPP) |
| 29 | + project( |
| 30 | + OOTCpp |
| 31 | + VERSION 1.0 |
| 32 | + DESCRIPTION "Out Of Tree Build C++ NuttX") |
| 33 | + |
| 34 | + message(STATUS "Building OOTCpp project") |
| 35 | + |
| 36 | + set(CMAKE_CXX_STANDARD 17) |
| 37 | + set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 38 | + |
| 39 | + set(SOURCE_FILES ${CMAKE_SOURCE_DIR}/src/HelloWorld.cpp |
| 40 | + ${CMAKE_SOURCE_DIR}/src/main.cpp) |
| 41 | + |
| 42 | + set(EXE_NAME oot) |
| 43 | + |
| 44 | + add_executable(${EXE_NAME} ${SOURCE_FILES}) |
| 45 | + |
| 46 | + target_include_directories(${EXE_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include) |
| 47 | + |
| 48 | + # Generate a .bin file from the ELF after build |
| 49 | + add_custom_command( |
| 50 | + TARGET ${EXE_NAME} |
| 51 | + POST_BUILD |
| 52 | + COMMAND ${CMAKE_OBJCOPY} -S -O binary ${CMAKE_BINARY_DIR}/${EXE_NAME} |
| 53 | + ${CMAKE_BINARY_DIR}/${EXE_NAME}.bin |
| 54 | + COMMENT "Generating binary image ${EXE_NAME}.bin") |
| 55 | + |
| 56 | +else() |
| 57 | + message(STATUS "Skipping OOTCpp project") |
| 58 | +endif() |
0 commit comments