Skip to content

Commit 3684699

Browse files
trns1997xiaoxiang781216
authored andcommitted
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 <[email protected]>
1 parent cf41b01 commit 3684699

File tree

5 files changed

+183
-0
lines changed

5 files changed

+183
-0
lines changed

testing/cxx-oot-build/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
nuttx-export*
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/****************************************************************************
2+
* testing/cxx-oot-build/include/HelloWorld.hpp
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of 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
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
#pragma once
24+
25+
class CHelloWorld
26+
{
27+
public:
28+
CHelloWorld();
29+
~CHelloWorld() = default;
30+
31+
bool HelloWorld();
32+
33+
private:
34+
int mSecret;
35+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/****************************************************************************
2+
* testing/cxx-oot-build/src/HelloWorld.cpp
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of 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
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
#include <cstdio>
24+
#include <string>
25+
26+
#include "HelloWorld.hpp"
27+
28+
CHelloWorld::CHelloWorld()
29+
{
30+
mSecret = 42;
31+
std::printf("Constructor: mSecret=%d\n",mSecret);
32+
}
33+
34+
35+
bool CHelloWorld::HelloWorld()
36+
{
37+
std::printf("HelloWorld: mSecret=%d\n",mSecret);
38+
39+
std::string sentence = "Hello";
40+
std::printf("TEST=%s\n",sentence.c_str());
41+
42+
if (mSecret == 42)
43+
{
44+
std::printf("CHelloWorld: HelloWorld: Hello, world!\n");
45+
return true;
46+
}
47+
else
48+
{
49+
std::printf("CHelloWorld: HelloWorld: CONSTRUCTION FAILED!\n");
50+
return false;
51+
}
52+
}

testing/cxx-oot-build/src/main.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/****************************************************************************
2+
* testing/cxx-oot-build/src/main.cpp
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of 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
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
#include <memory>
24+
25+
#include "HelloWorld.hpp"
26+
27+
int main(int, char*[])
28+
{
29+
auto pHelloWorld = std::make_shared<CHelloWorld>();
30+
pHelloWorld->HelloWorld();
31+
32+
CHelloWorld helloWorld;
33+
helloWorld.HelloWorld();
34+
35+
return 0;
36+
}

0 commit comments

Comments
 (0)