Skip to content

Commit c20c182

Browse files
committedJun 12, 2018
Reland "Use custom command and target to install libc++ headers"
Using file(COPY FILE...) has several downsides. Since the file command is only executed at configuration time, any changes to headers made after the initial CMake execution are ignored. This can lead to subtle errors since the just built Clang will be using stale libc++ headers. Furthermore, since the headers are copied prior to executing the build system, this may hide missing dependencies on libc++ from other LLVM components. This changes replaces the use of file(COPY FILE...) command with a custom command and target which addresses all aforementioned issues and matches the implementation already used by other LLVM components that also install headers like Clang builtin headers. Differential Revision: https://reviews.llvm.org/D44773 llvm-svn: 334468
1 parent e044d1e commit c20c182

File tree

4 files changed

+243
-40
lines changed

4 files changed

+243
-40
lines changed
 

Diff for: ‎libcxx/NOTES.TXT

+1
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ to libc++.
2626
1. Add a test under `test/libcxx` that the header defines `_LIBCPP_VERSION`.
2727
2. Update `test/libcxx/double_include.sh.cpp` to include the new header.
2828
3. Create a submodule in `include/module.modulemap` for the new header.
29+
4. Update the include/CMakeLists.txt file to include the new header.

Diff for: ‎libcxx/cmake/Modules/HandleLibCXXABI.cmake

+17-7
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,29 @@ macro(setup_abi_lib abidefines abilib abifiles abidirs)
4747
set(found TRUE)
4848
get_filename_component(dstdir ${fpath} PATH)
4949
get_filename_component(ifile ${fpath} NAME)
50-
file(COPY "${incpath}/${fpath}"
51-
DESTINATION "${LIBCXX_BINARY_INCLUDE_DIR}/${dstdir}"
52-
)
53-
file(COPY "${incpath}/${fpath}"
54-
DESTINATION "${CMAKE_BINARY_DIR}/include/c++/v1/${dstdir}"
55-
)
50+
set(src ${incpath}/${fpath})
51+
52+
set(dst ${LIBCXX_BINARY_INCLUDE_DIR}/${dstdir}/${fpath})
53+
add_custom_command(OUTPUT ${dst}
54+
DEPENDS ${src}
55+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
56+
COMMENT "Copying C++ ABI header ${fpath}...")
57+
list(APPEND abilib_headers "${dst}")
58+
59+
set(dst "${CMAKE_BINARY_DIR}/include/c++/v1/${dstdir}/${fpath}")
60+
add_custom_command(OUTPUT ${dst}
61+
DEPENDS ${src}
62+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
63+
COMMENT "Copying C++ ABI header ${fpath}...")
64+
list(APPEND abilib_headers "${dst}")
65+
5666
if (LIBCXX_INSTALL_HEADERS)
5767
install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}"
5868
DESTINATION ${LIBCXX_INSTALL_PREFIX}include/c++/v1/${dstdir}
5969
COMPONENT cxx-headers
6070
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
6171
)
6272
endif()
63-
list(APPEND abilib_headers "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}")
6473
endif()
6574
endforeach()
6675
if (NOT found)
@@ -69,6 +78,7 @@ macro(setup_abi_lib abidefines abilib abifiles abidirs)
6978
endforeach()
7079

7180
include_directories("${LIBCXX_BINARY_INCLUDE_DIR}")
81+
add_custom_target(cxx-abi-headers ALL DEPENDS ${abilib_headers})
7282
endmacro()
7383

7484

Diff for: ‎libcxx/include/CMakeLists.txt

