testing/cxx-oot-build: Add out-of-tree build test.

Add the source content for the out-of-tree build test
under `apps/testing/cxx-oot-build`. This supports the
new CI check in NuttX to prevent regressions in the
`make export` workflow.

The test project provides:
* Sample OOT build structure.
* Integration with exported `nuttx-export`.
* Verification of successful build and link.

Signed-off-by: trns1997 <trns1997@gmail.com>
This commit is contained in:
trns1997 2025-09-18 13:30:24 +02:00 committed by Xiang Xiao
parent cf41b01135
commit 3684699190
5 changed files with 183 additions and 0 deletions

2
testing/cxx-oot-build/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
build/
nuttx-export*

View file

@ -0,0 +1,58 @@
# ##############################################################################
# testing/cxx-oot-build/CMakeLists.txt
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
cmake_minimum_required(VERSION 3.12...3.31)
# --- Guard option ---
option(BUILD_OOTCPP "Build the Out Of Tree C++ project" OFF)
if(BUILD_OOTCPP)
project(
OOTCpp
VERSION 1.0
DESCRIPTION "Out Of Tree Build C++ NuttX")
message(STATUS "Building OOTCpp project")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SOURCE_FILES ${CMAKE_SOURCE_DIR}/src/HelloWorld.cpp
${CMAKE_SOURCE_DIR}/src/main.cpp)
set(EXE_NAME oot)
add_executable(${EXE_NAME} ${SOURCE_FILES})
target_include_directories(${EXE_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include)
# Generate a .bin file from the ELF after build
add_custom_command(
TARGET ${EXE_NAME}
POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -S -O binary ${CMAKE_BINARY_DIR}/${EXE_NAME}
${CMAKE_BINARY_DIR}/${EXE_NAME}.bin
COMMENT "Generating binary image ${EXE_NAME}.bin")
else()
message(STATUS "Skipping OOTCpp project")
endif()

View file

@ -0,0 +1,35 @@
/****************************************************************************
* testing/cxx-oot-build/include/HelloWorld.hpp
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#pragma once
class CHelloWorld
{
public:
CHelloWorld();
~CHelloWorld() = default;
bool HelloWorld();
private:
int mSecret;
};

View file

@ -0,0 +1,52 @@
/****************************************************************************
* testing/cxx-oot-build/src/HelloWorld.cpp
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#include <cstdio>
#include <string>
#include "HelloWorld.hpp"
CHelloWorld::CHelloWorld()
{
mSecret = 42;
std::printf("Constructor: mSecret=%d\n",mSecret);
}
bool CHelloWorld::HelloWorld()
{
std::printf("HelloWorld: mSecret=%d\n",mSecret);
std::string sentence = "Hello";
std::printf("TEST=%s\n",sentence.c_str());
if (mSecret == 42)
{
std::printf("CHelloWorld: HelloWorld: Hello, world!\n");
return true;
}
else
{
std::printf("CHelloWorld: HelloWorld: CONSTRUCTION FAILED!\n");
return false;
}
}

View file

@ -0,0 +1,36 @@
/****************************************************************************
* testing/cxx-oot-build/src/main.cpp
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#include <memory>
#include "HelloWorld.hpp"
int main(int, char*[])
{
auto pHelloWorld = std::make_shared<CHelloWorld>();
pHelloWorld->HelloWorld();
CHelloWorld helloWorld;
helloWorld.HelloWorld();
return 0;
}