cmake:enable libxx for CMake build

distinguish whether to add the CXX header file search path
according to the target Language.

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
This commit is contained in:
xuxin19 2024-03-04 17:24:49 +08:00 committed by Xiang Xiao
parent 2b4002d9ad
commit 2c9d46f176
6 changed files with 145 additions and 24 deletions

View File

@ -97,11 +97,11 @@ else()
set(ARCHCXXFLAGS "${ARCHCXXFLAGS} -D_STDLIB_H_")
endif()
if(CONFIG_CXX_EXCEPTION)
if(NOT CONFIG_CXX_EXCEPTION)
string(APPEND ARCHCXXFLAGS " -fno-exceptions -fcheck-new")
endif()
if(CONFIG_CXX_RTTI)
if(NOT CONFIG_CXX_RTTI)
string(APPEND ARCHCXXFLAGS " -fno-rtti")
endif()

View File

@ -26,6 +26,13 @@ function(nuttx_add_library_internal target)
# ensure nuttx_context is created before this
add_dependencies(${target} nuttx_context)
# add specified search directories for CXX targets
target_include_directories(
${target}
PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_CXX_INCLUDE_DIRECTORIES>>>
)
# add main include directories
target_include_directories(
${target} SYSTEM

View File

@ -55,27 +55,18 @@ if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/libcxx)
FetchContent_Populate(libcxx)
endif()
execute_process(
COMMAND
sh -c
"ln -s ${CMAKE_CURRENT_LIST_DIR}/libcxx/include ${NUTTX_DIR}/include/libcxx"
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
execute_process(
COMMAND
sh -c
"cp ${CMAKE_CURRENT_LIST_DIR}/__config_site ${NUTTX_DIR}/include/libcxx/__config_site"
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
endif()
set_property(
TARGET nuttx
APPEND
PROPERTY NUTTX_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/libcxx/include)
nuttx_create_symlink(${CMAKE_CURRENT_LIST_DIR}/libcxx/include
${CMAKE_BINARY_DIR}/include/libcxx)
configure_file(${CMAKE_CURRENT_LIST_DIR}/__config_site
${CMAKE_BINARY_DIR}/include/libcxx/__config_site COPYONLY)
set_property(
TARGET nuttx
APPEND
PROPERTY NUTTX_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/libcxx/src)
PROPERTY NUTTX_CXX_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/include/libcxx)
add_compile_definitions(_LIBCPP_BUILDING_LIBRARY)
if(CONFIG_LIBSUPCXX)
@ -84,6 +75,7 @@ endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
set(SRCS)
set(SRCSTMP)
@ -126,6 +118,11 @@ if(GCCVER GREATER_EQUAL 12)
PROPERTIES COMPILE_FLAGS -Wno-maybe-uninitialized)
endif()
if(GCCVER GREATER_EQUAL 13)
set_source_files_properties(
libcxx/src/string.cpp PROPERTIES COMPILE_FLAGS -Wno-alloc-size-larger-than)
endif()
set_source_files_properties(libcxx/src/barrier.cpp PROPERTIES COMPILE_FLAGS
-Wno-shadow)
set_source_files_properties(libcxx/src/locale.cpp PROPERTIES COMPILE_FLAGS
@ -137,3 +134,10 @@ set_source_files_properties(libcxx/src/condition_variable.cpp
nuttx_add_system_library(libcxx)
target_sources(libcxx PRIVATE ${SRCS})
if(CONFIG_LIBCXXABI)
target_include_directories(
libcxx BEFORE PRIVATE ${CMAKE_CURRENT_LIST_DIR}/libcxxabi/include)
endif()
target_include_directories(libcxx BEFORE
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/libcxx/src)

View File

@ -52,12 +52,6 @@ endif()
nuttx_add_system_library(libcxxabi)
set_property(
TARGET nuttx
APPEND
PROPERTY NUTTX_INCLUDE_DIRECTORIES
${CMAKE_CURRENT_LIST_DIR}/libcxxabi/include)
set(SRCS)
# C++ABI files
@ -103,3 +97,7 @@ endforeach()
target_compile_options(libcxxabi PRIVATE -frtti)
target_sources(libcxxabi PRIVATE ${TARGET_SRCS})
target_compile_options(libcxxabi PRIVATE -frtti)
target_include_directories(
libcxxabi BEFORE PRIVATE ${CMAKE_CURRENT_LIST_DIR}/libcxxabi/include
${CMAKE_CURRENT_LIST_DIR}/libcxx/src)

View File

@ -47,4 +47,4 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set_property(
TARGET nuttx
APPEND
PROPERTY NUTTX_INCLUDE_DIRECTORIES ${NUTTX_DIR}/include/cxx)
PROPERTY NUTTX_CXX_INCLUDE_DIRECTORIES ${NUTTX_DIR}/include/cxx)

112
libs/libxx/uClibc++.cmake Normal file
View File

@ -0,0 +1,112 @@
# ##############################################################################
# libs/libxx/uClibc++.cmake
#
# 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.
#
# ##############################################################################
set(UCLIBCXX_DIR ${CMAKE_CURRENT_LIST_DIR}/uClibc++)
if(NOT EXISTS ${UCLIBCXX_DIR})
set(UCLIBCXX_VERSION 0.2.5)
FetchContent_Declare(
uClibc++
DOWNLOAD_NAME "uClibc++-${UCLIBCXX_VERSION}.tar.bz2"
DOWNLOAD_DIR ${CMAKE_CURRENT_LIST_DIR}
URL "https://git.busybox.net/uClibc++/snapshot/uClibc++-${UCLIBCXX_VERSION}.tar.bz2"
SOURCE_DIR
${CMAKE_CURRENT_LIST_DIR}/uClibc++
BINARY_DIR
${CMAKE_BINARY_DIR}/libs/libc/uClibc++
CONFIGURE_COMMAND
""
BUILD_COMMAND
""
INSTALL_COMMAND
""
TEST_COMMAND
""
PATCH_COMMAND
patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/uClibc++ <
${CMAKE_CURRENT_LIST_DIR}/0001-uClibcxx-basic_definitions-fix-GCC-specific-definiti.patch
&& patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/uClibc++ <
${CMAKE_CURRENT_LIST_DIR}/0001-uclibxx-use-overload-constructor-of-filebuf-ostream.patch
DOWNLOAD_NO_PROGRESS true
TIMEOUT 30)
FetchContent_GetProperties(uClibc++)
if(NOT uClibc++_POPULATED)
FetchContent_Populate(uClibc++)
endif()
endif()
nuttx_create_symlink(${CMAKE_CURRENT_LIST_DIR}/uClibc++/include
${CMAKE_BINARY_DIR}/include/uClibc++)
configure_file(
${CMAKE_CURRENT_LIST_DIR}/system_configuration.h
${CMAKE_BINARY_DIR}/include/uClibc++/system_configuration.h COPYONLY)
set_property(
TARGET nuttx
APPEND
PROPERTY NUTTX_CXX_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/include/uClibc++)
set(SRCS
algorithm.cpp
associative_base.cpp
bitset.cpp
char_traits.cpp
complex.cpp
deque.cpp
exception.cpp
fstream.cpp
func_exception.cpp
iomanip.cpp
ios.cpp
iostream.cpp
istream.cpp
iterator.cpp
limits.cpp
list.cpp
locale.cpp
map.cpp
numeric.cpp
ostream.cpp
queue.cpp
set.cpp
sstream.cpp
stack.cpp
stdexcept.cpp
streambuf.cpp
string.cpp
utility.cpp
valarray.cpp
vector.cpp)
set(TARGET_SRCS)
foreach(src ${SRCS})
string(PREPEND src uClibc++/src/)
list(APPEND TARGET_SRCS ${src})
endforeach()
nuttx_add_system_library(uClibc++)
target_sources(uClibc++ PRIVATE ${TARGET_SRCS})