-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlibstdcxx.cmake
72 lines (63 loc) · 2.66 KB
/
libstdcxx.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
################################################################################
#
# \file libstdcxx.cmake
# \copyright 2012-2015 J. Bakosi,
# 2016-2018 Los Alamos National Security, LLC.,
# 2019-2021 Triad National Security, LLC.
# All rights reserved. See the LICENSE file for details.
# \brief Find libc++ and offer to switch between libc++ and libstdc++
#
################################################################################
if(__libstdcxx)
return()
endif()
set(__libstdcxx YES)
#### Attempt to find the libc++ library. Do not offer for gnu.
# More infor: libstdc++: http://gcc.gnu.org/libstdc++,
# libc++: http://libcxx.llvm.org.
if (NOT NO_SYSTEM_LIBCXX AND NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
find_package(LIBCXX)
endif()
#### If libc++ found, offer switch between libstdc++ and libc++.
if (LIBCXX_FOUND)
# Offer switch between libstdc++ and libc++ for the C++ standard library, only
# if libc++ has been found. We assume libstdc++ exists.
function(setlibstdcxx LIBCXX_DEFAULT)
# Available options
set(LIBCXX_VALUES "libstdc++" "libc++")
# Initialize all to off
set(LIBCXX_STDCPP off) # 0
set(LIBCXX_CPP off) # 1
# Set default and select from list
set(LIBCXX ${LIBCXX_DEFAULT} CACHE STRING "Select standard C++ library. Available options: ${LIBCXX_VALUES}.")
SET_PROPERTY (CACHE LIBCXX PROPERTY STRINGS ${LIBCXX_VALUES})
STRING (TOLOWER ${LIBCXX} LIBCXX)
LIST (FIND LIBCXX_VALUES ${LIBCXX} LIBCXX_INDEX)
# Evaluate selected option and put in a define for it
IF (${LIBCXX_INDEX} EQUAL 0)
set(LIBCXX_STDCPP on PARENT_SCOPE)
ELSEIF (${LIBCXX_INDEX} EQUAL 1)
set(LIBCXX_CPP on PARENT_SCOPE)
ELSEIF (${LIBCXX_INDEX} EQUAL -1)
MESSAGE(FATAL_ERROR "Standard C++ library '${LIBCXX}' not supported, valid entries are ${LIBCXX_VALUES}.")
ENDIF()
message(STATUS "Standard C++ library (LIBCXX): " ${LIBCXX})
endfunction()
# Evaluate offer for libstdc++ vs libc++ and set compiler flags
# Arguments: FLAGS2ADD2 - The cmake variable to which to add libc++ args to
# DEFAULT - The default to use if user did not select anything
macro(set_libstdcpp_vs_libcpp FLAGS2ADD2 DEFAULT)
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (NOT STDLIBCPP)
setlibstdcxx(${DEFAULT})
else()
setlibstdcxx(${STDLIBCPP})
endif()
if(LIBCXX_CPP) # set compiler flags for use of libc++
set(${FLAGS2ADD2} "${${FLAGS2ADD2}} -stdlib=libc++")
else() # set compiler flags for use of libstdc++
set(${FLAGS2ADD2} "${${FLAGS2ADD2}} -stdlib=libstdc++")
endif()
endif()
endmacro()
endif()