[llvm] 2630093 - [cmake] Stop using add_definitions
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 24 00:27:20 PST 2023
Author: Jay Foad
Date: 2023-01-24T08:27:04Z
New Revision: 2630093496d05a0d255b21fa6632455bd45c8720
URL: https://github.com/llvm/llvm-project/commit/2630093496d05a0d255b21fa6632455bd45c8720
DIFF: https://github.com/llvm/llvm-project/commit/2630093496d05a0d255b21fa6632455bd45c8720.diff
LOG: [cmake] Stop using add_definitions
Since CMake 3.12 this has been superseded by add_compile_definitions and
other commands.
Differential Revision: https://reviews.llvm.org/D142363
Added:
Modified:
llvm/CMakeLists.txt
llvm/cmake/modules/HandleLLVMOptions.cmake
llvm/cmake/modules/TensorFlowCompile.cmake
llvm/lib/Support/BLAKE3/CMakeLists.txt
llvm/lib/Support/CMakeLists.txt
llvm/tools/llvm-config/CMakeLists.txt
Removed:
################################################################################
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 28ed35f8b8025..cddca6b4822f1 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -703,7 +703,7 @@ option(LLVM_BUILD_EXAMPLES
option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
if(LLVM_BUILD_EXAMPLES)
- add_definitions(-DBUILD_EXAMPLES)
+ add_compile_definitions(BUILD_EXAMPLES)
endif(LLVM_BUILD_EXAMPLES)
option(LLVM_BUILD_TESTS
@@ -1059,8 +1059,8 @@ endif()
# Build with _XOPEN_SOURCE on AIX, as stray macros in _ALL_SOURCE mode tend to
# break things. In this case we need to enable the large-file API as well.
if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
- add_definitions("-D_XOPEN_SOURCE=700")
- add_definitions("-D_LARGE_FILE_API")
+ add_compile_definitions(_XOPEN_SOURCE=700)
+ add_compile_definitions(_LARGE_FILE_API)
# CMake versions less than 3.16 set default linker flags to include -brtl, as
# well as setting -G when building libraries, so clear them out. Note we only
@@ -1095,14 +1095,14 @@ endif()
# Build with _XOPEN_SOURCE on z/OS.
if (CMAKE_SYSTEM_NAME MATCHES "OS390")
- add_definitions("-D_XOPEN_SOURCE=600")
- add_definitions("-D_OPEN_SYS") # Needed for process information.
- add_definitions("-D_OPEN_SYS_FILE_EXT") # Needed for EBCDIC I/O.
+ add_compile_definitions(_XOPEN_SOURCE=600)
+ add_compile_definitions(_OPEN_SYS) # Needed for process information.
+ add_compile_definitions(_OPEN_SYS_FILE_EXT) # Needed for EBCDIC I/O.
endif()
# Build with _FILE_OFFSET_BITS=64 on Solaris to match g++ >= 9.
if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
- add_definitions("-D_FILE_OFFSET_BITS=64")
+ add_compile_definitions(_FILE_OFFSET_BITS=64)
endif()
set(CMAKE_INCLUDE_CURRENT_DIR ON)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index d0009fafad423..6119ecdce0f4b 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -61,13 +61,11 @@ endif()
if( LLVM_ENABLE_ASSERTIONS )
# MSVC doesn't like _DEBUG on release builds. See PR 4379.
if( NOT MSVC )
- add_definitions( -D_DEBUG )
+ add_compile_definitions(_DEBUG)
endif()
# On non-Debug builds cmake automatically defines NDEBUG, so we
# explicitly undefine it:
if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
- # NOTE: use `add_compile_options` rather than `add_definitions` since
- # `add_definitions` does not support generator expressions.
add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-UNDEBUG>)
if (MSVC)
# Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines.
@@ -86,7 +84,7 @@ if( LLVM_ENABLE_ASSERTIONS )
endif()
if(LLVM_ENABLE_EXPENSIVE_CHECKS)
- add_definitions(-DEXPENSIVE_CHECKS)
+ add_compile_definitions(EXPENSIVE_CHECKS)
# In some libstdc++ versions, std::min_element is not constexpr when
# _GLIBCXX_DEBUG is enabled.
@@ -99,14 +97,14 @@ if(LLVM_ENABLE_EXPENSIVE_CHECKS)
return 0;
}" CXX_SUPPORTS_GLIBCXX_DEBUG)
if(CXX_SUPPORTS_GLIBCXX_DEBUG)
- add_definitions(-D_GLIBCXX_DEBUG)
+ add_compile_definitions(_GLIBCXX_DEBUG)
else()
- add_definitions(-D_GLIBCXX_ASSERTIONS)
+ add_compile_definitions(_GLIBCXX_ASSERTIONS)
endif()
endif()
if (LLVM_ENABLE_STRICT_FIXED_SIZE_VECTORS)
- add_definitions(-DSTRICT_FIXED_SIZE_VECTORS)
+ add_compile_definitions(STRICT_FIXED_SIZE_VECTORS)
endif()
string(TOUPPER "${LLVM_ABI_BREAKING_CHECKS}" uppercase_LLVM_ABI_BREAKING_CHECKS)
@@ -372,7 +370,7 @@ if((NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX")) AND
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND MINGW)
- add_definitions( -D_FILE_OFFSET_BITS=64 )
+ add_compile_definitions(_FILE_OFFSET_BITS=64)
endif()
if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
@@ -386,8 +384,8 @@ if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -m32")
# FIXME: CMAKE_SIZEOF_VOID_P is still 8
- add_definitions(-D_LARGEFILE_SOURCE)
- add_definitions(-D_FILE_OFFSET_BITS=64)
+ add_compile_definitions(_LARGEFILE_SOURCE)
+ add_compile_definitions(_FILE_OFFSET_BITS=64)
endif( LLVM_BUILD_32_BITS )
endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
@@ -399,8 +397,8 @@ if (ANDROID AND (ANDROID_NATIVE_API_LEVEL LESS 24))
endif()
if( CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT LLVM_FORCE_SMALLFILE_FOR_ANDROID)
# FIXME: It isn't handled in LLVM_BUILD_32_BITS.
- add_definitions( -D_LARGEFILE_SOURCE )
- add_definitions( -D_FILE_OFFSET_BITS=64 )
+ add_compile_definitions(_LARGEFILE_SOURCE)
+ add_compile_definitions(_FILE_OFFSET_BITS=64)
endif()
if( XCODE )
@@ -433,10 +431,10 @@ if( MSVC_IDE )
"Number of parallel compiler jobs. 0 means use all processors. Default is 0.")
if( NOT LLVM_COMPILER_JOBS STREQUAL "1" )
if( LLVM_COMPILER_JOBS STREQUAL "0" )
- add_definitions( /MP )
+ add_compile_options(/MP)
else()
message(STATUS "Number of parallel compiler jobs set to " ${LLVM_COMPILER_JOBS})
- add_definitions( /MP${LLVM_COMPILER_JOBS} )
+ add_compile_options(/MP${LLVM_COMPILER_JOBS})
endif()
else()
message(STATUS "Parallel compilation disabled")
@@ -465,20 +463,20 @@ if( MSVC )
include(ChooseMSVCCRT)
# Add definitions that make MSVC much less annoying.
- add_definitions(
+ add_compile_definitions(
# For some reason MS wants to deprecate a bunch of standard functions...
- -D_CRT_SECURE_NO_DEPRECATE
- -D_CRT_SECURE_NO_WARNINGS
- -D_CRT_NONSTDC_NO_DEPRECATE
- -D_CRT_NONSTDC_NO_WARNINGS
- -D_SCL_SECURE_NO_DEPRECATE
- -D_SCL_SECURE_NO_WARNINGS
+ _CRT_SECURE_NO_DEPRECATE
+ _CRT_SECURE_NO_WARNINGS
+ _CRT_NONSTDC_NO_DEPRECATE
+ _CRT_NONSTDC_NO_WARNINGS
+ _SCL_SECURE_NO_DEPRECATE
+ _SCL_SECURE_NO_WARNINGS
)
# Tell MSVC to use the Unicode version of the Win32 APIs instead of ANSI.
- add_definitions(
- -DUNICODE
- -D_UNICODE
+ add_compile_definitions(
+ UNICODE
+ _UNICODE
)
if (LLVM_WINSYSROOT)
@@ -963,9 +961,9 @@ if (LLVM_USE_SPLIT_DWARF AND
endif()
endif()
-add_definitions( -D__STDC_CONSTANT_MACROS )
-add_definitions( -D__STDC_FORMAT_MACROS )
-add_definitions( -D__STDC_LIMIT_MACROS )
+add_compile_definitions(__STDC_CONSTANT_MACROS)
+add_compile_definitions(__STDC_FORMAT_MACROS)
+add_compile_definitions(__STDC_LIMIT_MACROS)
# clang and gcc don't default-print colored diagnostics when invoked from Ninja.
if (UNIX AND
diff --git a/llvm/cmake/modules/TensorFlowCompile.cmake b/llvm/cmake/modules/TensorFlowCompile.cmake
index d5ff44c9330d1..c4dae39f37e8c 100644
--- a/llvm/cmake/modules/TensorFlowCompile.cmake
+++ b/llvm/cmake/modules/TensorFlowCompile.cmake
@@ -114,5 +114,5 @@ function(tf_find_and_compile model default_url default_path test_model_generator
set(GeneratedMLSources ${GeneratedMLSources} ${GENERATED_OBJS} ${GENERATED_HEADERS} PARENT_SCOPE)
set(MLDeps ${MLDeps} tf_xla_runtime PARENT_SCOPE)
set(MLLinkDeps ${MLLinkDeps} tf_xla_runtime PARENT_SCOPE)
- add_definitions(-DLLVM_HAVE_TF_AOT_${fname_allcaps})
+ add_compile_definitions(LLVM_HAVE_TF_AOT_${fname_allcaps})
endfunction()
diff --git a/llvm/lib/Support/BLAKE3/CMakeLists.txt b/llvm/lib/Support/BLAKE3/CMakeLists.txt
index e5d227b0c4862..85fe4f6f4206e 100644
--- a/llvm/lib/Support/BLAKE3/CMakeLists.txt
+++ b/llvm/lib/Support/BLAKE3/CMakeLists.txt
@@ -12,7 +12,7 @@ else()
endif()
macro(disable_blake3_x86_simd)
- add_definitions(-DBLAKE3_NO_AVX512 -DBLAKE3_NO_AVX2 -DBLAKE3_NO_SSE41 -DBLAKE3_NO_SSE2)
+ add_compile_definitions(BLAKE3_NO_AVX512 BLAKE3_NO_AVX2 BLAKE3_NO_SSE41 BLAKE3_NO_SSE2)
endmacro()
# The BLAKE3 team recommends using the assembly versions, from the README:
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index 9b5402fa54f0f..4cbc3b79f3bbb 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -71,7 +71,7 @@ elseif( CMAKE_HOST_UNIX )
set(system_libs ${system_libs} zircon)
endif()
if ( HAIKU )
- add_definitions(-D_BSD_SOURCE)
+ add_compile_definitions(_BSD_SOURCE)
set(system_libs ${system_libs} bsd)
endif()
endif( MSVC OR MINGW )
@@ -100,7 +100,7 @@ if(LLVM_INTEGRATED_CRT_ALLOC)
endif()
if(LLVM_INTEGRATED_CRT_ALLOC MATCHES "rpmalloc$")
- add_definitions(-DENABLE_OVERRIDE -DENABLE_PRELOAD)
+ add_compile_definitions(ENABLE_OVERRIDE ENABLE_PRELOAD)
set(ALLOCATOR_FILES "${LLVM_INTEGRATED_CRT_ALLOC}/rpmalloc/rpmalloc.c")
elseif(LLVM_INTEGRATED_CRT_ALLOC MATCHES "snmalloc$")
set(ALLOCATOR_FILES "${LLVM_INTEGRATED_CRT_ALLOC}/src/snmalloc/override/new.cc")
@@ -322,7 +322,7 @@ set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${llvm_system_libs}")
if(LLVM_INTEGRATED_CRT_ALLOC)
if(LLVM_INTEGRATED_CRT_ALLOC MATCHES "snmalloc$")
set_property(TARGET LLVMSupport PROPERTY CXX_STANDARD 17)
- add_definitions(-D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)
+ add_compile_definitions(_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND
"${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64")
set_property(TARGET LLVMSupport PROPERTY COMPILE_FLAGS "-mcx16")
diff --git a/llvm/tools/llvm-config/CMakeLists.txt b/llvm/tools/llvm-config/CMakeLists.txt
index 61474d5d2b74a..35b8b215605d8 100644
--- a/llvm/tools/llvm-config/CMakeLists.txt
+++ b/llvm/tools/llvm-config/CMakeLists.txt
@@ -80,7 +80,7 @@ llvm_expand_pseudo_components(LLVM_DYLIB_COMPONENTS_expanded "${LLVM_DYLIB_COMPO
configure_file(${BUILDVARIABLES_SRCPATH} ${BUILDVARIABLES_OBJPATH} @ONLY)
# Set build-time environment(s).
-add_definitions(-DCMAKE_CFG_INTDIR="${CMAKE_CFG_INTDIR}")
+add_compile_definitions(CMAKE_CFG_INTDIR="${CMAKE_CFG_INTDIR}")
if(LLVM_ENABLE_MODULES)
target_compile_options(llvm-config PUBLIC
More information about the llvm-commits
mailing list