+220-32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,184 @@
1-
if (NOT LIBCXX_INSTALL_SUPPORT_HEADERS)
2-
set(LIBCXX_SUPPORT_HEADER_PATTERN PATTERN "support" EXCLUDE)
1+
set(files
2+
__bit_reference
3+
__bsd_locale_defaults.h
4+
__bsd_locale_fallbacks.h
5+
__debug
6+
__functional_03
7+
__functional_base
8+
__functional_base_03
9+
__hash_table
10+
__libcpp_version
11+
__locale
12+
__mutex_base
13+
__nullptr
14+
__split_buffer
15+
__sso_allocator
16+
__std_stream
17+
__string
18+
__threading_support
19+
__tree
20+
__tuple
21+
__undef_macros
22+
algorithm
23+
any
24+
array
25+
atomic
26+
bitset
27+
cassert
28+
ccomplex
29+
cctype
30+
cerrno
31+
cfenv
32+
cfloat
33+
chrono
34+
cinttypes
35+
ciso646
36+
climits
37+
clocale
38+
cmath
39+
codecvt
40+
compare
41+
complex
42+
complex.h
43+
condition_variable
44+
csetjmp
45+
csignal
46+
cstdarg
47+
cstdbool
48+
cstddef
49+
cstdint
50+
cstdio
51+
cstdlib
52+
cstring
53+
ctgmath
54+
ctime
55+
ctype.h
56+
cwchar
57+
cwctype
58+
deque
59+
errno.h
60+
exception
61+
experimental/__config
62+
experimental/__memory
63+
experimental/algorithm
64+
experimental/any
65+
experimental/chrono
66+
experimental/coroutine
67+
experimental/deque
68+
experimental/dynarray
69+
experimental/filesystem
70+
experimental/forward_list
71+
experimental/functional
72+
experimental/iterator
73+
experimental/list
74+
experimental/map
75+
experimental/memory_resource
76+
experimental/numeric
77+
experimental/optional
78+
experimental/propagate_const
79+
experimental/ratio
80+
experimental/regex
81+
experimental/set
82+
experimental/simd
83+
experimental/string
84+
experimental/string_view
85+
experimental/system_error
86+
experimental/tuple
87+
experimental/type_traits
88+
experimental/unordered_map
89+
experimental/unordered_set
90+
experimental/utility
91+
experimental/vector
92+
ext/__hash
93+
ext/hash_map
94+
ext/hash_set
95+
float.h
96+
forward_list
97+
fstream
98+
functional
99+
future
100+
initializer_list
101+
inttypes.h
102+
iomanip
103+
ios
104+
iosfwd
105+
iostream
106+
istream
107+
iterator
108+
limits
109+
limits.h
110+
list
111+
locale
112+
locale.h
113+
map
114+
math.h
115+
memory
116+
module.modulemap
117+
mutex
118+
new
119+
numeric
120+
optional
121+
ostream
122+
queue
123+
random
124+
ratio
125+
regex
126+
scoped_allocator
127+
set
128+
setjmp.h
129+
shared_mutex
130+
sstream
131+
stack
132+
stdbool.h
133+
stddef.h
134+
stdexcept
135+
stdint.h
136+
stdio.h
137+
stdlib.h
138+
streambuf
139+
string
140+
string.h
141+
string_view
142+
strstream
143+
system_error
144+
tgmath.h
145+
thread
146+
tuple
147+
type_traits
148+
typeindex
149+
typeinfo
150+
unordered_map
151+
unordered_set
152+
utility
153+
valarray
154+
variant
155+
vector
156+
version
157+
wchar.h
158+
wctype.h
159+
)
160+
161+
if(LIBCXX_INSTALL_SUPPORT_HEADERS)
162+
set(files
163+
${files}
164+
support/android/locale_bionic.h
165+
support/fuchsia/xlocale.h
166+
support/ibm/limits.h
167+
support/ibm/locale_mgmt_aix.h
168+
support/ibm/support.h
169+
support/ibm/xlocale.h
170+
support/musl/xlocale.h
171+
support/newlib/xlocale.h
172+
support/solaris/floatingpoint.h
173+
support/solaris/wchar.h
174+
support/solaris/xlocale.h
175+
support/win32/limits_msvc_win32.h
176+
support/win32/locale_win32.h
177+
support/xlocale/__nop_locale_mgmt.h
178+
support/xlocale/__posix_l_fallback.h
179+
support/xlocale/__strtonum_fallback.h
180+
support/xlocale/xlocale.h
181+
)
3182
endif()
4183

