Skip to content

Commit ce49756

Browse files
committed
oot ci build test
1 parent bc73779 commit ce49756

File tree

5 files changed

+94
-0
lines changed

5 files changed

+94
-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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
cmake_minimum_required(VERSION 3.12...3.31)
2+
3+
project(OOTCpp
4+
VERSION 1.0
5+
DESCRIPTION "Out Of Tree Build C++ NuttX"
6+
)
7+
8+
set(CMAKE_CXX_STANDARD 17)
9+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
10+
11+
# Use CMAKE_SOURCE_DIR for source files
12+
set(SOURCE_FILES
13+
${CMAKE_SOURCE_DIR}/src/HelloWorld.cpp
14+
${CMAKE_SOURCE_DIR}/src/main.cpp
15+
)
16+
17+
set(EXE_NAME oot)
18+
19+
add_executable(${EXE_NAME} ${SOURCE_FILES})
20+
21+
# Add include directory so you can #include "..." from include/
22+
target_include_directories(${EXE_NAME}
23+
PRIVATE
24+
${CMAKE_SOURCE_DIR}/include
25+
)
26+
27+
# Generate a .bin file from the ELF after build
28+
add_custom_command(
29+
TARGET ${EXE_NAME}
30+
POST_BUILD
31+
COMMAND ${CMAKE_OBJCOPY} -S -O binary
32+
${CMAKE_BINARY_DIR}/${EXE_NAME}
33+
${CMAKE_BINARY_DIR}/${EXE_NAME}.bin
34+
COMMENT "Generating binary image ${EXE_NAME}.bin"
35+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
class CHelloWorld
4+
{
5+
public:
6+
CHelloWorld();
7+
~CHelloWorld() = default;
8+
9+
bool HelloWorld();
10+
11+
private:
12+
int mSecret;
13+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <cstdio>
2+
#include <string>
3+
4+
#include "HelloWorld.hpp"
5+
6+
CHelloWorld::CHelloWorld()
7+
{
8+
mSecret = 42;
9+
std::printf("Constructor: mSecret=%d\n",mSecret);
10+
}
11+
12+
13+
bool CHelloWorld::HelloWorld()
14+
{
15+
std::printf("HelloWorld: mSecret=%d\n",mSecret);
16+
17+
std::string sentence = "Hello";
18+
std::printf("TEST=%s\n",sentence.c_str());
19+
20+
if (mSecret == 42)
21+
{
22+
std::printf("CHelloWorld: HelloWorld: Hello, world!\n");
23+
return true;
24+
}
25+
else
26+
{
27+
std::printf("CHelloWorld: HelloWorld: CONSTRUCTION FAILED!\n");
28+
return false;
29+
}
30+
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <memory>
2+
3+
#include "HelloWorld.hpp"
4+
5+
int main(int, char*[])
6+
{
7+
auto pHelloWorld = std::make_shared<CHelloWorld>();
8+
pHelloWorld->HelloWorld();
9+
10+
CHelloWorld helloWorld;
11+
helloWorld.HelloWorld();
12+
13+
return 0;
14+
}

0 commit comments

Comments
 (0)