llvm.org GIT mirror llvm / bbcc0db
Fix evaluation of LLVM_DEFINITIONS CMake variable LLVM_DEFINITIONS collects preprocessor definitions provided for host compiler that builds llvm components. A function add_llvm_definitions was introduced in AddLLVMDefinitions.cmake to keep track of these definitions and was intended to be a replacement for CMake command add_definitions. Actually in many cases add_definitions is still used and the content of LLVM_DEFINITIONS is not actual now. On the other hand the current version of CMake allows getting set of definitions in a more convenient way. This fix implements evaluation of the variable by reading corresponding cmake property. Differential Revision: https://reviews.llvm.org/D31125 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298336 91177308-0d34-0410-b5e6-96231b3b80d8 Serge Pavlov 2 years ago
4 changed file(s) with 26 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
366366 ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
367367 list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
368368
369 include(AddLLVMDefinitions)
370
371369 option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
372370 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
373371 option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)
243243
244244 check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
245245 if( LLVM_USING_GLIBC )
246 add_llvm_definitions( -D_GNU_SOURCE )
246 add_definitions( -D_GNU_SOURCE )
247247 endif()
248248 # This check requires _GNU_SOURCE
249249 if(HAVE_LIBPTHREAD)
77
88 include(CheckCompilerVersion)
99 include(HandleLLVMStdlib)
10 include(AddLLVMDefinitions)
1110 include(CheckCCompilerFlag)
1211 include(CheckCXXCompilerFlag)
1312
252251 "Number of parallel compiler jobs. 0 means use all processors. Default is 0.")
253252 if( NOT LLVM_COMPILER_JOBS STREQUAL "1" )
254253 if( LLVM_COMPILER_JOBS STREQUAL "0" )
255 add_llvm_definitions( /MP )
254 add_definitions( /MP )
256255 else()
257256 message(STATUS "Number of parallel compiler jobs set to " ${LLVM_COMPILER_JOBS})
258 add_llvm_definitions( /MP${LLVM_COMPILER_JOBS} )
257 add_definitions( /MP${LLVM_COMPILER_JOBS} )
259258 endif()
260259 else()
261260 message(STATUS "Parallel compilation disabled")
284283 if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0 )
285284 # For MSVC 2013, disable iterator null pointer checking in debug mode,
286285 # especially so std::equal(nullptr, nullptr, nullptr) will not assert.
287 add_llvm_definitions("-D_DEBUG_POINTER_IMPL=")
286 add_definitions("-D_DEBUG_POINTER_IMPL=")
288287 endif()
289288
290289 include(ChooseMSVCCRT)
291290
292291 if( MSVC11 )
293 add_llvm_definitions(-D_VARIADIC_MAX=10)
292 add_definitions(-D_VARIADIC_MAX=10)
294293 endif()
295294
296295 # Add definitions that make MSVC much less annoying.
297 add_llvm_definitions(
296 add_definitions(
298297 # For some reason MS wants to deprecate a bunch of standard functions...
299298 -D_CRT_SECURE_NO_DEPRECATE
300299 -D_CRT_SECURE_NO_WARNINGS
305304 )
306305
307306 # Tell MSVC to use the Unicode version of the Win32 APIs instead of ANSI.
308 add_llvm_definitions(
307 add_definitions(
309308 -DUNICODE
310309 -D_UNICODE
311310 )
645644 add_definitions("-gsplit-dwarf")
646645 endif()
647646
648 add_llvm_definitions( -D__STDC_CONSTANT_MACROS )
649 add_llvm_definitions( -D__STDC_FORMAT_MACROS )
650 add_llvm_definitions( -D__STDC_LIMIT_MACROS )
647 add_definitions( -D__STDC_CONSTANT_MACROS )
648 add_definitions( -D__STDC_FORMAT_MACROS )
649 add_definitions( -D__STDC_LIMIT_MACROS )
651650
652651 # clang doesn't print colored diagnostics when invoked from Ninja
653652 if (UNIX AND
773772 else()
774773 set(LLVM_ENABLE_PLUGINS ON)
775774 endif()
775
776 function(get_compile_definitions)
777 get_directory_property(top_dir_definitions DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS)
778 foreach(definition ${top_dir_definitions})
779 if(DEFINED result)
780 string(APPEND result " -D${definition}")
781 else()
782 set(result "-D${definition}")
783 endif()
784 endforeach()
785 set(LLVM_DEFINITIONS "${result}" PARENT_SCOPE)
786 endfunction()
787 get_compile_definitions()
3030 # Use configure_file to create BuildVariables.inc.
3131 set(LLVM_SRC_ROOT ${LLVM_MAIN_SRC_DIR})
3232 set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR})
33 set(LLVM_CPPFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
34 set(LLVM_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
35 set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
33 string(CONCAT LLVM_CPPFLAGS "${CMAKE_CPP_FLAGS}" "${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}}" "${LLVM_DEFINITIONS}")
34 string(CONCAT LLVM_CFLAGS "${CMAKE_C_FLAGS}" "${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}}" "${LLVM_DEFINITIONS}")
35 string(CONCAT LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS}" "${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}}" "${COMPILE_FLAGS}" "${LLVM_DEFINITIONS}")
3636 set(LLVM_BUILD_SYSTEM cmake)
3737 set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI})
3838 set(LLVM_DYLIB_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}${LLVM_VERSION_SUFFIX}")