fix: cmake & noexcept (#126)
This commit is contained in:
parent
86be305db8
commit
b4cdb6527e
@ -7,7 +7,7 @@ project(aimrt LANGUAGES C CXX)
|
||||
|
||||
# Prevent variables from being reset by option
|
||||
# This setting allows predefined variables to take precedence for FetchContent_MakeAvailable()
|
||||
# see: https://cmake.org/cmake/help/latest/policy/CMP0077.html
|
||||
# See: https://cmake.org/cmake/help/latest/policy/CMP0077.html
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
|
||||
|
||||
# Set cmake path
|
||||
@ -17,13 +17,16 @@ include(CMakeDependentOption)
|
||||
|
||||
# Some option
|
||||
option(AIMRT_BUILD_TESTS "AimRT build tests." OFF)
|
||||
option(AIMRT_BUILD_EXAMPLES "AimRT build examples." OFF)
|
||||
option(AIMRT_BUILD_DOCUMENT "AimRT build document." OFF)
|
||||
option(AIMRT_BUILD_RUNTIME "AimRT build runtime." ON)
|
||||
option(AIMRT_BUILD_CLI_TOOLS "AimRT build aimrt command line tools." OFF)
|
||||
option(AIMRT_BUILD_WITH_PROTOBUF "AimRT build with protobuf." ON)
|
||||
option(AIMRT_BUILD_WITH_ROS2 "AimRT build with ros2." OFF)
|
||||
|
||||
option(AIMRT_INSTALL "Enable installation of AimRT." ON)
|
||||
|
||||
cmake_dependent_option(AIMRT_BUILD_EXAMPLES "AimRT build examples." OFF "AIMRT_BUILD_RUNTIME" OFF)
|
||||
|
||||
cmake_dependent_option(AIMRT_BUILD_PYTHON_RUNTIME "AimRT build python runtime." OFF "AIMRT_BUILD_RUNTIME" OFF)
|
||||
cmake_dependent_option(AIMRT_BUILD_PYTHON_PACKAGE "AimRT build python package." OFF "AIMRT_BUILD_PYTHON_RUNTIME;AIMRT_INSTALL" OFF)
|
||||
|
||||
@ -46,8 +49,6 @@ cmake_dependent_option(AIMRT_BUILD_LOG_CONTROL_PLUGIN "AimRT build log control p
|
||||
cmake_dependent_option(AIMRT_BUILD_GRPC_PLUGIN "AimRT build grpc plugin." OFF "AIMRT_BUILD_RUNTIME" OFF)
|
||||
cmake_dependent_option(AIMRT_BUILD_PROXY_PLUGIN "AimRT build proxy plugin." OFF "AIMRT_BUILD_RUNTIME" OFF)
|
||||
|
||||
option(AIMRT_INSTALL "Enable installation of AimRT." ON)
|
||||
|
||||
option(AIMRT_EXECUTOR_USE_STDEXEC "AimRT use stdexec as executor impl. (Experimental)" OFF)
|
||||
option(AIMRT_BUILD_WITH_WERROR "AimRT build with -Werror option. (Experimental)" OFF)
|
||||
|
||||
@ -95,12 +96,10 @@ if(AIMRT_MASTER_PROJECT)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
add_compile_options(/utf-8 /wd4819)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus")
|
||||
endif()
|
||||
@ -180,7 +179,7 @@ if(AIMRT_BUILD_WITH_PROTOBUF)
|
||||
endif()
|
||||
|
||||
if(AIMRT_BUILD_WITH_ROS2)
|
||||
# fix cmake policy for using FindPythonInterp and FindPythonLibs (ros2)
|
||||
# Fix cmake policy for using FindPythonInterp and FindPythonLibs (ros2)
|
||||
if(POLICY CMP0148)
|
||||
cmake_policy(SET CMP0148 OLD)
|
||||
endif()
|
||||
@ -227,7 +226,7 @@ if(AIMRT_BUILD_RUNTIME)
|
||||
endif()
|
||||
|
||||
if(AIMRT_BUILD_ICEORYX_PLUGIN)
|
||||
# try to find libacl
|
||||
# Try to find libacl
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Linux|QNX")
|
||||
find_library(ACL_LIB acl)
|
||||
if(NOT ACL_LIB)
|
||||
@ -247,7 +246,7 @@ if(AIMRT_BUILD_RUNTIME)
|
||||
endif()
|
||||
|
||||
if(AIMRT_BUILD_ZENOH_PLUGIN)
|
||||
# find Rust compiler
|
||||
# Find Rust compiler
|
||||
execute_process(
|
||||
COMMAND rustc --version
|
||||
RESULT_VARIABLE rustc_result
|
||||
@ -293,9 +292,7 @@ if(AIMRT_INSTALL)
|
||||
endif()
|
||||
|
||||
# Put at last to ensure ros2 installation is done
|
||||
if(AIMRT_INSTALL
|
||||
AND AIMRT_BUILD_PYTHON_RUNTIME
|
||||
AND AIMRT_BUILD_PYTHON_PACKAGE)
|
||||
if(AIMRT_BUILD_PYTHON_PACKAGE)
|
||||
install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" --build \"${CMAKE_BINARY_DIR}\" --config ${CMAKE_BUILD_TYPE} --target create_python_pkg)")
|
||||
endif()
|
||||
|
||||
|
@ -17,6 +17,6 @@ if(AIMRT_BUILD_RUNTIME)
|
||||
add_subdirectory(plugins)
|
||||
endif()
|
||||
|
||||
if(AIMRT_BUILD_RUNTIME AND AIMRT_BUILD_EXAMPLES)
|
||||
if(AIMRT_BUILD_EXAMPLES)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
|
@ -9,8 +9,6 @@ if(AIMRT_BUILD_WITH_ROS2)
|
||||
add_subdirectory(ros2_util)
|
||||
endif()
|
||||
|
||||
if(AIMRT_BUILD_RUNTIME)
|
||||
if(AIMRT_BUILD_NET_PLUGIN OR AIMRT_BUILD_GRPC_PLUGIN)
|
||||
add_subdirectory(net)
|
||||
endif()
|
||||
if(AIMRT_BUILD_NET_PLUGIN OR AIMRT_BUILD_GRPC_PLUGIN)
|
||||
add_subdirectory(net)
|
||||
endif()
|
||||
|
@ -36,12 +36,6 @@ concept FunctionCStyleOps =
|
||||
std::is_same_v<void (*)(void*), decltype(T::destroyer)> &&
|
||||
DecayedType<typename InvokerTraitsHelper<decltype(T::invoker)>::ReturnType>;
|
||||
|
||||
/*
|
||||
TODO:
|
||||
1. noexcept类型
|
||||
2. operator()方法在加上Args的类型限制
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Function
|
||||
* @note 由定义好的C Style类型ops构造,可以直接使用NativeHandle与C互调
|
||||
@ -131,8 +125,9 @@ class Function<Ops> {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// TODO:加上Args的类型限制
|
||||
template <typename... Args>
|
||||
R operator()(Args... args) const {
|
||||
R operator()(Args... args) const noexcept {
|
||||
return static_cast<const OpsType*>(base_.ops)->invoker(&(base_.object_buf), args...);
|
||||
}
|
||||
|
||||
@ -147,17 +142,17 @@ class Function<Ops> {
|
||||
|
||||
if constexpr (sizeof(Decayed) <= sizeof(base_.object_buf)) {
|
||||
static constexpr OpsType kOps = {
|
||||
.invoker = [](void* object, std::tuple_element_t<Idx, ArgsTuple>... args) -> R {
|
||||
.invoker = [](void* object, std::tuple_element_t<Idx, ArgsTuple>... args) noexcept -> R {
|
||||
if constexpr (std::is_void_v<R>) {
|
||||
std::invoke(*static_cast<Decayed*>(object), args...);
|
||||
} else {
|
||||
return std::invoke(*static_cast<Decayed*>(object), args...);
|
||||
}
|
||||
},
|
||||
.relocator = [](void* from, void* to) {
|
||||
.relocator = [](void* from, void* to) noexcept {
|
||||
new (to) Decayed(std::move(*static_cast<Decayed*>(from)));
|
||||
static_cast<Decayed*>(from)->~Decayed(); },
|
||||
.destroyer = [](void* object) { static_cast<Decayed*>(object)->~Decayed(); }};
|
||||
.destroyer = [](void* object) noexcept { static_cast<Decayed*>(object)->~Decayed(); }};
|
||||
|
||||
base_.ops = &kOps;
|
||||
new (&(base_.object_buf)) Decayed(std::forward<T>(action));
|
||||
@ -165,15 +160,15 @@ class Function<Ops> {
|
||||
using Stored = Decayed*;
|
||||
|
||||
static constexpr OpsType kOps = {
|
||||
.invoker = [](void* object, std::tuple_element_t<Idx, ArgsTuple>... args) -> R {
|
||||
.invoker = [](void* object, std::tuple_element_t<Idx, ArgsTuple>... args) noexcept -> R {
|
||||
if constexpr (std::is_void_v<R>) {
|
||||
std::invoke(**static_cast<Stored*>(object), args...);
|
||||
} else {
|
||||
return std::invoke(**static_cast<Stored*>(object), args...);
|
||||
}
|
||||
},
|
||||
.relocator = [](void* from, void* to) { new (to) Stored(*static_cast<Stored*>(from)); },
|
||||
.destroyer = [](void* object) { delete *static_cast<Stored*>(object); }};
|
||||
.relocator = [](void* from, void* to) noexcept { new (to) Stored(*static_cast<Stored*>(from)); },
|
||||
.destroyer = [](void* object) noexcept { delete *static_cast<Stored*>(object); }};
|
||||
|
||||
base_.ops = &kOps;
|
||||
new (&(base_.object_buf)) Stored(new Decayed(std::forward<T>(action)));
|
||||
|
@ -191,6 +191,8 @@ void AimRTCore::StartImpl() {
|
||||
void AimRTCore::ShutdownImpl() {
|
||||
if (std::atomic_exchange(&shutdown_impl_flag_, true)) return;
|
||||
|
||||
AIMRT_INFO("AimRT start shutdown.");
|
||||
|
||||
EnterState(State::kPreShutdown);
|
||||
|
||||
EnterState(State::kPreShutdownModules);
|
||||
@ -271,6 +273,8 @@ std::future<void> AimRTCore::AsyncStart() {
|
||||
void AimRTCore::Shutdown() {
|
||||
if (std::atomic_exchange(&shutdown_flag_, true)) return;
|
||||
|
||||
AIMRT_INFO("Received shutdown signal.");
|
||||
|
||||
shutdown_promise_.set_value();
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,6 @@ if(AIMRT_BUILD_CLI_TOOLS)
|
||||
add_subdirectory(aimrt_cli)
|
||||
endif()
|
||||
|
||||
if(AIMRT_BUILD_PYTHON_RUNTIME AND AIMRT_BUILD_PYTHON_PACKAGE)
|
||||
if(AIMRT_BUILD_PYTHON_PACKAGE)
|
||||
add_subdirectory(package_aimrt_py)
|
||||
endif()
|
||||
|
Loading…
x
Reference in New Issue
Block a user