Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions testing/cxx-oot-build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
nuttx-export*
58 changes: 58 additions & 0 deletions testing/cxx-oot-build/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Comment thread
xiaoxiang781216 marked this conversation as resolved.
Comment thread
trns1997 marked this conversation as resolved.

# --- 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()
35 changes: 35 additions & 0 deletions testing/cxx-oot-build/include/HelloWorld.hpp
Original file line number Diff line number Diff line change
@@ -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
Comment thread
trns1997 marked this conversation as resolved.

class CHelloWorld
{
public:
CHelloWorld();
~CHelloWorld() = default;

bool HelloWorld();

private:
int mSecret;
};
52 changes: 52 additions & 0 deletions testing/cxx-oot-build/src/HelloWorld.cpp
Original file line number Diff line number Diff line change
@@ -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>
Comment thread
trns1997 marked this conversation as resolved.
#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;
}
}
36 changes: 36 additions & 0 deletions testing/cxx-oot-build/src/main.cpp
Original file line number Diff line number Diff line change
@@ -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>
Comment thread
trns1997 marked this conversation as resolved.

#include "HelloWorld.hpp"

int main(int, char*[])
{
auto pHelloWorld = std::make_shared<CHelloWorld>();
pHelloWorld->HelloWorld();

CHelloWorld helloWorld;
helloWorld.HelloWorld();

return 0;
}
Loading