2014-05-10 06:11:03 +08:00
include ( ExternalProject )
2013-01-19 00:05:21 +08:00
include ( CompilerRTUtils )
2020-03-28 07:17:52 +08:00
include ( HandleCompilerRT )
2012-12-19 20:33:39 +08:00
2016-07-12 05:51:56 +08: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-11 07:55:07 +08: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 11:39:24 +08:00
# OS <os names>
# ARCHS <architectures>
2015-06-11 07:55:07 +08:00
# SOURCES <source files>
# CFLAGS <compile flags>
2018-06-13 15:08:28 +08:00
# DEFS <compile definitions>
2018-07-10 21:00:17 +08:00
# DEPS <dependencies>
# ADDITIONAL_HEADERS <header files>)
2015-06-11 07:55:07 +08:00
function ( add_compiler_rt_object_libraries name )
2018-07-10 21:00:17 +08:00
cmake_parse_arguments ( LIB "" "" "OS;ARCHS;SOURCES;CFLAGS;DEFS;DEPS;ADDITIONAL_HEADERS"
$ { A R G N } )
2015-06-11 07:55:07 +08: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 17:28:01 +08:00
list_intersect ( LIB_ARCHS_ ${ libname } DARWIN_ ${ os } _ARCHS LIB_ARCHS )
2015-06-11 07:55:07 +08:00
endforeach ( )
2013-01-19 00:05:21 +08:00
else ( )
2015-06-19 11:39:24 +08:00
foreach ( arch ${ LIB_ARCHS } )
2015-06-11 07:55:07 +08:00
set ( libname "${name}.${arch}" )
set ( libnames ${ libnames } ${ libname } )
set ( extra_cflags_ ${ libname } ${ TARGET_${arch } _CFLAGS} )
if ( NOT CAN_TARGET_ ${ arch } )
2015-08-11 02:26:29 +08:00
message ( FATAL_ERROR "Architecture ${arch} can't be targeted" )
2015-06-11 07:55:07 +08:00
return ( )
endif ( )
endforeach ( )
2013-01-19 00:05:21 +08:00
endif ( )
2016-07-12 05:51:56 +08:00
2018-07-10 21:00:17 +08: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-11 07:55:07 +08:00
foreach ( libname ${ libnames } )
add_library ( ${ libname } OBJECT ${ LIB_SOURCES } )
2018-06-13 15:08:28 +08:00
if ( LIB_DEPS )
add_dependencies ( ${ libname } ${ LIB_DEPS } )
endif ( )
2017-09-07 09:36:47 +08: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-12 01:31:18 +08: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-19 02:04:28 +08: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-11 07:55:07 +08: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-12 05:51:56 +08:00
set_target_properties ( ${ libname } PROPERTIES FOLDER "Compiler-RT Libraries" )
2015-06-11 07:55:07 +08: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-14 04:38:16 +08: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-11 07:55:07 +08:00
endif ( )
endforeach ( )
endfunction ( )
2013-01-20 22:36:12 +08:00
2015-08-27 02:33:51 +08: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-27 04:52:22 +08: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-30 03:27:25 +08:00
function ( add_asm_sources output )
set ( ${ output } ${ ARGN } PARENT_SCOPE )
2020-08-21 01:17:47 +08: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 21:23:50 +08:00
set_source_files_properties ( ${ ARGN } PROPERTIES LANGUAGE C )
endif ( )
2017-11-30 03:27:25 +08:00
endfunction ( )
2017-08-30 06:12:31 +08:00
macro ( set_output_name output name arch )
2018-06-28 11:11:52 +08:00
if ( LLVM_ENABLE_PER_TARGET_RUNTIME_DIR )
set ( ${ output } ${ name } )
2017-08-30 06:12:31 +08:00
else ( )
2018-06-28 11:11:52 +08:00
if ( ANDROID AND ${ arch } STREQUAL "i386" )
set ( ${ output } "${name}-i686${COMPILER_RT_OS_SUFFIX}" )
else ( )
set ( ${ output } "${name}-${arch}${COMPILER_RT_OS_SUFFIX}" )
endif ( )
2017-08-30 06:12:31 +08:00
endif ( )
endmacro ( )
2015-08-26 03:53:09 +08: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>
2019-05-01 02:13:22 +08:00
# {OBJECT|STATIC|SHARED}
2015-08-26 03:53:09 +08:00
# ARCHS <architectures>
# OS <os list>
2014-03-31 21:45:36 +08:00
# SOURCES <source files>
# CFLAGS <compile flags>
2017-01-10 12:33:04 +08:00
# LINK_FLAGS <linker flags>
2014-09-29 21:18:55 +08:00
# DEFS <compile definitions>
2020-10-07 02:32:57 +08:00
# DEPS <dependencies>
2015-08-26 03:53:09 +08:00
# LINK_LIBS <linked libraries> (only for shared library)
2015-08-27 02:33:51 +08:00
# OBJECT_LIBS <object libraries to use as sources>
2018-07-10 21:00:17 +08:00
# PARENT_TARGET <convenience parent target>
# ADDITIONAL_HEADERS <header files>)
2015-08-26 03:53:09 +08:00
function ( add_compiler_rt_runtime name type )
2019-05-01 02:13:22 +08:00
if ( NOT type MATCHES "^(OBJECT|STATIC|SHARED)$" )
message ( FATAL_ERROR "type argument must be OBJECT, STATIC or SHARED" )
2015-08-26 03:53:09 +08:00
return ( )
endif ( )
cmake_parse_arguments ( LIB
" "
" P A R E N T _ T A R G E T "
2020-10-07 02:32:57 +08: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-26 03:53:09 +08:00
$ { A R G N } )
set ( libnames )
2017-03-23 01:25:49 +08: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-02 07:23:59 +08:00
2020-03-10 06:25:41 +08: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 21:00:17 +08: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-26 03:53:09 +08:00
if ( APPLE )
foreach ( os ${ LIB_OS } )
2017-09-02 07:23:59 +08: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-26 03:53:09 +08:00
if ( type STREQUAL "STATIC" )
set ( libname "${name}_${os}" )
else ( )
set ( libname "${name}_${os}_dynamic" )
2017-01-10 12:33:04 +08:00
set ( extra_link_flags_ ${ libname } ${ DARWIN_${os } _LINK_FLAGS} ${ LIB_LINK_FLAGS } )
2015-08-26 03:53:09 +08:00
endif ( )
2016-01-27 17:28:01 +08:00
list_intersect ( LIB_ARCHS_ ${ libname } DARWIN_ ${ os } _ARCHS LIB_ARCHS )
2015-08-26 03:53:09 +08:00
if ( LIB_ARCHS_ ${ libname } )
list ( APPEND libnames ${ libname } )
2020-03-10 06:25:41 +08:00
set ( extra_cflags_ ${ libname } ${ DARWIN_${os } _CFLAGS} ${ NO_LTO_FLAGS } ${ NO_PGO_FLAGS } ${ LIB_CFLAGS } )
2015-08-26 03:53:09 +08:00
set ( output_name_ ${ libname } ${ libname } ${ COMPILER_RT_OS_SUFFIX } )
2015-08-27 02:33:51 +08:00
set ( sources_ ${ libname } ${ LIB_SOURCES } )
format_object_libs ( sources_ ${ libname } ${ os } ${ LIB_OBJECT_LIBS } )
2018-06-28 11:11:52 +08: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-26 03:53:09 +08:00
endif ( )
endforeach ( )
2013-01-20 21:58:10 +08:00
else ( )
2015-08-26 03:53:09 +08:00
foreach ( arch ${ LIB_ARCHS } )
if ( NOT CAN_TARGET_ ${ arch } )
message ( FATAL_ERROR "Architecture ${arch} can't be targeted" )
return ( )
endif ( )
2019-05-01 02:13:22 +08: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-26 03:53:09 +08:00
set ( libname "${name}-${arch}" )
2017-08-30 06:12:31 +08:00
set_output_name ( output_name_ ${ libname } ${ name } ${ arch } )
2015-08-26 03:53:09 +08:00
else ( )
set ( libname "${name}-dynamic-${arch}" )
2016-06-21 22:46:32 +08:00
set ( extra_cflags_ ${ libname } ${ TARGET_${arch } _CFLAGS} ${ LIB_CFLAGS } )
2017-01-10 12:33:04 +08:00
set ( extra_link_flags_ ${ libname } ${ TARGET_${arch } _LINK_FLAGS} ${ LIB_LINK_FLAGS } )
2015-08-26 03:53:09 +08:00
if ( WIN32 )
2017-08-30 06:12:31 +08:00
set_output_name ( output_name_ ${ libname } ${ name } _dynamic ${ arch } )
2015-08-26 03:53:09 +08:00
else ( )
2017-08-30 06:12:31 +08:00
set_output_name ( output_name_ ${ libname } ${ name } ${ arch } )
2015-08-26 03:53:09 +08:00
endif ( )
endif ( )
2020-05-18 16:04:42 +08: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-28 07:17:52 +08:00
get_compiler_rt_target ( ${ arch } target )
find_compiler_rt_library ( builtins ${ target } builtins_ ${ libname } )
2020-05-18 16:04:42 +08: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-28 07:17:52 +08:00
endif ( )
2015-08-27 02:33:51 +08:00
set ( sources_ ${ libname } ${ LIB_SOURCES } )
format_object_libs ( sources_ ${ libname } ${ arch } ${ LIB_OBJECT_LIBS } )
2015-08-26 03:53:09 +08:00
set ( libnames ${ libnames } ${ libname } )
2020-03-10 06:25:41 +08:00
set ( extra_cflags_ ${ libname } ${ TARGET_${arch } _CFLAGS} ${ NO_LTO_FLAGS } ${ NO_PGO_FLAGS } ${ LIB_CFLAGS } )
2018-06-28 11:11:52 +08:00
get_compiler_rt_output_dir ( ${ arch } output_dir_ ${ libname } )
get_compiler_rt_install_dir ( ${ arch } install_dir_ ${ libname } )
2015-08-26 03:53:09 +08:00
endforeach ( )
2013-01-20 21:58:10 +08:00
endif ( )
2015-08-26 03:53:09 +08:00
if ( NOT libnames )
return ( )
endif ( )
if ( LIB_PARENT_TARGET )
2016-02-24 05:55:38 +08: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 20:56:34 +08: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-24 05:55:38 +08:00
endif ( )
2015-08-26 03:53:09 +08:00
endif ( )
2015-08-19 01:32:18 +08:00
2015-08-26 03:53:09 +08:00
foreach ( libname ${ libnames } )
2016-07-12 05:51:56 +08:00
# If you are using a multi-configuration generator we don't generate
2016-02-24 05:55:38 +08: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-05-01 02:13:22 +08:00
if ( type STREQUAL "OBJECT" )
2019-05-01 10:49:45 +08:00
if ( CMAKE_C_COMPILER_ID MATCHES Clang AND CMAKE_C_COMPILER_TARGET )
2019-05-01 13:41:58 +08:00
list ( APPEND extra_cflags_ ${ libname } "--target=${CMAKE_C_COMPILER_TARGET}" )
2019-05-01 11:30:51 +08:00
endif ( )
if ( CMAKE_SYSROOT )
2019-05-01 13:41:58 +08:00
list ( APPEND extra_cflags_ ${ libname } "--sysroot=${CMAKE_SYSROOT}" )
2019-05-01 10:49:45 +08: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 11:29:15 +08:00
2019-05-01 10:49:45 +08:00
set ( output_file_ ${ libname } ${ output_name_${libname } } ${ CMAKE_C_OUTPUT_EXTENSION } )
foreach ( substitution ${ substitutions } )
if ( substitution STREQUAL "<CMAKE_C_COMPILER>" )
2019-05-19 11:29:15 +08:00
string ( REPLACE "<CMAKE_C_COMPILER>" "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}"
2019-05-01 10:49:45 +08: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 13:41:58 +08:00
string ( REPLACE "<FLAGS>" "${CMAKE_C_FLAGS} ${extra_cflags_${libname}}"
2019-05-01 10:49:45 +08: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-05-01 02:13:22 +08:00
add_custom_command (
2019-05-01 10:49:45 +08: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-05-01 02:13:22 +08: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 10:49:45 +08: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-05-01 02:13:22 +08: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-07 02:32:57 +08:00
if ( LIB_DEPS )
add_dependencies ( ${ libname } ${ LIB_DEPS } )
endif ( )
2015-08-26 03:53:09 +08: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-12 05:51:56 +08:00
set_target_properties ( ${ libname } PROPERTIES FOLDER "Compiler-RT Runtime" )
2017-08-22 07:25:50 +08:00
if ( LIB_LINK_LIBS )
2019-02-07 14:32:09 +08:00
target_link_libraries ( ${ libname } PRIVATE ${ LIB_LINK_LIBS } )
2017-08-22 07:25:50 +08:00
endif ( )
2020-03-28 07:17:52 +08:00
if ( builtins_ ${ libname } )
target_link_libraries ( ${ libname } PRIVATE ${ builtins_${libname } } )
endif ( )
2016-09-08 04:32:48 +08:00
if ( ${ type } STREQUAL "SHARED" )
2018-01-28 05:14:17 +08:00
if ( COMMAND llvm_setup_rpath )
llvm_setup_rpath ( ${ libname } )
endif ( )
2016-09-08 04:32:48 +08: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-27 02:59:22 +08: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 } >
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 _ L I B R A R Y _ O U T P U T _ D I R }
)
endif ( )
2015-08-26 03:53:09 +08:00
endif ( )
2016-02-24 05:55:38 +08:00
2019-05-08 03:00:37 +08:00
set ( parent_target_arg )
if ( LIB_PARENT_TARGET )
set ( parent_target_arg PARENT_TARGET ${ LIB_PARENT_TARGET } )
2016-02-24 05:55:38 +08:00
endif ( )
2019-05-08 03:00:37 +08:00
add_compiler_rt_install_targets ( ${ libname } ${ parent_target_arg } )
2015-08-26 03:53:09 +08: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-04 04:08:22 +08:00
if ( type STREQUAL "SHARED" )
rt_externalize_debuginfo ( ${ libname } )
endif ( )
2015-08-26 03:53:09 +08:00
endforeach ( )
if ( LIB_PARENT_TARGET )
2016-02-27 04:59:40 +08:00
add_dependencies ( ${ LIB_PARENT_TARGET } ${ libnames } )
2015-08-19 01:32:18 +08:00
endif ( )
endfunction ( )
2013-01-21 16:12:20 +08:00
2016-01-15 02:18:49 +08:00
# when cross compiling, COMPILER_RT_TEST_COMPILER_CFLAGS help
# in compilation and linking of unittests.
string ( REPLACE " " ";" COMPILER_RT_UNITTEST_CFLAGS "${COMPILER_RT_TEST_COMPILER_CFLAGS}" )
2017-01-10 12:33:04 +08:00
set ( COMPILER_RT_UNITTEST_LINK_FLAGS ${ COMPILER_RT_UNITTEST_CFLAGS } )
2014-05-30 20:42:57 +08:00
2013-01-19 00:05:21 +08:00
# Unittests support.
2012-12-19 20:33:39 +08:00
set ( COMPILER_RT_GTEST_PATH ${ LLVM_MAIN_SRC_DIR } /utils/unittest/googletest )
2013-11-15 18:21:15 +08:00
set ( COMPILER_RT_GTEST_SOURCE ${ COMPILER_RT_GTEST_PATH } /src/gtest-all.cc )
2014-03-24 21:29:20 +08:00
set ( COMPILER_RT_GTEST_CFLAGS
2019-08-21 21:56:29 +08:00
- D G T E S T _ N O _ L L V M _ S U P P O R T = 1
2014-05-28 16:38:13 +08:00
- D G T E S T _ H A S _ R T T I = 0
2012-12-19 20:33:39 +08:00
- I $ { C O M P I L E R _ R T _ G T E S T _ P A T H } / i n c l u d e
2013-11-15 18:21:15 +08:00
- I $ { C O M P I L E R _ R T _ G T E S T _ P A T H }
2012-12-19 20:33:39 +08:00
)
2018-09-20 13:22:37 +08:00
# Mocking support.
set ( COMPILER_RT_GMOCK_PATH ${ LLVM_MAIN_SRC_DIR } /utils/unittest/googlemock )
set ( COMPILER_RT_GMOCK_SOURCE ${ COMPILER_RT_GMOCK_PATH } /src/gmock-all.cc )
set ( COMPILER_RT_GMOCK_CFLAGS
2019-08-21 21:56:29 +08:00
- D G T E S T _ N O _ L L V M _ S U P P O R T = 1
2018-09-20 13:22:37 +08:00
- D G T E S T _ H A S _ R T T I = 0
- I $ { C O M P I L E R _ R T _ G M O C K _ P A T H } / i n c l u d e
- I $ { C O M P I L E R _ R T _ G M O C K _ P A T H }
)
2016-01-15 02:18:49 +08:00
append_list_if ( COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 COMPILER_RT_UNITTEST_CFLAGS )
2017-01-05 11:41:41 +08:00
append_list_if ( COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG -Wno-covered-switch-default COMPILER_RT_UNITTEST_CFLAGS )
2020-07-23 08:44:52 +08:00
append_list_if ( COMPILER_RT_HAS_WSUGGEST_OVERRIDE_FLAG -Wno-suggest-override COMPILER_RT_UNITTEST_CFLAGS )
2015-01-07 04:58:40 +08:00
2014-05-28 16:38:13 +08:00
if ( MSVC )
2014-05-30 20:42:57 +08:00
# gtest use a lot of stuff marked as deprecated on Windows.
list ( APPEND COMPILER_RT_GTEST_CFLAGS -Wno-deprecated-declarations )
2014-05-28 16:38:13 +08:00
endif ( )
2017-08-16 06:56:10 +08: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-16 07:22:52 +08: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-16 06:56:10 +08:00
)
set ( "${test_objects}" "${${test_objects}}" PARENT_SCOPE )
endfunction ( )
2014-02-19 21:01:03 +08: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 20:33:39 +08:00
# test_suite.
2017-08-16 06:56:10 +08:00
# add_compiler_rt_test(<test_suite> <test_name> <arch>
2014-12-18 07:14:01 +08:00
# SUBDIR <subdirectory for binary>
2012-12-19 20:33:39 +08:00
# OBJECTS <object files>
# DEPS <deps (e.g. runtime libs)>
# LINK_FLAGS <link flags>)
2017-08-16 06:56:10 +08:00
function ( add_compiler_rt_test test_suite test_name arch )
2015-06-19 11:39:24 +08:00
cmake_parse_arguments ( TEST "" "SUBDIR" "OBJECTS;DEPS;LINK_FLAGS" "" ${ ARGN } )
2017-08-16 02:32:28 +08:00
set ( output_dir ${ CMAKE_CURRENT_BINARY_DIR } )
2014-12-18 07:14:01 +08:00
if ( TEST_SUBDIR )
2017-08-16 02:32:28 +08:00
set ( output_dir "${output_dir}/${TEST_SUBDIR}" )
2014-12-18 07:14:01 +08:00
endif ( )
2017-08-16 02:32:28 +08:00
set ( output_dir "${output_dir}/${CMAKE_CFG_INTDIR}" )
file ( MAKE_DIRECTORY "${output_dir}" )
set ( output_bin "${output_dir}/${test_name}" )
2015-01-22 22:54:22 +08:00
if ( MSVC )
set ( output_bin "${output_bin}.exe" )
endif ( )
2016-05-16 22:58:07 +08:00
2014-02-19 21:01:03 +08: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-16 06:56:10 +08:00
get_target_flags_for_arch ( ${ arch } TARGET_LINK_FLAGS )
list ( APPEND TEST_LINK_FLAGS ${ TARGET_LINK_FLAGS } )
2014-05-16 00:33:58 +08: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 23:21:49 +08: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-16 00:33:58 +08:00
set ( TEST_LINK_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${TEST_LINK_FLAGS}" )
separate_arguments ( TEST_LINK_FLAGS )
endif ( )
2019-12-28 08: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 10:06:34 +08: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-22 05:19:13 +08: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 20:33:39 +08:00
$ { T E S T _ L I N K _ F L A G S }
2017-08-22 05:19:13 +08: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-12 05:51:56 +08:00
2012-12-19 20:33:39 +08:00
# Make the test suite depend on the binary.
2017-08-22 05:19:13 +08:00
add_dependencies ( ${ test_suite } T ${ test_name } )
2017-08-16 02:32:28 +08:00
endfunction ( )
2013-05-21 21:48:27 +08:00
2016-02-24 05:50:39 +08:00
macro ( add_compiler_rt_resource_file target_name file_name component )
2013-05-21 21:48:27 +08:00
set ( src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}" )
2018-01-14 11:43:14 +08:00
set ( dst_file "${COMPILER_RT_OUTPUT_DIR}/share/${file_name}" )
2014-02-27 15:22:59 +08:00
add_custom_command ( OUTPUT ${ dst_file }
D E P E N D S $ { s r c _ f i l e }
2013-05-21 21:48:27 +08: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 15:22:59 +08: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 21:48:27 +08:00
# Install in Clang resource directory.
2016-02-24 05:50:39 +08:00
install ( FILES ${ file_name }
2018-01-14 11:43:14 +08: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 _ P A T H } / s h a r e
2016-02-24 05:50:39 +08: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-12 05:51:56 +08:00
set_target_properties ( ${ target_name } PROPERTIES FOLDER "Compiler-RT Misc" )
2013-05-21 21:48:27 +08:00
endmacro ( )
2014-02-27 16:41:40 +08: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
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 _ P A T H } / b i n )
endmacro ( add_compiler_rt_script src name )
2014-05-10 06:11:03 +08: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 09:01:53 +08:00
# CFLAGS <list of compile flags>
# USE_TOOLCHAIN)
2014-05-10 06:11:03 +08:00
macro ( add_custom_libcxx name prefix )
2017-12-12 09:20:52 +08:00
if ( NOT COMPILER_RT_LIBCXX_PATH )
2014-05-10 06:11:03 +08:00
message ( FATAL_ERROR "libcxx not found!" )
endif ( )
2019-02-17 20:16:20 +08:00
if ( NOT COMPILER_RT_LIBCXXABI_PATH )
message ( FATAL_ERROR "libcxxabi not found!" )
endif ( )
2014-05-10 06:11:03 +08:00
2018-01-21 09:01:53 +08:00
cmake_parse_arguments ( LIBCXX "USE_TOOLCHAIN" "" "DEPS;CFLAGS;CMAKE_ARGS" ${ ARGN } )
2014-05-10 06:11:03 +08:00
2018-01-21 09:01:53 +08: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 } )
2019-02-09 11:06:56 +08:00
if ( NOT COMPILER_RT_STANDALONE_BUILD AND NOT RUNTIMES_BUILD )
2018-03-08 02:14:09 +08:00
set ( toolchain_deps $< TARGET_FILE:clang > )
set ( force_deps DEPENDS $< TARGET_FILE:clang > )
2018-01-21 09:01:53 +08:00
endif ( )
2018-01-21 11:22:22 +08: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 09:01:53 +08:00
endif ( )
2018-03-08 02:14:09 +08: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 20:56:34 +08:00
set_target_properties ( ${ name } -clear PROPERTIES FOLDER "Compiler-RT Misc" )
2018-03-08 02:14:09 +08: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 20:56:34 +08:00
set_target_properties ( ${ name } -clobber PROPERTIES FOLDER "Compiler-RT Misc" )
2018-03-08 02:14:09 +08:00
2018-06-13 13:32:22 +08: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 09:38:26 +08: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 13:32:22 +08: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
C M A K E _ S Y S T E M _ N A M E )
foreach ( variable ${ PASSTHROUGH_VARIABLES } )
2018-11-03 09:38:26 +08: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 13:32:22 +08:00
endif ( )
endforeach ( )
2018-11-01 06:40:25 +08: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-08 03:57:43 +08:00
2014-05-10 06:11:03 +08:00
ExternalProject_Add ( ${ name }
2018-03-08 02:14:09 +08: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-10 06:11:03 +08:00
P R E F I X $ { p r e f i x }
2019-02-17 20:16:20 +08: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-08 02:14:09 +08: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 13:32:22 +08: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 09:01:53 +08:00
$ { c o m p i l e r _ a r g s }
2018-03-08 02:14:09 +08: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-10 06:11:03 +08: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-16 01:52:27 +08: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 20:55:28 +08: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-08 02:14:09 +08: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 20:16:20 +08: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-22 04:04:10 +08:00
$ { L I B C X X _ C M A K E _ A R G S }
2018-03-08 02:14:09 +08: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 09:01:53 +08:00
E X C L U D E _ F R O M _ A L L T R U E
2019-10-30 06:04:43 +08: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-10 06:11:03 +08:00
)
2018-03-08 02:14:09 +08: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 22:38:51 +08:00
- - c o n f i g " $ < C O N F I G > " )
2018-03-08 02:14:09 +08:00
endif ( )
2014-05-10 06:11:03 +08:00
2018-03-08 02:14:09 +08: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 09:01:53 +08:00
$ { f o r c e _ d e p s }
2018-03-08 02:14:09 +08: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-10 06:11:03 +08:00
)
2018-03-08 02:14:09 +08: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-10 06:11:03 +08:00
endmacro ( )
2015-12-04 04:08:22 +08:00
function ( rt_externalize_debuginfo name )
if ( NOT COMPILER_RT_EXTERNALIZE_DEBUGINFO )
return ( )
endif ( )
2016-04-01 05:17:19 +08:00
if ( NOT COMPILER_RT_EXTERNALIZE_DEBUGINFO_SKIP_STRIP )
set ( strip_command COMMAND xcrun strip -Sl $< TARGET_FILE:${name} > )
endif ( )
2015-12-04 04:08:22 +08: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-04 06:52:22 +08:00
set_property ( TARGET ${ name } APPEND_STRING PROPERTY
2015-12-04 06:56:21 +08: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-04 04:08:22 +08: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-04-01 05:17:19 +08:00
$ { s t r i p _ c o m m a n d } )
2015-12-04 04:08:22 +08:00
else ( )
message ( FATAL_ERROR "COMPILER_RT_EXTERNALIZE_DEBUGINFO isn't implemented for non-darwin platforms!" )
endif ( )
endfunction ( )
2017-11-13 20:57:54 +08: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 11:11:52 +08:00
get_compiler_rt_output_dir ( ${ COMPILER_RT_DEFAULT_TARGET_ARCH } output_dir )
2017-11-13 20:57:54 +08:00
string ( REPLACE ${ CMAKE_CFG_INTDIR } ${ LLVM_BUILD_MODE } COMPILER_RT_RESOLVED_TEST_COMPILER ${ COMPILER_RT_TEST_COMPILER } )
2018-06-28 11:11:52 +08:00
string ( REPLACE ${ CMAKE_CFG_INTDIR } ${ LLVM_BUILD_MODE } COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR ${ output_dir } )
2017-11-13 20:57:54 +08:00
configure_lit_site_cfg ( ${ input } ${ output } )
endfunction ( )