Skip to content

Commit

Permalink
[CMake][compiler-rt] Use COMPILE_OPTIONS and LINK_OPTIONS
Browse files Browse the repository at this point in the history
This avoids the need for string-ification and lets CMake deduplicate
potentially duplicate flags.

Differential Revision: https://reviews.llvm.org/D122750
  • Loading branch information
petrhosek committed Jun 24, 2022
1 parent 44ee3ef commit 30dfe01
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
9 changes: 3 additions & 6 deletions compiler-rt/cmake/Modules/AddCompilerRT.cmake
Expand Up @@ -83,8 +83,7 @@ function(add_compiler_rt_object_libraries name)
"${libname}" MATCHES ".*\.osx.*")
foreach(arch ${LIB_ARCHS_${libname}})
list(APPEND target_flags
-target ${arch}-apple-macos${DARWIN_osx_MIN_VER}
-darwin-target-variant ${arch}-apple-ios13.1-macabi)
"SHELL:-target ${arch}-apple-macos${DARWIN_osx_MIN_VER} -darwin-target-variant ${arch}-apple-ios13.1-macabi")
endforeach()
endif()

Expand Down Expand Up @@ -251,11 +250,9 @@ function(add_compiler_rt_runtime name type)
"${os}" MATCHES "^(osx)$")
foreach(arch ${LIB_ARCHS_${libname}})
list(APPEND extra_cflags_${libname}
-target ${arch}-apple-macos${DARWIN_osx_MIN_VER}
-darwin-target-variant ${arch}-apple-ios13.1-macabi)
"SHELL:-target ${arch}-apple-macos${DARWIN_osx_MIN_VER} -darwin-target-variant ${arch}-apple-ios13.1-macabi")
list(APPEND extra_link_flags_${libname}
-target ${arch}-apple-macos${DARWIN_osx_MIN_VER}
-darwin-target-variant ${arch}-apple-ios13.1-macabi)
"SHELL:-target ${arch}-apple-macos${DARWIN_osx_MIN_VER} -darwin-target-variant ${arch}-apple-ios13.1-macabi")
endforeach()
endif()
endforeach()
Expand Down
13 changes: 6 additions & 7 deletions compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
Expand Up @@ -304,8 +304,7 @@ macro(darwin_add_builtin_library name suffix)
"${LIB_OS}" MATCHES "^osx$")
# Build the macOS builtins with Mac Catalyst support.
list(APPEND builtin_cflags
-target ${LIB_ARCH}-apple-macos${DARWIN_osx_BUILTIN_MIN_VER}
-darwin-target-variant ${LIB_ARCH}-apple-ios13.1-macabi)
"SHELL:-target ${LIB_ARCH}-apple-macos${DARWIN_osx_BUILTIN_MIN_VER} -darwin-target-variant ${LIB_ARCH}-apple-ios13.1-macabi")
endif()

set_target_compile_flags(${libname}
Expand Down Expand Up @@ -400,12 +399,12 @@ endfunction()
macro(darwin_add_builtin_libraries)
set(DARWIN_EXCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Darwin-excludes)

set(CFLAGS "-fPIC -O3 -fvisibility=hidden -DVISIBILITY_HIDDEN -Wall -fomit-frame-pointer")
set(CFLAGS -fPIC -O3 -fvisibility=hidden -DVISIBILITY_HIDDEN -Wall -fomit-frame-pointer)
set(CMAKE_C_FLAGS "")
set(CMAKE_CXX_FLAGS "")
set(CMAKE_ASM_FLAGS "")

append_string_if(COMPILER_RT_HAS_ASM_LSE " -DHAS_ASM_LSE" CFLAGS)
append_list_if(COMPILER_RT_HAS_ASM_LSE -DHAS_ASM_LSE CFLAGS)

set(PROFILE_SOURCES ../profile/InstrProfiling.c
../profile/InstrProfilingBuffer.c
Expand Down Expand Up @@ -515,7 +514,7 @@ macro(darwin_add_embedded_builtin_libraries)

set(MACHO_SYM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/macho_embedded)

set(CFLAGS "-Oz -Wall -fomit-frame-pointer -ffreestanding")
set(CFLAGS -Oz -Wall -fomit-frame-pointer -ffreestanding)
set(CMAKE_C_FLAGS "")
set(CMAKE_CXX_FLAGS "")
set(CMAKE_ASM_FLAGS "")
Expand All @@ -534,8 +533,8 @@ macro(darwin_add_embedded_builtin_libraries)
set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR
${COMPILER_RT_INSTALL_LIBRARY_DIR}/macho_embedded)

set(CFLAGS_armv7 "-target thumbv7-apple-darwin-eabi")
set(CFLAGS_i386 "-march=pentium")
set(CFLAGS_armv7 -target thumbv7-apple-darwin-eabi)
set(CFLAGS_i386 -march=pentium)

darwin_read_list_from_file(common_FUNCTIONS ${MACHO_SYM_DIR}/common.txt)
darwin_read_list_from_file(thumb2_FUNCTIONS ${MACHO_SYM_DIR}/thumb2.txt)
Expand Down
12 changes: 2 additions & 10 deletions compiler-rt/cmake/Modules/CompilerRTUtils.cmake
Expand Up @@ -5,19 +5,11 @@ include(CheckSymbolExists)
# define a handy helper function for it. The compile flags setting in CMake
# has serious issues that make its syntax challenging at best.
function(set_target_compile_flags target)
set(argstring "")
foreach(arg ${ARGN})
set(argstring "${argstring} ${arg}")
endforeach()
set_property(TARGET ${target} PROPERTY COMPILE_FLAGS "${argstring}")
set_property(TARGET ${target} PROPERTY COMPILE_OPTIONS ${ARGN})
endfunction()

function(set_target_link_flags target)
set(argstring "")
foreach(arg ${ARGN})
set(argstring "${argstring} ${arg}")
endforeach()
set_property(TARGET ${target} PROPERTY LINK_FLAGS "${argstring}")
set_property(TARGET ${target} PROPERTY LINK_OPTIONS ${ARGN})
endfunction()

# Set the variable var_PYBOOL to True if var holds a true-ish string,
Expand Down

0 comments on commit 30dfe01

Please sign in to comment.