CMake: defines and uses macro add_llvm_definitions for keeping track

of compiler parameters explicitly added by the build
specification. This macro replaces the cmake built-in
`add_definitions'.

Detects glibc and defines _GNU_SOURCE accordingly.

Resolves bug 3882.

llvm-svn: 68428
This commit is contained in:
Oscar Fuentes 2009-04-04 22:41:07 +00:00
parent 3b779984b4
commit bda403b4c8
4 changed files with 35 additions and 12 deletions

View File

@ -74,6 +74,8 @@ set(CMAKE_MODULE_PATH
"${LLVM_MAIN_SRC_DIR}/cmake/modules"
)
include(AddLLVMDefinitions)
if(WIN32)
if(CYGWIN)
set(LLVM_ON_WIN32 0)
@ -110,7 +112,7 @@ option(LLVM_ENABLE_PIC "Build Position-Independent Code" OFF)
if( LLVM_ENABLE_PIC )
if( SUPPORTS_FPIC_FLAG )
message(STATUS "Building with -fPIC")
add_definitions(-fPIC)
add_llvm_definitions(-fPIC)
else( SUPPORTS_FPIC_FLAG )
message(STATUS "Warning: -fPIC not supported.")
endif()
@ -122,8 +124,8 @@ set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
# set(CMAKE_VERBOSE_MAKEFILE true)
add_definitions( -D__STDC_LIMIT_MACROS )
add_definitions( -D__STDC_CONSTANT_MACROS )
add_llvm_definitions( -D__STDC_LIMIT_MACROS )
add_llvm_definitions( -D__STDC_CONSTANT_MACROS )
set(LLVM_PLO_FLAGS "" CACHE
STRING "Flags for creating partially linked objects.")
@ -133,7 +135,7 @@ if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
if( LLVM_BUILD_32_BITS )
message(STATUS "Building 32 bits executables and libraries.")
add_definitions( -m32 )
add_llvm_definitions( -m32 )
list(APPEND CMAKE_EXE_LINKER_FLAGS -m32)
list(APPEND CMAKE_SHARED_LINKER_FLAGS -m32)
set( LLVM_PLO_FLAGS -melf_i386 ${LLVM_PLO_FLAGS} )
@ -141,11 +143,11 @@ if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
if( MSVC )
add_definitions( -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS )
add_definitions( -D_SCL_SECURE_NO_WARNINGS -DCRT_NONSTDC_NO_WARNINGS )
add_definitions( -D_SCL_SECURE_NO_DEPRECATE )
add_definitions( -wd4146 -wd4503 -wd4996 -wd4800 -wd4244 -wd4624 )
add_definitions( -wd4355 -wd4715 -wd4180 -wd4345 -wd4224 )
add_llvm_definitions( -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS )
add_llvm_definitions( -D_SCL_SECURE_NO_WARNINGS -DCRT_NONSTDC_NO_WARNINGS )
add_llvm_definitions( -D_SCL_SECURE_NO_DEPRECATE )
add_llvm_definitions( -wd4146 -wd4503 -wd4996 -wd4800 -wd4244 -wd4624 )
add_llvm_definitions( -wd4355 -wd4715 -wd4180 -wd4345 -wd4224 )
endif( MSVC )
include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})

View File

@ -52,6 +52,11 @@ check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
check_symbol_exists(pthread_mutex_lock pthread.h HAVE_PTHREAD_MUTEX_LOCK)
check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL)
check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
if( LLVM_USING_GLIBC )
add_llvm_definitions( -D_GNU_SOURCE )
endif()
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fPIC" SUPPORTS_FPIC_FLAG)

View File

@ -0,0 +1,11 @@
# There is no clear way of keeping track of compiler command-line
# options chosen via `add_definitions', so we need our own method for
# using it on tools/llvm-config/CMakeLists.txt.
# Beware that there is no implementation of remove_llvm_definitions.
macro(add_llvm_definitions)
set(LLVM_DEFINITIONS "${LLVM_DEFINITIONS} ${ARGN}")
add_definitions( ${ARGN} )
endmacro(add_llvm_definitions)

View File

@ -82,10 +82,15 @@ add_custom_command(OUTPUT ${FINAL_LIBDEPS}
DEPENDS ${LIBDEPS}
COMMENT "Checking for cyclic dependencies between LLVM libraries.")
string(TOUPPER ${CMAKE_BUILD_TYPE} uppercase_CMAKE_BUILD_TYPE)
set(C_FLGS "${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
set(CXX_FLGS "${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
set(CPP_FLGS "${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
add_custom_command(OUTPUT ${LLVM_CONFIG}
COMMAND echo 's!@LLVM_CPPFLAGS@!${CMAKE_CPP_FLAGS}!' > temp.sed
COMMAND echo 's!@LLVM_CFLAGS@!${CMAKE_C_FLAGS}!' >> temp.sed
COMMAND echo 's!@LLVM_CXXFLAGS@!${CMAKE_CXX_FLAGS}!' >> temp.sed
COMMAND echo 's!@LLVM_CPPFLAGS@!${CPP_FLGS}!' > temp.sed
COMMAND echo 's!@LLVM_CFLAGS@!${C_FLGS}!' >> temp.sed
COMMAND echo 's!@LLVM_CXXFLAGS@!${CXX_FLGS}!' >> temp.sed
# TODO: Use general flags for linking! not just for shared libs:
COMMAND echo 's!@LLVM_LDFLAGS@!${CMAKE_SHARED_LINKER_FLAGS}!' >> temp.sed
COMMAND echo 's!@LIBS@!!' >> temp.sed # TODO: System libs