2014-05-09 22:11:03 +00:00
include ( ExternalProject )
2013-01-18 16:05:21 +00:00
include ( CompilerRTUtils )
2020-03-27 16:17:52 -07:00
include ( HandleCompilerRT )
2012-12-19 12:33:39 +00:00
2016-07-11 21:51:56 +00:00
function ( set_target_output_directories target output_dir )
# For RUNTIME_OUTPUT_DIRECTORY variable, Multi-configuration generators
# append a per-configuration subdirectory to the specified directory.
# To avoid the appended folder, the configuration specific variable must be
# set 'RUNTIME_OUTPUT_DIRECTORY_${CONF}':
# RUNTIME_OUTPUT_DIRECTORY_DEBUG, RUNTIME_OUTPUT_DIRECTORY_RELEASE, ...
if ( CMAKE_CONFIGURATION_TYPES )
foreach ( build_mode ${ CMAKE_CONFIGURATION_TYPES } )
string ( TOUPPER "${build_mode}" CONFIG_SUFFIX )
set_target_properties ( "${target}" PROPERTIES
" A R C H I V E _ O U T P U T _ D I R E C T O R Y _ $ { C O N F I G _ S U F F I X } " $ { o u t p u t _ d i r }
" L I B R A R Y _ O U T P U T _ D I R E C T O R Y _ $ { C O N F I G _ S U F F I X } " $ { o u t p u t _ d i r }
" R U N T I M E _ O U T P U T _ D I R E C T O R Y _ $ { C O N F I G _ S U F F I X } " $ { o u t p u t _ d i r } )
endforeach ( )
else ( )
set_target_properties ( "${target}" PROPERTIES
A R C H I V E _ O U T P U T _ D I R E C T O R Y $ { o u t p u t _ d i r }
L I B R A R Y _ O U T P U T _ D I R E C T O R Y $ { o u t p u t _ d i r }
R U N T I M E _ O U T P U T _ D I R E C T O R Y $ { o u t p u t _ d i r } )
endif ( )
endfunction ( )
2015-06-10 23:55:07 +00:00
# Tries to add an "object library" target for a given list of OSs and/or
# architectures with name "<name>.<arch>" for non-Darwin platforms if
# architecture can be targeted, and "<name>.<os>" for Darwin platforms.
# add_compiler_rt_object_libraries(<name>
2015-06-19 03:39:24 +00:00
# OS <os names>
# ARCHS <architectures>
2015-06-10 23:55:07 +00:00
# SOURCES <source files>
# CFLAGS <compile flags>
2018-06-13 07:08:28 +00:00
# DEFS <compile definitions>
2018-07-10 13:00:17 +00:00
# DEPS <dependencies>
# ADDITIONAL_HEADERS <header files>)
2015-06-10 23:55:07 +00:00
function ( add_compiler_rt_object_libraries name )
2018-07-10 13:00:17 +00:00
cmake_parse_arguments ( LIB "" "" "OS;ARCHS;SOURCES;CFLAGS;DEFS;DEPS;ADDITIONAL_HEADERS"
$ { A R G N } )
2015-06-10 23:55:07 +00:00
set ( libnames )
if ( APPLE )
foreach ( os ${ LIB_OS } )
set ( libname "${name}.${os}" )
set ( libnames ${ libnames } ${ libname } )
set ( extra_cflags_ ${ libname } ${ DARWIN_${os } _CFLAGS} )
2016-01-27 09:28:01 +00:00
list_intersect ( LIB_ARCHS_ ${ libname } DARWIN_ ${ os } _ARCHS LIB_ARCHS )
2015-06-10 23:55:07 +00:00
endforeach ( )
2013-01-18 16:05:21 +00:00
else ( )
2015-06-19 03:39:24 +00:00
foreach ( arch ${ LIB_ARCHS } )
2015-06-10 23:55:07 +00:00
set ( libname "${name}.${arch}" )
set ( libnames ${ libnames } ${ libname } )
set ( extra_cflags_ ${ libname } ${ TARGET_${arch } _CFLAGS} )
if ( NOT CAN_TARGET_ ${ arch } )
2015-08-10 18:26:29 +00:00
message ( FATAL_ERROR "Architecture ${arch} can't be targeted" )
2015-06-10 23:55:07 +00:00
return ( )
endif ( )
endforeach ( )
2013-01-18 16:05:21 +00:00
endif ( )
2016-07-11 21:51:56 +00:00
2018-07-10 13:00:17 +00:00
# Add headers to LIB_SOURCES for IDEs
compiler_rt_process_sources ( LIB_SOURCES
$ { L I B _ S O U R C E S }
A D D I T I O N A L _ H E A D E R S
$ { L I B _ A D D I T I O N A L _ H E A D E R S }
)
2015-06-10 23:55:07 +00:00
foreach ( libname ${ libnames } )
add_library ( ${ libname } OBJECT ${ LIB_SOURCES } )
2018-06-13 07:08:28 +00:00
if ( LIB_DEPS )
add_dependencies ( ${ libname } ${ LIB_DEPS } )
endif ( )
2017-09-07 01:36:47 +00:00
# Strip out -msse3 if this isn't macOS.
set ( target_flags ${ LIB_CFLAGS } )
if ( APPLE AND NOT "${libname}" MATCHES ".*\.osx.*" )
list ( REMOVE_ITEM target_flags "-msse3" )
endif ( )
2018-04-11 17:31:18 +00:00
set_target_compile_flags ( ${ libname }
[compiler-rt] Don't explicitly set CMAKE_CXX_FLAGS.
Summary:
C++ flags should not be used for not-C++ files as it may trigger
-Werror=unused-command-line-argument. CMake will use CMAKE_C_FLAGS,
CMAKE_CXX_FLAGS, and CMAKE_ASM_FLAGS as appropriate implicitly, so
this does not need to be explicitly handled here.
This change depends on https://reviews.llvm.org/D53301, since one of
the builders depended on this behavior because it was not configuring
CMAKE_ASM_FLAGS.
Reviewers: eugenis, vitalybuka
Reviewed By: eugenis, vitalybuka
Subscribers: dberris, mgorny, delcypher, #sanitizers, llvm-commits
Differential Revision: https://reviews.llvm.org/D53335
llvm-svn: 344751
2018-10-18 18:04:28 +00:00
$ { e x t r a _ c f l a g s _ $ { l i b n a m e } } $ { t a r g e t _ f l a g s } )
2015-06-10 23:55:07 +00:00
set_property ( TARGET ${ libname } APPEND PROPERTY
C O M P I L E _ D E F I N I T I O N S $ { L I B _ D E F S } )
2016-07-11 21:51:56 +00:00
set_target_properties ( ${ libname } PROPERTIES FOLDER "Compiler-RT Libraries" )
2015-06-10 23:55:07 +00:00
if ( APPLE )
[CMake] Add experimental support for building compiler-rt for iOS
Summary:
This is a reunification of three separate reviews D11073, D11082, D11083.
Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change.
This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake.
Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov
Subscribers: jevinskie, filcab, llvm-commits
Differential Revision: http://reviews.llvm.org/D11820
llvm-svn: 244948
2015-08-13 20:38:16 +00:00
set_target_properties ( ${ libname } PROPERTIES
O S X _ A R C H I T E C T U R E S " $ { L I B _ A R C H S _ $ { l i b n a m e } } " )
2015-06-10 23:55:07 +00:00
endif ( )
endforeach ( )
endfunction ( )
2013-01-20 14:36:12 +00:00
2015-08-26 18:33:51 +00:00
# Takes a list of object library targets, and a suffix and appends the proper
# TARGET_OBJECTS string to the output variable.
# format_object_libs(<output> <suffix> ...)
macro ( format_object_libs output suffix )
foreach ( lib ${ ARGN } )
list ( APPEND ${ output } $< TARGET_OBJECTS:${lib}.${suffix} > )
endforeach ( )
endmacro ( )
2016-08-26 20:52:22 +00:00
function ( add_compiler_rt_component name )
add_custom_target ( ${ name } )
set_target_properties ( ${ name } PROPERTIES FOLDER "Compiler-RT Misc" )
if ( COMMAND runtime_register_component )
runtime_register_component ( ${ name } )
endif ( )
add_dependencies ( compiler-rt ${ name } )
endfunction ( )
2017-11-29 19:27:25 +00:00
function ( add_asm_sources output )
set ( ${ output } ${ ARGN } PARENT_SCOPE )
2020-08-20 20:17:47 +03:00
# CMake doesn't pass the correct architecture for Apple prior to CMake 3.19. https://gitlab.kitware.com/cmake/cmake/-/issues/20771
# MinGW didn't work correctly with assembly prior to CMake 3.17. https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4287 and https://reviews.llvm.org/rGb780df052dd2b246a760d00e00f7de9ebdab9d09
# Workaround these two issues by compiling as C.
# Same workaround used in libunwind. Also update there if changed here.
if ( ( APPLE AND CMAKE_VERSION VERSION_LESS 3.19 ) OR ( MINGW AND CMAKE_VERSION VERSION_LESS 3.17 ) )
2020-08-20 15:23:50 +02:00
set_source_files_properties ( ${ ARGN } PROPERTIES LANGUAGE C )
endif ( )
2017-11-29 19:27:25 +00:00
endfunction ( )
2017-08-29 22:12:31 +00:00
macro ( set_output_name output name arch )
2018-06-28 03:11:52 +00:00
if ( LLVM_ENABLE_PER_TARGET_RUNTIME_DIR )
set ( ${ output } ${ name } )
2017-08-29 22:12:31 +00:00
else ( )
2018-06-28 03:11:52 +00:00
if ( ANDROID AND ${ arch } STREQUAL "i386" )
set ( ${ output } "${name}-i686${COMPILER_RT_OS_SUFFIX}" )
2021-03-11 23:44:16 +02:00
elseif ( "${arch}" MATCHES "^arm" )
if ( COMPILER_RT_DEFAULT_TARGET_ONLY )
set ( triple "${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" )
else ( )
set ( triple "${TARGET_TRIPLE}" )
endif ( )
# When using arch-suffixed runtime library names, clang only looks for
# libraries named "arm" or "armhf", see getArchNameForCompilerRTLib in
# clang. Therefore, try to inspect both the arch name and the triple
# if it seems like we're building an armhf target.
if ( "${arch}" MATCHES "hf$" OR "${triple}" MATCHES "hf$" )
set ( ${ output } "${name}-armhf${COMPILER_RT_OS_SUFFIX}" )
else ( )
set ( ${ output } "${name}-arm${COMPILER_RT_OS_SUFFIX}" )
endif ( )
2018-06-28 03:11:52 +00:00
else ( )
set ( ${ output } "${name}-${arch}${COMPILER_RT_OS_SUFFIX}" )
endif ( )
2017-08-29 22:12:31 +00:00
endif ( )
endmacro ( )
2015-08-25 19:53:09 +00:00
# Adds static or shared runtime for a list of architectures and operating
# systems and puts it in the proper directory in the build and install trees.
# add_compiler_rt_runtime(<name>
2021-06-11 23:21:40 +00:00
# {OBJECT|STATIC|SHARED|MODULE}
2015-08-25 19:53:09 +00:00
# ARCHS <architectures>
# OS <os list>
2014-03-31 13:45:36 +00:00
# SOURCES <source files>
# CFLAGS <compile flags>
2017-01-10 04:33:04 +00:00
# LINK_FLAGS <linker flags>
2014-09-29 13:18:55 +00:00
# DEFS <compile definitions>
2020-10-06 11:32:57 -07:00
# DEPS <dependencies>
2015-08-25 19:53:09 +00:00
# LINK_LIBS <linked libraries> (only for shared library)
2015-08-26 18:33:51 +00:00
# OBJECT_LIBS <object libraries to use as sources>
2018-07-10 13:00:17 +00:00
# PARENT_TARGET <convenience parent target>
# ADDITIONAL_HEADERS <header files>)
2015-08-25 19:53:09 +00:00
function ( add_compiler_rt_runtime name type )
2021-06-11 23:21:40 +00:00
if ( NOT type MATCHES "^(OBJECT|STATIC|SHARED|MODULE)$" )
message ( FATAL_ERROR
" t y p e a r g u m e n t m u s t b e O B J E C T , S T A T I C , S H A R E D o r M O D U L E " )
2015-08-25 19:53:09 +00:00
return ( )
endif ( )
cmake_parse_arguments ( LIB
" "
" P A R E N T _ T A R G E T "
2020-10-06 11:32:57 -07:00
" O S ; A R C H S ; S O U R C E S ; C F L A G S ; L I N K _ F L A G S ; D E F S ; D E P S ; L I N K _ L I B S ; O B J E C T _ L I B S ; A D D I T I O N A L _ H E A D E R S "
2015-08-25 19:53:09 +00:00
$ { A R G N } )
set ( libnames )
2017-03-22 17:25:49 +00:00
# Until we support this some other way, build compiler-rt runtime without LTO
# to allow non-LTO projects to link with it.
if ( COMPILER_RT_HAS_FNO_LTO_FLAG )
set ( NO_LTO_FLAGS "-fno-lto" )
else ( )
set ( NO_LTO_FLAGS "" )
endif ( )
2017-09-01 23:23:59 +00:00
2020-03-09 15:25:41 -07:00
# By default do not instrument or use profdata for compiler-rt.
set ( NO_PGO_FLAGS "" )
if ( NOT COMPILER_RT_ENABLE_PGO )
if ( LLVM_PROFDATA_FILE AND COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG )
list ( APPEND NO_PGO_FLAGS "-fno-profile-instr-use" )
endif ( )
if ( LLVM_BUILD_INSTRUMENTED MATCHES IR AND COMPILER_RT_HAS_FNO_PROFILE_GENERATE_FLAG )
list ( APPEND NO_PGO_FLAGS "-fno-profile-generate" )
elseif ( LLVM_BUILD_INSTRUMENTED AND COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG )
list ( APPEND NO_PGO_FLAGS "-fno-profile-instr-generate" )
endif ( )
endif ( )
2018-07-10 13:00:17 +00:00
list ( LENGTH LIB_SOURCES LIB_SOURCES_LENGTH )
if ( ${ LIB_SOURCES_LENGTH } GREATER 0 )
# Add headers to LIB_SOURCES for IDEs. It doesn't make sense to
# do this for a runtime library that only consists of OBJECT
# libraries, so only add the headers when source files are present.
compiler_rt_process_sources ( LIB_SOURCES
$ { L I B _ S O U R C E S }
A D D I T I O N A L _ H E A D E R S
$ { L I B _ A D D I T I O N A L _ H E A D E R S }
)
endif ( )
2015-08-25 19:53:09 +00:00
if ( APPLE )
foreach ( os ${ LIB_OS } )
2017-09-01 23:23:59 +00:00
# Strip out -msse3 if this isn't macOS.
list ( LENGTH LIB_CFLAGS HAS_EXTRA_CFLAGS )
if ( HAS_EXTRA_CFLAGS AND NOT "${os}" MATCHES "^(osx)$" )
list ( REMOVE_ITEM LIB_CFLAGS "-msse3" )
endif ( )
2015-08-25 19:53:09 +00:00
if ( type STREQUAL "STATIC" )
set ( libname "${name}_${os}" )
else ( )
set ( libname "${name}_${os}_dynamic" )
2017-01-10 04:33:04 +00:00
set ( extra_link_flags_ ${ libname } ${ DARWIN_${os } _LINK_FLAGS} ${ LIB_LINK_FLAGS } )
2015-08-25 19:53:09 +00:00
endif ( )
2016-01-27 09:28:01 +00:00
list_intersect ( LIB_ARCHS_ ${ libname } DARWIN_ ${ os } _ARCHS LIB_ARCHS )
2015-08-25 19:53:09 +00:00
if ( LIB_ARCHS_ ${ libname } )
list ( APPEND libnames ${ libname } )
2020-03-09 15:25:41 -07:00
set ( extra_cflags_ ${ libname } ${ DARWIN_${os } _CFLAGS} ${ NO_LTO_FLAGS } ${ NO_PGO_FLAGS } ${ LIB_CFLAGS } )
2015-08-25 19:53:09 +00:00
set ( output_name_ ${ libname } ${ libname } ${ COMPILER_RT_OS_SUFFIX } )
2015-08-26 18:33:51 +00:00
set ( sources_ ${ libname } ${ LIB_SOURCES } )
format_object_libs ( sources_ ${ libname } ${ os } ${ LIB_OBJECT_LIBS } )
2018-06-28 03:11:52 +00:00
get_compiler_rt_output_dir ( ${ COMPILER_RT_DEFAULT_TARGET_ARCH } output_dir_ ${ libname } )
get_compiler_rt_install_dir ( ${ COMPILER_RT_DEFAULT_TARGET_ARCH } install_dir_ ${ libname } )
2015-08-25 19:53:09 +00:00
endif ( )
endforeach ( )
2013-01-20 13:58:10 +00:00
else ( )
2015-08-25 19:53:09 +00:00
foreach ( arch ${ LIB_ARCHS } )
if ( NOT CAN_TARGET_ ${ arch } )
message ( FATAL_ERROR "Architecture ${arch} can't be targeted" )
return ( )
endif ( )
2019-04-30 18:13:22 +00:00
if ( type STREQUAL "OBJECT" )
set ( libname "${name}-${arch}" )
set_output_name ( output_name_ ${ libname } ${ name } ${ COMPILER_RT_OS_SUFFIX } ${ arch } )
elseif ( type STREQUAL "STATIC" )
2015-08-25 19:53:09 +00:00
set ( libname "${name}-${arch}" )
2017-08-29 22:12:31 +00:00
set_output_name ( output_name_ ${ libname } ${ name } ${ arch } )
2015-08-25 19:53:09 +00:00
else ( )
set ( libname "${name}-dynamic-${arch}" )
2016-06-21 14:46:32 +00:00
set ( extra_cflags_ ${ libname } ${ TARGET_${arch } _CFLAGS} ${ LIB_CFLAGS } )
2017-01-10 04:33:04 +00:00
set ( extra_link_flags_ ${ libname } ${ TARGET_${arch } _LINK_FLAGS} ${ LIB_LINK_FLAGS } )
2015-08-25 19:53:09 +00:00
if ( WIN32 )
2017-08-29 22:12:31 +00:00
set_output_name ( output_name_ ${ libname } ${ name } _dynamic ${ arch } )
2015-08-25 19:53:09 +00:00
else ( )
2017-08-29 22:12:31 +00:00
set_output_name ( output_name_ ${ libname } ${ name } ${ arch } )
2015-08-25 19:53:09 +00:00
endif ( )
endif ( )
2020-05-18 11:04:42 +03:00
if ( COMPILER_RT_USE_BUILTINS_LIBRARY AND NOT type STREQUAL "OBJECT" AND
N O T n a m e S T R E Q U A L " c l a n g _ r t . b u i l t i n s " )
2020-03-27 16:17:52 -07:00
get_compiler_rt_target ( ${ arch } target )
find_compiler_rt_library ( builtins ${ target } builtins_ ${ libname } )
2020-05-18 11:04:42 +03:00
if ( builtins_ ${ libname } STREQUAL "NOTFOUND" )
2020-05-16 11:59:21 +08:00
message ( FATAL_ERROR "Cannot find builtins library for the target architecture" )
endif ( )
2020-03-27 16:17:52 -07:00
endif ( )
2015-08-26 18:33:51 +00:00
set ( sources_ ${ libname } ${ LIB_SOURCES } )
format_object_libs ( sources_ ${ libname } ${ arch } ${ LIB_OBJECT_LIBS } )
2015-08-25 19:53:09 +00:00
set ( libnames ${ libnames } ${ libname } )
2020-03-09 15:25:41 -07:00
set ( extra_cflags_ ${ libname } ${ TARGET_${arch } _CFLAGS} ${ NO_LTO_FLAGS } ${ NO_PGO_FLAGS } ${ LIB_CFLAGS } )
2018-06-28 03:11:52 +00:00
get_compiler_rt_output_dir ( ${ arch } output_dir_ ${ libname } )
get_compiler_rt_install_dir ( ${ arch } install_dir_ ${ libname } )
2015-08-25 19:53:09 +00:00
endforeach ( )
2013-01-20 13:58:10 +00:00
endif ( )
2015-08-25 19:53:09 +00:00
if ( NOT libnames )
return ( )
endif ( )
if ( LIB_PARENT_TARGET )
2016-02-23 21:55:38 +00:00
# If the parent targets aren't created we should create them
if ( NOT TARGET ${ LIB_PARENT_TARGET } )
add_custom_target ( ${ LIB_PARENT_TARGET } )
2018-06-27 12:56:34 +00:00
set_target_properties ( ${ LIB_PARENT_TARGET } PROPERTIES
F O L D E R " C o m p i l e r - R T M i s c " )
2016-02-23 21:55:38 +00:00
endif ( )
2015-08-25 19:53:09 +00:00
endif ( )
2015-08-18 17:32:18 +00:00
2015-08-25 19:53:09 +00:00
foreach ( libname ${ libnames } )
2016-07-11 21:51:56 +00:00
# If you are using a multi-configuration generator we don't generate
2016-02-23 21:55:38 +00:00
# per-library install rules, so we fall back to the parent target COMPONENT
if ( CMAKE_CONFIGURATION_TYPES AND LIB_PARENT_TARGET )
set ( COMPONENT_OPTION COMPONENT ${ LIB_PARENT_TARGET } )
else ( )
set ( COMPONENT_OPTION COMPONENT ${ libname } )
endif ( )
2019-04-30 18:13:22 +00:00
if ( type STREQUAL "OBJECT" )
2019-05-01 02:49:45 +00:00
if ( CMAKE_C_COMPILER_ID MATCHES Clang AND CMAKE_C_COMPILER_TARGET )
2019-05-01 05:41:58 +00:00
list ( APPEND extra_cflags_ ${ libname } "--target=${CMAKE_C_COMPILER_TARGET}" )
2019-05-01 03:30:51 +00:00
endif ( )
if ( CMAKE_SYSROOT )
2019-05-01 05:41:58 +00:00
list ( APPEND extra_cflags_ ${ libname } "--sysroot=${CMAKE_SYSROOT}" )
2019-05-01 02:49:45 +00:00
endif ( )
string ( REPLACE ";" " " extra_cflags_ ${ libname } "${extra_cflags_${libname}}" )
string ( REGEX MATCHALL "<[A-Za-z0-9_]*>" substitutions
$ { C M A K E _ C _ C O M P I L E _ O B J E C T } )
set ( compile_command_ ${ libname } "${CMAKE_C_COMPILE_OBJECT}" )
2019-05-19 03:29:15 +00:00
2019-05-01 02:49:45 +00:00
set ( output_file_ ${ libname } ${ output_name_${libname } } ${ CMAKE_C_OUTPUT_EXTENSION } )
foreach ( substitution ${ substitutions } )
if ( substitution STREQUAL "<CMAKE_C_COMPILER>" )
2019-05-19 03:29:15 +00:00
string ( REPLACE "<CMAKE_C_COMPILER>" "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}"
2019-05-01 02:49:45 +00:00
c o m p i l e _ c o m m a n d _ $ { l i b n a m e } $ { c o m p i l e _ c o m m a n d _ $ { l i b n a m e } } )
elseif ( substitution STREQUAL "<OBJECT>" )
string ( REPLACE "<OBJECT>" "${output_dir_${libname}}/${output_file_${libname}}"
c o m p i l e _ c o m m a n d _ $ { l i b n a m e } $ { c o m p i l e _ c o m m a n d _ $ { l i b n a m e } } )
elseif ( substitution STREQUAL "<SOURCE>" )
string ( REPLACE "<SOURCE>" "${sources_${libname}}"
c o m p i l e _ c o m m a n d _ $ { l i b n a m e } $ { c o m p i l e _ c o m m a n d _ $ { l i b n a m e } } )
elseif ( substitution STREQUAL "<FLAGS>" )
2019-05-01 05:41:58 +00:00
string ( REPLACE "<FLAGS>" "${CMAKE_C_FLAGS} ${extra_cflags_${libname}}"
2019-05-01 02:49:45 +00:00
c o m p i l e _ c o m m a n d _ $ { l i b n a m e } $ { c o m p i l e _ c o m m a n d _ $ { l i b n a m e } } )
else ( )
string ( REPLACE "${substitution}" "" compile_command_ ${ libname }
$ { c o m p i l e _ c o m m a n d _ $ { l i b n a m e } } )
endif ( )
endforeach ( )
separate_arguments ( compile_command_ ${ libname } )
2019-04-30 18:13:22 +00:00
add_custom_command (
2019-05-01 02:49:45 +00:00
O U T P U T $ { o u t p u t _ d i r _ $ { l i b n a m e } } / $ { o u t p u t _ f i l e _ $ { l i b n a m e } }
C O M M A N D $ { c o m p i l e _ c o m m a n d _ $ { l i b n a m e } }
2019-04-30 18:13:22 +00:00
D E P E N D S $ { s o u r c e s _ $ { l i b n a m e } }
2019-05-01 02:49:45 +00:00
C O M M E N T " B u i l d i n g C o b j e c t $ { o u t p u t _ f i l e _ $ { l i b n a m e } } " )
add_custom_target ( ${ libname } DEPENDS ${ output_dir_${libname } }/ ${ output_file_${libname } } )
install ( FILES ${ output_dir_${libname } }/ ${ output_file_${libname } }
2019-04-30 18:13:22 +00:00
D E S T I N A T I O N $ { i n s t a l l _ d i r _ $ { l i b n a m e } }
$ { C O M P O N E N T _ O P T I O N } )
else ( )
add_library ( ${ libname } ${ type } ${ sources_${libname } } )
set_target_compile_flags ( ${ libname } ${ extra_cflags_${libname } } )
set_target_link_flags ( ${ libname } ${ extra_link_flags_${libname } } )
set_property ( TARGET ${ libname } APPEND PROPERTY
C O M P I L E _ D E F I N I T I O N S $ { L I B _ D E F S } )
set_target_output_directories ( ${ libname } ${ output_dir_${libname } } )
install ( TARGETS ${ libname }
A R C H I V E D E S T I N A T I O N $ { i n s t a l l _ d i r _ $ { l i b n a m e } }
$ { C O M P O N E N T _ O P T I O N }
L I B R A R Y D E S T I N A T I O N $ { i n s t a l l _ d i r _ $ { l i b n a m e } }
$ { C O M P O N E N T _ O P T I O N }
R U N T I M E D E S T I N A T I O N $ { i n s t a l l _ d i r _ $ { l i b n a m e } }
$ { C O M P O N E N T _ O P T I O N } )
endif ( )
2020-10-06 11:32:57 -07:00
if ( LIB_DEPS )
add_dependencies ( ${ libname } ${ LIB_DEPS } )
endif ( )
2015-08-25 19:53:09 +00:00
set_target_properties ( ${ libname } PROPERTIES
O U T P U T _ N A M E $ { o u t p u t _ n a m e _ $ { l i b n a m e } } )
2016-07-11 21:51:56 +00:00
set_target_properties ( ${ libname } PROPERTIES FOLDER "Compiler-RT Runtime" )
2017-08-21 23:25:50 +00:00
if ( LIB_LINK_LIBS )
2019-02-07 06:32:09 +00:00
target_link_libraries ( ${ libname } PRIVATE ${ LIB_LINK_LIBS } )
2017-08-21 23:25:50 +00:00
endif ( )
2020-03-27 16:17:52 -07:00
if ( builtins_ ${ libname } )
target_link_libraries ( ${ libname } PRIVATE ${ builtins_${libname } } )
endif ( )
2016-09-07 20:32:48 +00:00
if ( ${ type } STREQUAL "SHARED" )
2021-06-22 16:11:29 -07:00
if ( COMMAND llvm_setup_rpath )
llvm_setup_rpath ( ${ libname } )
endif ( )
2016-09-07 20:32:48 +00:00
if ( WIN32 AND NOT CYGWIN AND NOT MINGW )
set_target_properties ( ${ libname } PROPERTIES IMPORT_PREFIX "" )
set_target_properties ( ${ libname } PROPERTIES IMPORT_SUFFIX ".lib" )
endif ( )
2017-04-26 18:59:22 +00:00
if ( APPLE )
# Ad-hoc sign the dylibs
add_custom_command ( TARGET ${ libname }
P O S T _ B U I L D
C O M M A N D c o d e s i g n - - s i g n - $ < T A R G E T _ F I L E : $ { l i b n a m e } >
Prepare Compiler-RT for GnuInstallDirs, matching libcxx, document all
This is a second attempt at D101497, which landed as
9a9bc76c0eb72f0f2732c729a460abbd5239c2e3 but had to be reverted in
8cf7ddbdd4e5af966a369e170c73250f2e3920e7.
This issue was that in the case that `COMPILER_RT_INSTALL_PATH` is
empty, expressions like "${COMPILER_RT_INSTALL_PATH}/bin" evaluated to
"/bin" not "bin" as intended and as was originally.
One solution is to make `COMPILER_RT_INSTALL_PATH` always non-empty,
defaulting it to `CMAKE_INSTALL_PREFIX`. D99636 adopted that approach.
But, I think it is more ergonomic to allow those project-specific paths
to be relative the global ones. Also, making install paths absolute by
default inhibits the proper behavior of functions like
`GNUInstallDirs_get_absolute_install_dir` which make relative install
paths absolute in a more complicated way.
Given all this, I will define a function like the one asked for in
https://gitlab.kitware.com/cmake/cmake/-/issues/19568 (and needed for a
similar use-case).
---
Original message:
Instead of using `COMPILER_RT_INSTALL_PATH` through the CMake for
complier-rt, just use it to define variables for the subdirs which
themselves are used.
This preserves compatibility, but later on we might consider getting rid
of `COMPILER_RT_INSTALL_PATH` and just changing the defaults for the
subdir variables directly.
---
There was a seaming bug where the (non-Apple) per-target libdir was
`${target}` not `lib/${target}`. I suspect that has to do with the docs
on `COMPILER_RT_INSTALL_PATH` saying was the library dir when that's no
longer true, so I just went ahead and fixed it, allowing me to define
fewer and more sensible variables.
That last part should be the only behavior changes; everything else
should be a pure refactoring.
---
I added some documentation of these variables too. In particular, I
wanted to highlight the gotcha where `-DSomeCachePath=...` without the
`:PATH` will lead CMake to make the path absolute. See [1] for
discussion of the problem, and [2] for the brief official documentation
they added as a result.
[1]: https://cmake.org/pipermail/cmake/2015-March/060204.html
[2]: https://cmake.org/cmake/help/latest/manual/cmake.1.html#options
In 38b2dec37ee735d5409148e71ecba278caf0f969 the problem was somewhat
misidentified and so `:STRING` was used, but `:PATH` is better as it
sets the correct type from the get-go.
---
D99484 is the main thrust of the `GnuInstallDirs` work. Once this lands,
it should be feasible to follow both of these up with a simple patch for
compiler-rt analogous to the one for libcxx.
Reviewed By: phosek, #libc_abi, #libunwind
Differential Revision: https://reviews.llvm.org/D105765
2021-04-28 22:36:47 +00:00
W O R K I N G _ D I R E C T O R Y $ { C O M P I L E R _ R T _ O U T P U T _ L I B R A R Y _ D I R }
2017-04-26 18:59:22 +00:00
)
endif ( )
2015-08-25 19:53:09 +00:00
endif ( )
2016-02-23 21:55:38 +00:00
2019-05-07 19:00:37 +00:00
set ( parent_target_arg )
if ( LIB_PARENT_TARGET )
set ( parent_target_arg PARENT_TARGET ${ LIB_PARENT_TARGET } )
2016-02-23 21:55:38 +00:00
endif ( )
2019-05-07 19:00:37 +00:00
add_compiler_rt_install_targets ( ${ libname } ${ parent_target_arg } )
2015-08-25 19:53:09 +00:00
if ( APPLE )
set_target_properties ( ${ libname } PROPERTIES
O S X _ A R C H I T E C T U R E S " $ { L I B _ A R C H S _ $ { l i b n a m e } } " )
endif ( )
2015-12-03 20:08:22 +00:00
if ( type STREQUAL "SHARED" )
rt_externalize_debuginfo ( ${ libname } )
endif ( )
2015-08-25 19:53:09 +00:00
endforeach ( )
if ( LIB_PARENT_TARGET )
2016-02-26 20:59:40 +00:00
add_dependencies ( ${ LIB_PARENT_TARGET } ${ libnames } )
2015-08-18 17:32:18 +00:00
endif ( )
endfunction ( )
2013-01-21 08:12:20 +00:00
2017-08-15 22:56:10 +00:00
# Compile and register compiler-rt tests.
# generate_compiler_rt_tests(<output object files> <test_suite> <test_name>
# <test architecture>
# KIND <custom prefix>
# SUBDIR <subdirectory for testing binary>
# SOURCES <sources to compile>
# RUNTIME <tests runtime to link in>
# CFLAGS <compile-time flags>
# COMPILE_DEPS <compile-time dependencies>
# DEPS <dependencies>
# LINK_FLAGS <flags to use during linking>
# )
function ( generate_compiler_rt_tests test_objects test_suite testname arch )
cmake_parse_arguments ( TEST "" "KIND;RUNTIME;SUBDIR"
" S O U R C E S ; C O M P I L E _ D E P S ; D E P S ; C F L A G S ; L I N K _ F L A G S " $ { A R G N } )
foreach ( source ${ TEST_SOURCES } )
sanitizer_test_compile (
" $ { t e s t _ o b j e c t s } " " $ { s o u r c e } " " $ { a r c h } "
K I N D $ { T E S T _ K I N D }
C O M P I L E _ D E P S $ { T E S T _ C O M P I L E _ D E P S }
D E P S $ { T E S T _ D E P S }
C F L A G S $ { T E S T _ C F L A G S }
)
endforeach ( )
set ( TEST_DEPS ${ ${test_objects } } )
if ( NOT "${TEST_RUNTIME}" STREQUAL "" )
list ( APPEND TEST_DEPS ${ TEST_RUNTIME } )
list ( APPEND "${test_objects}" $< TARGET_FILE:${TEST_RUNTIME} > )
endif ( )
add_compiler_rt_test ( ${ test_suite } "${testname}" "${arch}"
S U B D I R $ { T E S T _ S U B D I R }
O B J E C T S $ { $ { t e s t _ o b j e c t s } }
D E P S $ { T E S T _ D E P S }
2017-08-15 23:22:52 +00:00
L I N K _ F L A G S $ { T E S T _ L I N K _ F L A G S }
2017-08-15 22:56:10 +00:00
)
set ( "${test_objects}" "${${test_objects}}" PARENT_SCOPE )
endfunction ( )
2014-02-19 13:01:03 +00:00
# Link objects into a single executable with COMPILER_RT_TEST_COMPILER,
# using specified link flags. Make executable a part of provided
2012-12-19 12:33:39 +00:00
# test_suite.
2017-08-15 22:56:10 +00:00
# add_compiler_rt_test(<test_suite> <test_name> <arch>
2014-12-17 23:14:01 +00:00
# SUBDIR <subdirectory for binary>
2012-12-19 12:33:39 +00:00
# OBJECTS <object files>
# DEPS <deps (e.g. runtime libs)>
# LINK_FLAGS <link flags>)
2017-08-15 22:56:10 +00:00
function ( add_compiler_rt_test test_suite test_name arch )
2015-06-19 03:39:24 +00:00
cmake_parse_arguments ( TEST "" "SUBDIR" "OBJECTS;DEPS;LINK_FLAGS" "" ${ ARGN } )
2017-08-15 18:32:28 +00:00
set ( output_dir ${ CMAKE_CURRENT_BINARY_DIR } )
2014-12-17 23:14:01 +00:00
if ( TEST_SUBDIR )
2017-08-15 18:32:28 +00:00
set ( output_dir "${output_dir}/${TEST_SUBDIR}" )
2014-12-17 23:14:01 +00:00
endif ( )
2017-08-15 18:32:28 +00:00
set ( output_dir "${output_dir}/${CMAKE_CFG_INTDIR}" )
file ( MAKE_DIRECTORY "${output_dir}" )
set ( output_bin "${output_dir}/${test_name}" )
2015-01-22 14:54:22 +00:00
if ( MSVC )
set ( output_bin "${output_bin}.exe" )
endif ( )
2016-05-16 14:58:07 +00:00
2014-02-19 13:01:03 +00:00
# Use host compiler in a standalone build, and just-built Clang otherwise.
if ( NOT COMPILER_RT_STANDALONE_BUILD )
list ( APPEND TEST_DEPS clang )
endif ( )
2017-08-15 22:56:10 +00:00
get_target_flags_for_arch ( ${ arch } TARGET_LINK_FLAGS )
list ( APPEND TEST_LINK_FLAGS ${ TARGET_LINK_FLAGS } )
2014-05-15 16:33:58 +00:00
# If we're not on MSVC, include the linker flags from CMAKE but override them
# with the provided link flags. This ensures that flags which are required to
# link programs at all are included, but the changes needed for the test
# trump. With MSVC we can't do that because CMake is set up to run link.exe
# when linking, not the compiler. Here, we hack it to use the compiler
# because we want to use -fsanitize flags.
2020-05-15 15:21:49 +00:00
# Only add CMAKE_EXE_LINKER_FLAGS when in a standalone bulid.
# Or else CMAKE_EXE_LINKER_FLAGS contains flags for build compiler of Clang/llvm.
# This might not be the same as what the COMPILER_RT_TEST_COMPILER supports.
# eg: the build compiler use lld linker and we build clang with default ld linker
# then to be tested clang will complain about lld options like --color-diagnostics.
if ( NOT MSVC AND COMPILER_RT_STANDALONE_BUILD )
2014-05-15 16:33:58 +00:00
set ( TEST_LINK_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${TEST_LINK_FLAGS}" )
separate_arguments ( TEST_LINK_FLAGS )
endif ( )
2019-12-27 16:01:03 -08:00
if ( NOT COMPILER_RT_STANDALONE_BUILD AND COMPILER_RT_HAS_LLD AND "lld" IN_LIST LLVM_ENABLE_PROJECTS )
2019-08-27 02:06:34 +00:00
# CMAKE_EXE_LINKER_FLAGS may contain -fuse=lld
# FIXME: -DLLVM_ENABLE_LLD=ON and -DLLVM_ENABLE_PROJECTS without lld case.
list ( APPEND TEST_DEPS lld )
endif ( )
2017-08-21 21:19:13 +00:00
add_custom_command (
O U T P U T " $ { o u t p u t _ b i n } "
C O M M A N D $ { C O M P I L E R _ R T _ T E S T _ C O M P I L E R } $ { T E S T _ O B J E C T S } - o " $ { o u t p u t _ b i n } "
2012-12-19 12:33:39 +00:00
$ { T E S T _ L I N K _ F L A G S }
2017-08-21 21:19:13 +00:00
D E P E N D S $ { T E S T _ D E P S }
)
add_custom_target ( T ${ test_name } DEPENDS "${output_bin}" )
set_target_properties ( T ${ test_name } PROPERTIES FOLDER "Compiler-RT Tests" )
2016-07-11 21:51:56 +00:00
2012-12-19 12:33:39 +00:00
# Make the test suite depend on the binary.
2017-08-21 21:19:13 +00:00
add_dependencies ( ${ test_suite } T ${ test_name } )
2017-08-15 18:32:28 +00:00
endfunction ( )
2013-05-21 13:48:27 +00:00
2016-02-23 21:50:39 +00:00
macro ( add_compiler_rt_resource_file target_name file_name component )
2013-05-21 13:48:27 +00:00
set ( src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}" )
2018-01-14 03:43:14 +00:00
set ( dst_file "${COMPILER_RT_OUTPUT_DIR}/share/${file_name}" )
2014-02-27 07:22:59 +00:00
add_custom_command ( OUTPUT ${ dst_file }
D E P E N D S $ { s r c _ f i l e }
2013-05-21 13:48:27 +00:00
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t $ { s r c _ f i l e } $ { d s t _ f i l e }
2014-02-27 07:22:59 +00:00
C O M M E N T " C o p y i n g $ { f i l e _ n a m e } . . . " )
add_custom_target ( ${ target_name } DEPENDS ${ dst_file } )
2013-05-21 13:48:27 +00:00
# Install in Clang resource directory.
2016-02-23 21:50:39 +00:00
install ( FILES ${ file_name }
Prepare Compiler-RT for GnuInstallDirs, matching libcxx, document all
This is a second attempt at D101497, which landed as
9a9bc76c0eb72f0f2732c729a460abbd5239c2e3 but had to be reverted in
8cf7ddbdd4e5af966a369e170c73250f2e3920e7.
This issue was that in the case that `COMPILER_RT_INSTALL_PATH` is
empty, expressions like "${COMPILER_RT_INSTALL_PATH}/bin" evaluated to
"/bin" not "bin" as intended and as was originally.
One solution is to make `COMPILER_RT_INSTALL_PATH` always non-empty,
defaulting it to `CMAKE_INSTALL_PREFIX`. D99636 adopted that approach.
But, I think it is more ergonomic to allow those project-specific paths
to be relative the global ones. Also, making install paths absolute by
default inhibits the proper behavior of functions like
`GNUInstallDirs_get_absolute_install_dir` which make relative install
paths absolute in a more complicated way.
Given all this, I will define a function like the one asked for in
https://gitlab.kitware.com/cmake/cmake/-/issues/19568 (and needed for a
similar use-case).
---
Original message:
Instead of using `COMPILER_RT_INSTALL_PATH` through the CMake for
complier-rt, just use it to define variables for the subdirs which
themselves are used.
This preserves compatibility, but later on we might consider getting rid
of `COMPILER_RT_INSTALL_PATH` and just changing the defaults for the
subdir variables directly.
---
There was a seaming bug where the (non-Apple) per-target libdir was
`${target}` not `lib/${target}`. I suspect that has to do with the docs
on `COMPILER_RT_INSTALL_PATH` saying was the library dir when that's no
longer true, so I just went ahead and fixed it, allowing me to define
fewer and more sensible variables.
That last part should be the only behavior changes; everything else
should be a pure refactoring.
---
I added some documentation of these variables too. In particular, I
wanted to highlight the gotcha where `-DSomeCachePath=...` without the
`:PATH` will lead CMake to make the path absolute. See [1] for
discussion of the problem, and [2] for the brief official documentation
they added as a result.
[1]: https://cmake.org/pipermail/cmake/2015-March/060204.html
[2]: https://cmake.org/cmake/help/latest/manual/cmake.1.html#options
In 38b2dec37ee735d5409148e71ecba278caf0f969 the problem was somewhat
misidentified and so `:STRING` was used, but `:PATH` is better as it
sets the correct type from the get-go.
---
D99484 is the main thrust of the `GnuInstallDirs` work. Once this lands,
it should be feasible to follow both of these up with a simple patch for
compiler-rt analogous to the one for libcxx.
Reviewed By: phosek, #libc_abi, #libunwind
Differential Revision: https://reviews.llvm.org/D105765
2021-04-28 22:36:47 +00:00
D E S T I N A T I O N $ { C O M P I L E R _ R T _ I N S T A L L _ D A T A _ D I R }
2016-02-23 21:50:39 +00:00
C O M P O N E N T $ { c o m p o n e n t } )
add_dependencies ( ${ component } ${ target_name } )
2016-07-11 21:51:56 +00:00
set_target_properties ( ${ target_name } PROPERTIES FOLDER "Compiler-RT Misc" )
2013-05-21 13:48:27 +00:00
endmacro ( )
2014-02-27 08:41:40 +00:00
macro ( add_compiler_rt_script name )
set ( dst ${ COMPILER_RT_EXEC_OUTPUT_DIR } / ${ name } )
set ( src ${ CMAKE_CURRENT_SOURCE_DIR } / ${ name } )
add_custom_command ( OUTPUT ${ dst }
D E P E N D S $ { s r c }
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t $ { s r c } $ { d s t }
C O M M E N T " C o p y i n g $ { n a m e } . . . " )
add_custom_target ( ${ name } DEPENDS ${ dst } )
install ( FILES ${ dst }
P E R M I S S I O N S O W N E R _ R E A D O W N E R _ W R I T E O W N E R _ E X E C U T E G R O U P _ R E A D G R O U P _ E X E C U T E W O R L D _ R E A D W O R L D _ E X E C U T E
Prepare Compiler-RT for GnuInstallDirs, matching libcxx, document all
This is a second attempt at D101497, which landed as
9a9bc76c0eb72f0f2732c729a460abbd5239c2e3 but had to be reverted in
8cf7ddbdd4e5af966a369e170c73250f2e3920e7.
This issue was that in the case that `COMPILER_RT_INSTALL_PATH` is
empty, expressions like "${COMPILER_RT_INSTALL_PATH}/bin" evaluated to
"/bin" not "bin" as intended and as was originally.
One solution is to make `COMPILER_RT_INSTALL_PATH` always non-empty,
defaulting it to `CMAKE_INSTALL_PREFIX`. D99636 adopted that approach.
But, I think it is more ergonomic to allow those project-specific paths
to be relative the global ones. Also, making install paths absolute by
default inhibits the proper behavior of functions like
`GNUInstallDirs_get_absolute_install_dir` which make relative install
paths absolute in a more complicated way.
Given all this, I will define a function like the one asked for in
https://gitlab.kitware.com/cmake/cmake/-/issues/19568 (and needed for a
similar use-case).
---
Original message:
Instead of using `COMPILER_RT_INSTALL_PATH` through the CMake for
complier-rt, just use it to define variables for the subdirs which
themselves are used.
This preserves compatibility, but later on we might consider getting rid
of `COMPILER_RT_INSTALL_PATH` and just changing the defaults for the
subdir variables directly.
---
There was a seaming bug where the (non-Apple) per-target libdir was
`${target}` not `lib/${target}`. I suspect that has to do with the docs
on `COMPILER_RT_INSTALL_PATH` saying was the library dir when that's no
longer true, so I just went ahead and fixed it, allowing me to define
fewer and more sensible variables.
That last part should be the only behavior changes; everything else
should be a pure refactoring.
---
I added some documentation of these variables too. In particular, I
wanted to highlight the gotcha where `-DSomeCachePath=...` without the
`:PATH` will lead CMake to make the path absolute. See [1] for
discussion of the problem, and [2] for the brief official documentation
they added as a result.
[1]: https://cmake.org/pipermail/cmake/2015-March/060204.html
[2]: https://cmake.org/cmake/help/latest/manual/cmake.1.html#options
In 38b2dec37ee735d5409148e71ecba278caf0f969 the problem was somewhat
misidentified and so `:STRING` was used, but `:PATH` is better as it
sets the correct type from the get-go.
---
D99484 is the main thrust of the `GnuInstallDirs` work. Once this lands,
it should be feasible to follow both of these up with a simple patch for
compiler-rt analogous to the one for libcxx.
Reviewed By: phosek, #libc_abi, #libunwind
Differential Revision: https://reviews.llvm.org/D105765
2021-04-28 22:36:47 +00:00
D E S T I N A T I O N $ { C O M P I L E R _ R T _ I N S T A L L _ B I N A R Y _ D I R } )
2014-02-27 08:41:40 +00:00
endmacro ( add_compiler_rt_script src name )
2014-05-09 22:11:03 +00:00
# Builds custom version of libc++ and installs it in <prefix>.
# Can be used to build sanitized versions of libc++ for running unit tests.
# add_custom_libcxx(<name> <prefix>
# DEPS <list of build deps>
2018-01-21 01:01:53 +00:00
# CFLAGS <list of compile flags>
# USE_TOOLCHAIN)
2014-05-09 22:11:03 +00:00
macro ( add_custom_libcxx name prefix )
2017-12-12 01:20:52 +00:00
if ( NOT COMPILER_RT_LIBCXX_PATH )
2014-05-09 22:11:03 +00:00
message ( FATAL_ERROR "libcxx not found!" )
endif ( )
2019-02-17 12:16:20 +00:00
if ( NOT COMPILER_RT_LIBCXXABI_PATH )
message ( FATAL_ERROR "libcxxabi not found!" )
endif ( )
2014-05-09 22:11:03 +00:00
2018-01-21 01:01:53 +00:00
cmake_parse_arguments ( LIBCXX "USE_TOOLCHAIN" "" "DEPS;CFLAGS;CMAKE_ARGS" ${ ARGN } )
2014-05-09 22:11:03 +00:00
2018-01-21 01:01:53 +00:00
if ( LIBCXX_USE_TOOLCHAIN )
set ( compiler_args -DCMAKE_C_COMPILER= ${ COMPILER_RT_TEST_COMPILER }
- D C M A K E _ C X X _ C O M P I L E R = $ { C O M P I L E R _ R T _ T E S T _ C X X _ C O M P I L E R } )
2021-03-03 00:39:50 -08:00
if ( NOT COMPILER_RT_STANDALONE_BUILD AND NOT LLVM_RUNTIMES_BUILD )
2018-03-07 18:14:09 +00:00
set ( toolchain_deps $< TARGET_FILE:clang > )
set ( force_deps DEPENDS $< TARGET_FILE:clang > )
2018-01-21 01:01:53 +00:00
endif ( )
2018-01-21 03:22:22 +00:00
else ( )
set ( compiler_args -DCMAKE_C_COMPILER= ${ CMAKE_C_COMPILER }
- D C M A K E _ C X X _ C O M P I L E R = $ { C M A K E _ C X X _ C O M P I L E R } )
2018-01-21 01:01:53 +00:00
endif ( )
2018-03-07 18:14:09 +00:00
set ( STAMP_DIR ${ prefix } -stamps/ )
set ( BINARY_DIR ${ prefix } -bins/ )
add_custom_target ( ${ name } -clear
C O M M A N D $ { C M A K E _ C O M M A N D } - E r e m o v e _ d i r e c t o r y $ { B I N A R Y _ D I R }
C O M M A N D $ { C M A K E _ C O M M A N D } - E r e m o v e _ d i r e c t o r y $ { S T A M P _ D I R }
C O M M E N T " C l o b b e r i n g $ { n a m e } b u i l d a n d s t a m p d i r e c t o r i e s "
U S E S _ T E R M I N A L
)
2018-06-27 12:56:34 +00:00
set_target_properties ( ${ name } -clear PROPERTIES FOLDER "Compiler-RT Misc" )
2018-03-07 18:14:09 +00:00
add_custom_command (
O U T P U T $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { n a m e } - c l o b b e r - s t a m p
D E P E N D S $ { L I B C X X _ D E P S } $ { t o o l c h a i n _ d e p s }
C O M M A N D $ { C M A K E _ C O M M A N D } - E t o u c h $ { B I N A R Y _ D I R } / C M a k e C a c h e . t x t
C O M M A N D $ { C M A K E _ C O M M A N D } - E t o u c h $ { S T A M P _ D I R } / $ { n a m e } - m k d i r
C O M M A N D $ { C M A K E _ C O M M A N D } - E t o u c h $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { n a m e } - c l o b b e r - s t a m p
C O M M E N T " C l o b b e r i n g b o o t s t r a p b u i l d a n d s t a m p d i r e c t o r i e s "
)
add_custom_target ( ${ name } -clobber
D E P E N D S $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { n a m e } - c l o b b e r - s t a m p )
2018-06-27 12:56:34 +00:00
set_target_properties ( ${ name } -clobber PROPERTIES FOLDER "Compiler-RT Misc" )
2018-03-07 18:14:09 +00:00
2018-06-13 05:32:22 +00:00
set ( PASSTHROUGH_VARIABLES
C M A K E _ C _ C O M P I L E R _ T A R G E T
C M A K E _ C X X _ C O M P I L E R _ T A R G E T
2018-11-03 01:38:26 +00:00
C M A K E _ S H A R E D _ L I N K E R _ F L A G S
C M A K E _ M O D U L E _ L I N K E R _ F L A G S
C M A K E _ E X E _ L I N K E R _ F L A G S
2018-06-13 05:32:22 +00:00
C M A K E _ I N S T A L L _ P R E F I X
C M A K E _ M A K E _ P R O G R A M
C M A K E _ L I N K E R
C M A K E _ A R
C M A K E _ R A N L I B
C M A K E _ N M
C M A K E _ O B J C O P Y
C M A K E _ O B J D U M P
C M A K E _ S T R I P
C M A K E _ S Y S R O O T
2021-01-06 10:55:40 -08:00
L I B C X X _ H A S _ M U S L _ L I B C
2020-11-17 17:44:00 -06:00
P Y T H O N _ E X E C U T A B L E
P y t h o n 3 _ E X E C U T A B L E
P y t h o n 2 _ E X E C U T A B L E
2018-06-13 05:32:22 +00:00
C M A K E _ S Y S T E M _ N A M E )
foreach ( variable ${ PASSTHROUGH_VARIABLES } )
2018-11-03 01:38:26 +00:00
get_property ( is_value_set CACHE ${ variable } PROPERTY VALUE SET )
if ( ${ is_value_set } )
get_property ( value CACHE ${ variable } PROPERTY VALUE )
list ( APPEND CMAKE_PASSTHROUGH_VARIABLES -D ${ variable } = ${ value } )
2018-06-13 05:32:22 +00:00
endif ( )
endforeach ( )
2018-10-31 22:40:25 +00:00
string ( REPLACE ";" " " LIBCXX_C_FLAGS "${LIBCXX_CFLAGS}" )
get_property ( C_FLAGS CACHE CMAKE_C_FLAGS PROPERTY VALUE )
set ( LIBCXX_C_FLAGS "${LIBCXX_C_FLAGS} ${C_FLAGS}" )
string ( REPLACE ";" " " LIBCXX_CXX_FLAGS "${LIBCXX_CFLAGS}" )
get_property ( CXX_FLAGS CACHE CMAKE_CXX_FLAGS PROPERTY VALUE )
set ( LIBCXX_CXX_FLAGS "${LIBCXX_CXX_FLAGS} ${CXX_FLAGS}" )
2018-06-07 19:57:43 +00:00
2014-05-09 22:11:03 +00:00
ExternalProject_Add ( ${ name }
2018-03-07 18:14:09 +00:00
D E P E N D S $ { n a m e } - c l o b b e r $ { L I B C X X _ D E P S }
2014-05-09 22:11:03 +00:00
P R E F I X $ { p r e f i x }
2019-02-17 12:16:20 +00:00
S O U R C E _ D I R $ { C O M P I L E R _ R T _ S O U R C E _ D I R } / c m a k e / M o d u l e s / C u s t o m L i b c x x
2018-03-07 18:14:09 +00:00
S T A M P _ D I R $ { S T A M P _ D I R }
B I N A R Y _ D I R $ { B I N A R Y _ D I R }
2018-06-13 05:32:22 +00:00
C M A K E _ A R G S $ { C M A K E _ P A S S T H R O U G H _ V A R I A B L E S }
2018-01-21 01:01:53 +00:00
$ { c o m p i l e r _ a r g s }
2018-03-07 18:14:09 +00:00
- D C M A K E _ C _ F L A G S = $ { L I B C X X _ C _ F L A G S }
- D C M A K E _ C X X _ F L A G S = $ { L I B C X X _ C X X _ F L A G S }
2014-05-09 22:11:03 +00:00
- D C M A K E _ B U I L D _ T Y P E = R e l e a s e
2019-03-15 17:52:27 +00:00
- D C M A K E _ T R Y _ C O M P I L E _ T A R G E T _ T Y P E = S T A T I C _ L I B R A R Y
2016-02-02 12:55:28 +00:00
- D L L V M _ P A T H = $ { L L V M _ M A I N _ S R C _ D I R }
2018-03-07 18:14:09 +00:00
- D L L V M _ B I N A R Y _ D I R = $ { p r e f i x }
- D L L V M _ L I B R A R Y _ O U T P U T _ I N T D I R = $ { p r e f i x } / l i b
2019-02-17 12:16:20 +00:00
- D C O M P I L E R _ R T _ L I B C X X _ P A T H = $ { C O M P I L E R _ R T _ L I B C X X _ P A T H }
- D C O M P I L E R _ R T _ L I B C X X A B I _ P A T H = $ { C O M P I L E R _ R T _ L I B C X X A B I _ P A T H }
2017-12-21 20:04:10 +00:00
$ { L I B C X X _ C M A K E _ A R G S }
2018-03-07 18:14:09 +00:00
I N S T A L L _ C O M M A N D " "
S T E P _ T A R G E T S c o n f i g u r e b u i l d
B U I L D _ A L W A Y S 1
U S E S _ T E R M I N A L _ C O N F I G U R E 1
U S E S _ T E R M I N A L _ B U I L D 1
U S E S _ T E R M I N A L _ I N S T A L L 1
2018-01-21 01:01:53 +00:00
E X C L U D E _ F R O M _ A L L T R U E
2019-10-29 15:04:43 -07:00
B U I L D _ B Y P R O D U C T S " $ { p r e f i x } / l i b / l i b c + + . a " " $ { p r e f i x } / l i b / l i b c + + a b i . a "
2014-05-09 22:11:03 +00:00
)
2018-03-07 18:14:09 +00:00
if ( CMAKE_GENERATOR MATCHES "Make" )
set ( run_clean "$(MAKE)" "-C" "${BINARY_DIR}" "clean" )
else ( )
set ( run_clean ${ CMAKE_COMMAND } --build ${ BINARY_DIR } --target clean
2019-03-30 14:38:51 +00:00
- - c o n f i g " $ < C O N F I G > " )
2018-03-07 18:14:09 +00:00
endif ( )
2014-05-09 22:11:03 +00:00
2018-03-07 18:14:09 +00:00
ExternalProject_Add_Step ( ${ name } clean
C O M M A N D $ { r u n _ c l e a n }
C O M M E N T " C l e a n i n g $ { n a m e } . . . "
D E P E N D E E S c o n f i g u r e
2018-01-21 01:01:53 +00:00
$ { f o r c e _ d e p s }
2018-03-07 18:14:09 +00:00
W O R K I N G _ D I R E C T O R Y $ { B I N A R Y _ D I R }
E X C L U D E _ F R O M _ M A I N 1
U S E S _ T E R M I N A L 1
2014-05-09 22:11:03 +00:00
)
2018-03-07 18:14:09 +00:00
ExternalProject_Add_StepTargets ( ${ name } clean )
if ( LIBCXX_USE_TOOLCHAIN )
add_dependencies ( ${ name } -clean ${ name } -clobber )
set_target_properties ( ${ name } -clean PROPERTIES
S O U R C E S $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { n a m e } - c l o b b e r - s t a m p )
endif ( )
2014-05-09 22:11:03 +00:00
endmacro ( )
2015-12-03 20:08:22 +00:00
function ( rt_externalize_debuginfo name )
if ( NOT COMPILER_RT_EXTERNALIZE_DEBUGINFO )
return ( )
endif ( )
2016-03-31 21:17:19 +00:00
if ( NOT COMPILER_RT_EXTERNALIZE_DEBUGINFO_SKIP_STRIP )
set ( strip_command COMMAND xcrun strip -Sl $< TARGET_FILE:${name} > )
endif ( )
2015-12-03 20:08:22 +00:00
if ( APPLE )
if ( CMAKE_CXX_FLAGS MATCHES "-flto"
O R C M A K E _ C X X _ F L A G S _ $ { u p p e r c a s e _ C M A K E _ B U I L D _ T Y P E } M A T C H E S " - f l t o " )
set ( lto_object ${ CMAKE_CURRENT_BINARY_DIR } / ${ CMAKE_CFG_INTDIR } / ${ name } -lto.o )
2015-12-03 22:52:22 +00:00
set_property ( TARGET ${ name } APPEND_STRING PROPERTY
2015-12-03 22:56:21 +00:00
L I N K _ F L A G S " - W l , - o b j e c t _ p a t h _ l t o - W l , $ { l t o _ o b j e c t } " )
2015-12-03 20:08:22 +00:00
endif ( )
add_custom_command ( TARGET ${ name } POST_BUILD
C O M M A N D x c r u n d s y m u t i l $ < T A R G E T _ F I L E : $ { n a m e } >
2016-03-31 21:17:19 +00:00
$ { s t r i p _ c o m m a n d } )
2015-12-03 20:08:22 +00:00
else ( )
message ( FATAL_ERROR "COMPILER_RT_EXTERNALIZE_DEBUGINFO isn't implemented for non-darwin platforms!" )
endif ( )
endfunction ( )
2017-11-13 12:57:54 +00:00
# Configure lit configuration files, including compiler-rt specific variables.
function ( configure_compiler_rt_lit_site_cfg input output )
set_llvm_build_mode ( )
2018-06-28 03:11:52 +00:00
get_compiler_rt_output_dir ( ${ COMPILER_RT_DEFAULT_TARGET_ARCH } output_dir )
2017-11-13 12:57:54 +00:00
string ( REPLACE ${ CMAKE_CFG_INTDIR } ${ LLVM_BUILD_MODE } COMPILER_RT_RESOLVED_TEST_COMPILER ${ COMPILER_RT_TEST_COMPILER } )
2018-06-28 03:11:52 +00:00
string ( REPLACE ${ CMAKE_CFG_INTDIR } ${ LLVM_BUILD_MODE } COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR ${ output_dir } )
2017-11-13 12:57:54 +00:00
configure_lit_site_cfg ( ${ input } ${ output } )
endfunction ( )