5184
if (LIBCXX_NEEDS_SITE_CONFIG)
@@ -14,44 +193,56 @@ if (LIBCXX_NEEDS_SITE_CONFIG)
14193
${LIBCXX_BINARY_DIR}/__config_site
15194
)
16195
# Add a target that executes the generation commands.
17-
add_custom_target(generate_config_header ALL
196+
add_custom_target(cxx-generated-config ALL
18197
DEPENDS ${LIBCXX_BINARY_DIR}/__generated_config)
19-
set(generated_config_deps generate_config_header)
198+
set(generated_config_deps cxx-generated-config)
199+
else()
200+
set(files
201+
${files}
202+
__config
203+
)
20204
endif()
21205

22-
set(LIBCXX_HEADER_PATTERN
23-
PATTERN "*"
24-
PATTERN "CMakeLists.txt" EXCLUDE
25-
PATTERN ".svn" EXCLUDE
26-
PATTERN "__config_site.in" EXCLUDE
27-
${LIBCXX_SUPPORT_HEADER_PATTERN}
28-
)
29-
30206
if(NOT LIBCXX_USING_INSTALLED_LLVM AND LLVM_BINARY_DIR)
31-
file(COPY .
32-
DESTINATION "${LLVM_BINARY_DIR}/include/c++/v1"
33-
FILES_MATCHING
34-
${LIBCXX_HEADER_PATTERN}
35-
)
207+
set(output_dir ${LLVM_BINARY_DIR}/include/c++/v1)
208+
209+
set(out_files)
210+
foreach(f ${files})
211+
set(src ${CMAKE_CURRENT_SOURCE_DIR}/${f})
212+
set(dst ${output_dir}/${f})
213+
add_custom_command(OUTPUT ${dst}
214+
DEPENDS ${src}
215+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
216+
COMMENT "Copying CXX header ${f}")
217+
list(APPEND out_files ${dst})
218+
endforeach()
36219

37220
if (LIBCXX_NEEDS_SITE_CONFIG)
38221
# Copy the generated header as __config into build directory.
39-
add_custom_command(
40-
TARGET generate_config_header POST_BUILD
41-
COMMAND ${CMAKE_COMMAND} -E copy
42-
${LIBCXX_BINARY_DIR}/__generated_config
43-
${LLVM_BINARY_DIR}/include/c++/v1/__config)
222+
set(src ${LIBCXX_BINARY_DIR}/__generated_config)
223+
set(dst ${output_dir}/__config)
224+
add_custom_command(OUTPUT ${dst}
225+
DEPENDS ${src} ${generated_config_deps}
226+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
227+
COMMENT "Copying CXX __config")
228+
list(APPEND out_files ${dst})
44229
endif()
230+
231+
add_custom_target(cxx-headers ALL DEPENDS ${out_files} ${LIBCXX_CXX_ABI_LIBRARY_HEADERS})
232+
else()
233+
add_custom_target(cxx-headers)
45234
endif()
235+
set_target_properties(cxx-headers PROPERTIES FOLDER "Misc")
46236

47237
if (LIBCXX_INSTALL_HEADERS)
48-
install(DIRECTORY .
49-
DESTINATION ${LIBCXX_INSTALL_PREFIX}include/c++/v1
50-
COMPONENT cxx-headers
51-
FILES_MATCHING
52-
${LIBCXX_HEADER_PATTERN}
53-
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
54-
)
238+
foreach(file ${files})
239+
get_filename_component(dir ${file} DIRECTORY)
240+
install(FILES ${file}
241+
DESTINATION ${LIBCXX_INSTALL_PREFIX}include/c++/v1/${dir}
242+
COMPONENT cxx-headers
243+
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
244+
)
245+
endforeach()
55246

56247
if (LIBCXX_NEEDS_SITE_CONFIG)
57248
# Install the generated header as __config.
@@ -63,8 +254,6 @@ if (LIBCXX_INSTALL_HEADERS)
63254
endif()
64255

65256
if (NOT CMAKE_CONFIGURATION_TYPES)
66-
# this target is just needed as a placeholder for the distribution target
67-
add_custom_target(cxx-headers)
68257
add_custom_target(install-cxx-headers
69258
DEPENDS cxx-headers ${generated_config_deps}
70259
COMMAND "${CMAKE_COMMAND}"
@@ -73,7 +262,6 @@ if (LIBCXX_INSTALL_HEADERS)
73262
# Stripping is a no-op for headers
74263
add_custom_target(install-cxx-headers-stripped DEPENDS install-cxx-headers)
75264

76-
add_custom_target(libcxx-headers)
77265
add_custom_target(install-libcxx-headers DEPENDS install-cxx-headers)
78266
add_custom_target(install-libcxx-headers-stripped DEPENDS install-cxx-headers-stripped)
79267
endif()

Diff for: ‎libcxx/lib/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ split_list(LIBCXX_LINK_FLAGS)
189189

190190
# Add an object library that contains the compiled source files.
191191
add_library(cxx_objects OBJECT ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
192+
if(LIBCXX_CXX_ABI_LIBRARY_HEADERS)
193+
add_dependencies(cxx_objects ${LIBCXX_CXX_ABI_LIBRARY_HEADERS})
194+
endif()
192195
if(WIN32 AND NOT MINGW)
193196
target_compile_definitions(cxx_objects
194197
PRIVATE
@@ -283,7 +286,8 @@ if (LIBCXX_ENABLE_STATIC)
283286
endif()
284287

285288
# Add a meta-target for both libraries.
286-
add_custom_target(cxx DEPENDS ${LIBCXX_TARGETS} ${generated_config_deps})
289+
add_custom_target(cxx DEPENDS ${LIBCXX_TARGETS})
290+
add_dependencies(cxx cxx-headers)
287291

288292
if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
289293
file(GLOB LIBCXX_EXPERIMENTAL_SOURCES ../src/experimental/*.cpp)

0 commit comments

Comments
 (0)
Please sign in to comment.