Skip to content

Commit 0af67d1

Browse files
committed
[runtimes] Move common functions from Handle{Libcxx,Libcxxabi,Libunwind}Flags.cmake to runtimes/cmake/Modules/HandleFlags.cmake
Reviewed By: phosek, #libunwind, #libc, #libc_abi Spies: arichardson, libcxx-commits Differential Revision: https://reviews.llvm.org/D144395
1 parent bbb58a2 commit 0af67d1

File tree

7 files changed

+119
-334
lines changed

7 files changed

+119
-334
lines changed

libcxx/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
1212
list(INSERT CMAKE_MODULE_PATH 0
1313
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
1414
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
15+
"${CMAKE_CURRENT_SOURCE_DIR}/../runtimes/cmake/Modules"
1516
"${LLVM_COMMON_CMAKE_UTILS}"
1617
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
1718
)

libcxx/cmake/Modules/HandleLibcxxFlags.cmake

Lines changed: 1 addition & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -5,102 +5,10 @@
55
# - LIBCXX_LIBRARIES: libraries to link libc++ to.
66

77
include(CheckCXXCompilerFlag)
8+
include(HandleFlags)
89

910
unset(add_flag_if_supported)
1011

11-
# Mangle the name of a compiler flag into a valid CMake identifier.
12-
# Ex: --std=c++11 -> STD_EQ_CXX11
13-
macro(mangle_name str output)
14-
string(STRIP "${str}" strippedStr)
15-
string(REGEX REPLACE "^/" "" strippedStr "${strippedStr}")
16-
string(REGEX REPLACE "^-+" "" strippedStr "${strippedStr}")
17-
string(REGEX REPLACE "-+$" "" strippedStr "${strippedStr}")
18-
string(REPLACE "-" "_" strippedStr "${strippedStr}")
19-
string(REPLACE ":" "_COLON_" strippedStr "${strippedStr}")
20-
string(REPLACE "=" "_EQ_" strippedStr "${strippedStr}")
21-
string(REPLACE "+" "X" strippedStr "${strippedStr}")
22-
string(TOUPPER "${strippedStr}" ${output})
23-
endmacro()
24-
25-
# Remove a list of flags from all CMake variables that affect compile flags.
26-
# This can be used to remove unwanted flags specified on the command line
27-
# or added in other parts of LLVM's cmake configuration.
28-
macro(remove_flags)
29-
foreach(var ${ARGN})
30-
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
31-
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
32-
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
33-
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
34-
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
35-
string(REPLACE "${var}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
36-
string(REPLACE "${var}" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
37-
string(REPLACE "${var}" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
38-
string(REPLACE "${var}" "" CMAKE_SHARED_MODULE_FLAGS "${CMAKE_SHARED_MODULE_FLAGS}")
39-
remove_definitions(${var})
40-
endforeach()
41-
endmacro(remove_flags)
42-
43-
macro(check_flag_supported flag)
44-
mangle_name("${flag}" flagname)
45-
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
46-
endmacro()
47-
48-
macro(append_flags DEST)
49-
foreach(value ${ARGN})
50-
list(APPEND ${DEST} ${value})
51-
list(APPEND ${DEST} ${value})
52-
endforeach()
53-
endmacro()
54-
55-
# If the specified 'condition' is true then append the specified list of flags to DEST
56-
macro(append_flags_if condition DEST)
57-
if (${condition})
58-
list(APPEND ${DEST} ${ARGN})
59-
endif()
60-
endmacro()
61-
62-
# Add each flag in the list specified by DEST if that flag is supported by the current compiler.
63-
macro(append_flags_if_supported DEST)
64-
foreach(flag ${ARGN})
65-
mangle_name("${flag}" flagname)
66-
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
67-
append_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${DEST} ${flag})
68-
endforeach()
69-
endmacro()
70-
71-
# Add a macro definition if condition is true.
72-
macro(define_if condition def)
73-
if (${condition})
74-
add_definitions(${def})
75-
endif()
76-
endmacro()
77-
78-
# Add a macro definition if condition is not true.
79-
macro(define_if_not condition def)
80-
if (NOT ${condition})
81-
add_definitions(${def})
82-
endif()
83-
endmacro()
84-
85-
# Add a macro definition to the __config_site file if the specified condition
86-
# is 'true'. Note that '-D${def}' is not added. Instead it is expected that
87-
# the build include the '__config_site' header.
88-
macro(config_define_if condition def)
89-
if (${condition})
90-
set(${def} ON)
91-
endif()
92-
endmacro()
93-
94-
macro(config_define_if_not condition def)
95-
if (NOT ${condition})
96-
set(${def} ON)
97-
endif()
98-
endmacro()
99-
100-
macro(config_define value def)
101-
set(${def} ${value})
102-
endmacro()
103-
10412
# Add a list of flags to all of 'CMAKE_CXX_FLAGS', 'CMAKE_C_FLAGS',
10513
# 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS'.
10614
macro(add_target_flags)
@@ -224,11 +132,6 @@ macro(add_library_flags_if condition)
224132
endif()
225133
endmacro()
226134

227-
# Turn a comma separated CMake list into a space separated string.
228-
macro(split_list listname)
229-
string(REPLACE ";" " " ${listname} "${${listname}}")
230-
endmacro()
231-
232135
# For each specified flag, add that link flag to the provided target.
233136
# The flags are added with the given visibility, i.e. PUBLIC|PRIVATE|INTERFACE.
234137
function(target_add_link_flags_if_supported target visibility)
@@ -240,15 +143,3 @@ function(target_add_link_flags_if_supported target visibility)
240143
endif()
241144
endforeach()
242145
endfunction()
243-
244-
# For each specified flag, add that compile flag to the provided target.
245-
# The flags are added with the given visibility, i.e. PUBLIC|PRIVATE|INTERFACE.
246-
function(target_add_compile_flags_if_supported target visibility)
247-
foreach(flag ${ARGN})
248-
mangle_name("${flag}" flagname)
249-
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
250-
if (CXX_SUPPORTS_${flagname}_FLAG)
251-
target_compile_options(${target} ${visibility} ${flag})
252-
endif()
253-
endforeach()
254-
endfunction()

libcxxabi/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
1212
list(INSERT CMAKE_MODULE_PATH 0
1313
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
1414
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
15+
"${CMAKE_CURRENT_SOURCE_DIR}/../runtimes/cmake/Modules"
1516
"${LLVM_COMMON_CMAKE_UTILS}"
1617
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
1718
)

libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake

Lines changed: 1 addition & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -5,104 +5,10 @@
55
# - LIBCXXABI_LIBRARIES: libraries to link libc++abi to.
66

77
include(CheckCXXCompilerFlag)
8+
include(HandleFlags)
89

910
unset(add_flag_if_supported)
1011

11-
# Mangle the name of a compiler flag into a valid CMake identifier.
12-
# Ex: --std=c++11 -> STD_EQ_CXX11
13-
macro(mangle_name str output)
14-
string(STRIP "${str}" strippedStr)
15-
string(REGEX REPLACE "^/" "" strippedStr "${strippedStr}")
16-
string(REGEX REPLACE "^-+" "" strippedStr "${strippedStr}")
17-
string(REGEX REPLACE "-+$" "" strippedStr "${strippedStr}")
18-
string(REPLACE "-" "_" strippedStr "${strippedStr}")
19-
string(REPLACE "=" "_EQ_" strippedStr "${strippedStr}")
20-
string(REPLACE "+" "X" strippedStr "${strippedStr}")
21-
string(TOUPPER "${strippedStr}" ${output})
22-
endmacro()
23-
24-
# Remove a list of flags from all CMake variables that affect compile flags.
25-
# This can be used to remove unwanted flags specified on the command line
26-
# or added in other parts of LLVM's cmake configuration.
27-
macro(remove_flags)
28-
foreach(var ${ARGN})
29-
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
30-
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
31-
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
32-
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
33-
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
34-
string(REPLACE "${var}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
35-
string(REPLACE "${var}" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
36-
string(REPLACE "${var}" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
37-
string(REPLACE "${var}" "" CMAKE_SHARED_MODULE_FLAGS "${CMAKE_SHARED_MODULE_FLAGS}")
38-
remove_definitions(${var})
39-
endforeach()
40-
endmacro(remove_flags)
41-
42-
macro(check_flag_supported flag)
43-
mangle_name("${flag}" flagname)
44-
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
45-
endmacro()
46-
47-
macro(append_flags DEST)
48-
foreach(value ${ARGN})
49-
list(APPEND ${DEST} ${value})
50-
list(APPEND ${DEST} ${value})
51-
endforeach()
52-
endmacro()
53-
54-
# If the specified 'condition' is true then append the specified list of flags to DEST
55-
macro(append_flags_if condition DEST)
56-
if (${condition})
57-
list(APPEND ${DEST} ${ARGN})
58-
endif()
59-
endmacro()
60-
61-
# Add each flag in the list specified by DEST if that flag is supported by the current compiler.
62-
macro(append_flags_if_supported DEST)
63-
foreach(flag ${ARGN})
64-
mangle_name("${flag}" flagname)
65-
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
66-
append_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${DEST} ${flag})
67-
endforeach()
68-
endmacro()
69-
70-
# Add a macro definition if condition is true.
71-
macro(define_if condition def)
72-
if (${condition})
73-
add_definitions(${def})
74-
endif()
75-
endmacro()
76-
77-
# Add a macro definition if condition is not true.
78-
macro(define_if_not condition def)
79-
if (NOT ${condition})
80-
add_definitions(${def})
81-
endif()
82-
endmacro()
83-
84-
# Add a macro definition to the __config_site file if the specified condition
85-
# is 'true'. Note that '-D${def}' is not added. Instead it is expected that
86-
# the build include the '__config_site' header.
87-
macro(config_define_if condition def)
88-
if (${condition})
89-
set(${def} ON)
90-
set(LIBCXXABI_NEEDS_SITE_CONFIG ON)
91-
endif()
92-
endmacro()
93-
94-
macro(config_define_if_not condition def)
95-
if (NOT ${condition})
96-
set(${def} ON)
97-
set(LIBCXXABI_NEEDS_SITE_CONFIG ON)
98-
endif()
99-
endmacro()
100-
101-
macro(config_define value def)
102-
set(${def} ${value})
103-
set(LIBCXXABI_NEEDS_SITE_CONFIG ON)
104-
endmacro()
105-
10612
# Add a list of flags to all of 'CMAKE_CXX_FLAGS', 'CMAKE_C_FLAGS',
10713
# 'LIBCXXABI_COMPILE_FLAGS' and 'LIBCXXABI_LINK_FLAGS'.
10814
macro(add_target_flags)
@@ -235,20 +141,3 @@ macro(add_library_flags_if condition)
235141
add_library_flags(${ARGN})
236142
endif()
237143
endmacro()
238-
239-
# Turn a comma separated CMake list into a space separated string.
240-
macro(split_list listname)
241-
string(REPLACE ";" " " ${listname} "${${listname}}")
242-
endmacro()
243-
244-
# For each specified flag, add that compile flag to the provided target.
245-
# The flags are added with the given visibility, i.e. PUBLIC|PRIVATE|INTERFACE.
246-
function(target_add_compile_flags_if_supported target visibility)
247-
foreach(flag ${ARGN})
248-
mangle_name("${flag}" flagname)
249-
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
250-
if (CXX_SUPPORTS_${flagname}_FLAG)
251-
target_compile_options(${target} ${visibility} ${flag})
252-
endif()
253-
endforeach()
254-
endfunction()

libunwind/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
1010
list(INSERT CMAKE_MODULE_PATH 0
1111
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
1212
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
13+
"${CMAKE_CURRENT_SOURCE_DIR}/../runtimes/cmake/Modules"
1314
"${LLVM_COMMON_CMAKE_UTILS}"
1415
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
1516
)

0 commit comments

Comments
 (0)