[CMAKE] Get rid of the set_cpp macro

Instead of messing with global variables and the like, we introduce two target properties:
 - WITH_CXX_EXCEPTIONS: if you want to use C++ exceptions
 - WITH_CXX_RTTI: if you need RTTI in your module
You can use the newly introduced set_target_cpp_properties function, with WITH_EXCEPTIONS and WITH_RTTI arguments
We also introduce two libraries :
 - cpprt: for C++ runtime routines
 - cppstl: for the C++ standard template library

NB: On GCC, this requires to create imported libraries with the related built-in libraries:libsupc++, limingwex, libstdc++

Finally, we manage the relevant flags with the ad-hoc generator expressions

So, if you don't need exceptions, nor RTTI, nor use any runtime at all: you simply have nothing else to do than add your C++ file to your module
This commit is contained in:
Jérôme Gardou 2020-09-18 09:34:18 +02:00 committed by Jérôme Gardou
parent 980ce77316
commit d6ea8659c8
69 changed files with 193 additions and 259 deletions

View file

@ -1,86 +1,4 @@
# set_cpp
# Marks the current folder as containing C++ modules, additionally enabling
# specific C++ language features as specified (all of these default to off):
#
# WITH_RUNTIME
# Links with the C++ runtime. Enable this for modules which use new/delete or
# RTTI, but do not require STL. This is the right choice if you see undefined
# references to operator new/delete, vector constructor/destructor iterator,
# type_info::vtable, ...
# Note: this only affects linking, so cannot be used for static libraries.
# WITH_RTTI
# Enables run-time type information. Enable this if the module uses typeid or
# dynamic_cast. You will probably need to enable WITH_RUNTIME as well, if
# you're not already using STL.
# WITH_EXCEPTIONS
# Enables C++ exception handling. Enable this if the module uses try/catch or
# throw. You might also need this if you use a standard operator new (the one
# without nothrow).
# WITH_STL
# Enables standard C++ headers and links to the Standard Template Library.
# Use this for modules using anything from the std:: namespace, e.g. maps,
# strings, vectors, etc.
# Note: this affects both compiling (via include directories) and
# linking (by adding STL). Implies WITH_RUNTIME.
# FIXME: WITH_STL is currently also required for runtime headers such as
# <new> and <exception>. This is not a big issue because in stl-less
# environments you usually don't want those anyway; but we might want
# to have modules like this in the future.
#
# Examples:
# set_cpp()
# Enables the C++ language, but will cause errors if any runtime or standard
# library features are used. This should be the default for C++ in kernel
# mode or otherwise restricted environments.
# Note: this is required to get libgcc (for multiplication/division) linked
# in for C++ modules, and to set the correct language for precompiled
# header files, so it IS required even with no features specified.
# set_cpp(WITH_RUNTIME)
# Links with the C++ runtime, so that e.g. custom operator new implementations
# can be used in a restricted environment. This is also required for linking
# with libraries (such as ATL) which have RTTI enabled, even if the module in
# question does not use WITH_RTTI.
# set_cpp(WITH_RTTI WITH_EXCEPTIONS WITH_STL)
# The full package. This will adjust compiler and linker so that all C++
# features can be used.
macro(set_cpp)
cmake_parse_arguments(__cppopts "WITH_RUNTIME;WITH_RTTI;WITH_EXCEPTIONS;WITH_STL" "" "" ${ARGN})
if(__cppopts_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "set_cpp: unparsed arguments ${__cppopts_UNPARSED_ARGUMENTS}")
endif()
if(__cppopts_WITH_RUNTIME)
set(CPP_USE_RT 1)
endif()
if(__cppopts_WITH_RTTI)
if(MSVC)
replace_compile_flags("/GR-" "/GR")
else()
replace_compile_flags_language("-fno-rtti" "-frtti" "CXX")
endif()
endif()
if(__cppopts_WITH_EXCEPTIONS)
if(MSVC)
replace_compile_flags("/EHs-c-" "/EHsc")
else()
replace_compile_flags_language("-fno-exceptions" "-fexceptions" "CXX")
endif()
endif()
if(__cppopts_WITH_STL)
set(CPP_USE_STL 1)
if(MSVC)
add_definitions(-DNATIVE_CPP_INCLUDE=${REACTOS_SOURCE_DIR}/sdk/include/c++)
include_directories(${REACTOS_SOURCE_DIR}/sdk/include/c++/stlport)
else()
replace_compile_flags("-nostdinc" " ")
add_definitions(-DPAL_STDCPP_COMPAT)
endif()
endif()
set(IS_CPP 1)
endmacro()
function(add_dependency_node _node)
if(GENERATE_DEPENDENCY_GRAPH)
get_target_property(_type ${_node} TYPE)
@ -988,3 +906,15 @@ else()
macro(add_pch _target _pch _skip_list)
endmacro()
endif()
function(set_target_cpp_properties _target)
cmake_parse_arguments(_CPP "WITH_EXCEPTIONS;WITH_RTTI" "" "" ${ARGN})
if (_CPP_WITH_EXCEPTIONS)
set_target_properties(${_target} PROPERTIES WITH_CXX_EXCEPTIONS TRUE)
endif()
if (_CPP_WITH_RTTI)
set_target_properties(${_target} PROPERTIES WITH_CXX_RTTI TRUE)
endif()
endfunction()