Changed: CXXFLAGS and CPPFLAGS support in CMake

Changed: Use LIBRARY_ARCHITECTURE to override CMAKE_LIBRARY_ARCHITECTURE
This commit is contained in:
kervala 2012-10-03 22:31:12 +02:00
parent ad98304019
commit 0d382e9034

View file

@ -407,28 +407,40 @@ MACRO(NL_SETUP_BUILD)
ENDIF("${HOST_CPU}" STREQUAL "${TARGET_CPU}") ENDIF("${HOST_CPU}" STREQUAL "${TARGET_CPU}")
# Use values from environment variables # Use values from environment variables
SET(PLATFORM_CFLAGS "$ENV{CFLAGS} ${PLATFORM_CFLAGS}") SET(PLATFORM_CFLAGS "$ENV{CFLAGS} $ENV{CPPFLAGS} ${PLATFORM_CFLAGS}")
SET(PLATFORM_CXXFLAGS "$ENV{CXXFLAGS} $ENV{CPPFLAGS} ${PLATFORM_CXXFLAGS}")
SET(PLATFORM_LINKFLAGS "$ENV{LDFLAGS} ${PLATFORM_LINKFLAGS}") SET(PLATFORM_LINKFLAGS "$ENV{LDFLAGS} ${PLATFORM_LINKFLAGS}")
# Remove -g and -O flag because we are managing them ourself # Remove -g and -O flag because we are managing them ourself
STRING(REPLACE "-g" "" PLATFORM_CFLAGS ${PLATFORM_CFLAGS}) STRING(REPLACE "-g" "" PLATFORM_CFLAGS ${PLATFORM_CFLAGS})
STRING(REPLACE "-g" "" PLATFORM_CXXFLAGS ${PLATFORM_CXXFLAGS})
STRING(REGEX REPLACE "-O[0-9s]" "" PLATFORM_CFLAGS ${PLATFORM_CFLAGS}) STRING(REGEX REPLACE "-O[0-9s]" "" PLATFORM_CFLAGS ${PLATFORM_CFLAGS})
STRING(REGEX REPLACE "-O[0-9s]" "" PLATFORM_CXXFLAGS ${PLATFORM_CXXFLAGS})
# Strip spaces # Strip spaces
STRING(STRIP ${PLATFORM_CFLAGS} PLATFORM_CFLAGS) STRING(STRIP ${PLATFORM_CFLAGS} PLATFORM_CFLAGS)
STRING(STRIP ${PLATFORM_CXXFLAGS} PLATFORM_CXXFLAGS)
STRING(STRIP ${PLATFORM_LINKFLAGS} PLATFORM_LINKFLAGS) STRING(STRIP ${PLATFORM_LINKFLAGS} PLATFORM_LINKFLAGS)
IF(TARGET_CPU STREQUAL "x86_64") IF(TARGET_CPU STREQUAL "x86_64")
SET(TARGET_X64 1) SET(TARGET_X64 1)
SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DHAVE_X86_64") SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DHAVE_X86_64")
SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -DHAVE_X86_64")
ELSEIF(TARGET_CPU STREQUAL "x86") ELSEIF(TARGET_CPU STREQUAL "x86")
SET(TARGET_X86 1) SET(TARGET_X86 1)
SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DHAVE_X86") SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DHAVE_X86")
SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -DHAVE_X86")
ELSEIF(TARGET_CPU STREQUAL "arm") ELSEIF(TARGET_CPU STREQUAL "arm")
SET(TARGET_ARM 1) SET(TARGET_ARM 1)
SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DHAVE_ARM") SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DHAVE_ARM")
SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -DHAVE_ARM")
ENDIF(TARGET_CPU STREQUAL "x86_64") ENDIF(TARGET_CPU STREQUAL "x86_64")
# Override CMAKE_LIBRARY_ARCHITECTURE that is automatically determinated
IF(LIBRARY_ARCHITECTURE)
SET(CMAKE_LIBRARY_ARCHITECTURE ${LIBRARY_ARCHITECTURE})
ENDIF(LIBRARY_ARCHITECTURE)
# Fix library paths suffixes for Debian MultiArch # Fix library paths suffixes for Debian MultiArch
IF(CMAKE_LIBRARY_ARCHITECTURE) IF(CMAKE_LIBRARY_ARCHITECTURE)
SET(CMAKE_LIBRARY_PATH /lib/${CMAKE_LIBRARY_ARCHITECTURE} /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE} ${CMAKE_LIBRARY_PATH}) SET(CMAKE_LIBRARY_PATH /lib/${CMAKE_LIBRARY_ARCHITECTURE} /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE} ${CMAKE_LIBRARY_PATH})
@ -461,10 +473,12 @@ MACRO(NL_SETUP_BUILD)
ENDIF(MSVC10) ENDIF(MSVC10)
SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_WARNINGS /DWIN32 /D_WINDOWS /W3 /Zm1000 /MP /Gy-") SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_WARNINGS /DWIN32 /D_WINDOWS /W3 /Zm1000 /MP /Gy-")
SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_WARNINGS /DWIN32 /D_WINDOWS /W3 /Zm1000 /MP /Gy-")
IF(TARGET_X64) IF(TARGET_X64)
# Fix a bug with Intellisense # Fix a bug with Intellisense
SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} /D_WIN64") SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} /D_WIN64")
SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} /D_WIN64")
# Fix a compilation error for some big C++ files # Fix a compilation error for some big C++ files
SET(MIN_OPTIMIZATIONS "${MIN_OPTIMIZATIONS} /bigobj") SET(MIN_OPTIMIZATIONS "${MIN_OPTIMIZATIONS} /bigobj")
ELSE(TARGET_X64) ELSE(TARGET_X64)
@ -473,7 +487,7 @@ MACRO(NL_SETUP_BUILD)
ENDIF(TARGET_X64) ENDIF(TARGET_X64)
# Exceptions are only set for C++ # Exceptions are only set for C++
SET(PLATFORM_CXXFLAGS "${PLATFORM_CFLAGS} /EHa") SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} /EHa")
IF(WITH_SYMBOLS) IF(WITH_SYMBOLS)
SET(NL_RELEASE_CFLAGS "/Zi ${NL_RELEASE_CFLAGS}") SET(NL_RELEASE_CFLAGS "/Zi ${NL_RELEASE_CFLAGS}")
@ -494,33 +508,41 @@ MACRO(NL_SETUP_BUILD)
IF(APPLE) IF(APPLE)
IF(TARGET_CPU STREQUAL "x86") IF(TARGET_CPU STREQUAL "x86")
SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -arch i386") SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -arch i386")
SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -arch i386")
ENDIF(TARGET_CPU STREQUAL "x86") ENDIF(TARGET_CPU STREQUAL "x86")
IF(TARGET_CPU STREQUAL "x86_64") IF(TARGET_CPU STREQUAL "x86_64")
SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -arch x86_64") SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -arch x86_64")
SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -arch x86_64")
ENDIF(TARGET_CPU STREQUAL "x86_64") ENDIF(TARGET_CPU STREQUAL "x86_64")
ELSE(APPLE) ELSE(APPLE)
IF(HOST_CPU STREQUAL "x86_64" AND TARGET_CPU STREQUAL "x86") IF(HOST_CPU STREQUAL "x86_64" AND TARGET_CPU STREQUAL "x86")
SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -m32 -march=i686") SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -m32 -march=i686")
SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -m32 -march=i686")
ENDIF(HOST_CPU STREQUAL "x86_64" AND TARGET_CPU STREQUAL "x86") ENDIF(HOST_CPU STREQUAL "x86_64" AND TARGET_CPU STREQUAL "x86")
IF(HOST_CPU STREQUAL "x86" AND TARGET_CPU STREQUAL "x86_64") IF(HOST_CPU STREQUAL "x86" AND TARGET_CPU STREQUAL "x86_64")
SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -m64") SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -m64")
SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -m64")
ENDIF(HOST_CPU STREQUAL "x86" AND TARGET_CPU STREQUAL "x86_64") ENDIF(HOST_CPU STREQUAL "x86" AND TARGET_CPU STREQUAL "x86_64")
ENDIF(APPLE) ENDIF(APPLE)
SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -D_REENTRANT -pipe -Wall -W -Wpointer-arith -Wsign-compare -Wno-deprecated-declarations -Wno-multichar -Wno-unused -fno-strict-aliasing") SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -D_REENTRANT -pipe -Wall -W -Wpointer-arith -Wsign-compare -Wno-deprecated-declarations -Wno-multichar -Wno-unused -fno-strict-aliasing")
SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -D_REENTRANT -pipe -Wall -W -Wpointer-arith -Wsign-compare -Wno-deprecated-declarations -Wno-multichar -Wno-unused -fno-strict-aliasing")
IF(NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") IF(NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -ansi") SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -ansi")
SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -ansi")
ENDIF(NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") ENDIF(NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
IF(WITH_COVERAGE) IF(WITH_COVERAGE)
SET(PLATFORM_CFLAGS "-fprofile-arcs -ftest-coverage ${PLATFORM_CFLAGS}") SET(PLATFORM_CFLAGS "-fprofile-arcs -ftest-coverage ${PLATFORM_CFLAGS}")
SET(PLATFORM_CXXFLAGS "-fprofile-arcs -ftest-coverage ${PLATFORM_CXXFLAGS}")
ENDIF(WITH_COVERAGE) ENDIF(WITH_COVERAGE)
IF(APPLE) IF(APPLE)
SET(PLATFORM_CFLAGS "-gdwarf-2 ${PLATFORM_CFLAGS}") SET(PLATFORM_CFLAGS "-gdwarf-2 ${PLATFORM_CFLAGS}")
SET(PLATFORM_CXXFLAGS "-gdwarf-2 ${PLATFORM_CXXFLAGS}")
ENDIF(APPLE) ENDIF(APPLE)
IF(APPLE AND XCODE) IF(APPLE AND XCODE)
@ -538,6 +560,7 @@ MACRO(NL_SETUP_BUILD)
IF(CMAKE_OSX_SYSROOT) IF(CMAKE_OSX_SYSROOT)
SET(PLATFORM_CFLAGS "-isysroot ${CMAKE_OSX_SYSROOT} ${PLATFORM_CFLAGS}") SET(PLATFORM_CFLAGS "-isysroot ${CMAKE_OSX_SYSROOT} ${PLATFORM_CFLAGS}")
SET(PLATFORM_CXXFLAGS "-isysroot ${CMAKE_OSX_SYSROOT} ${PLATFORM_CXXFLAGS}")
ELSE(CMAKE_OSX_SYSROOT) ELSE(CMAKE_OSX_SYSROOT)
MESSAGE(FATAL_ERROR "CMAKE_OSX_SYSROOT can't be determinated") MESSAGE(FATAL_ERROR "CMAKE_OSX_SYSROOT can't be determinated")
ENDIF(CMAKE_OSX_SYSROOT) ENDIF(CMAKE_OSX_SYSROOT)
@ -545,10 +568,12 @@ MACRO(NL_SETUP_BUILD)
IF(CMAKE_OSX_ARCHITECTURES) IF(CMAKE_OSX_ARCHITECTURES)
FOREACH(_ARCH ${CMAKE_OSX_ARCHITECTURES}) FOREACH(_ARCH ${CMAKE_OSX_ARCHITECTURES})
SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -arch ${_ARCH}") SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -arch ${_ARCH}")
SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -arch ${_ARCH}")
ENDFOREACH(_ARCH) ENDFOREACH(_ARCH)
ENDIF(CMAKE_OSX_ARCHITECTURES) ENDIF(CMAKE_OSX_ARCHITECTURES)
IF(CMAKE_C_OSX_DEPLOYMENT_TARGET_FLAG) IF(CMAKE_C_OSX_DEPLOYMENT_TARGET_FLAG)
SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}") SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
ENDIF(CMAKE_C_OSX_DEPLOYMENT_TARGET_FLAG) ENDIF(CMAKE_C_OSX_DEPLOYMENT_TARGET_FLAG)
SET(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,-headerpad_max_install_names") SET(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,-headerpad_max_install_names")
@ -561,9 +586,10 @@ MACRO(NL_SETUP_BUILD)
# Fix "relocation R_X86_64_32 against.." error on x64 platforms # Fix "relocation R_X86_64_32 against.." error on x64 platforms
IF(TARGET_X64 AND WITH_STATIC AND NOT WITH_STATIC_DRIVERS) IF(TARGET_X64 AND WITH_STATIC AND NOT WITH_STATIC_DRIVERS)
SET(PLATFORM_CFLAGS "-fPIC ${PLATFORM_CFLAGS}") SET(PLATFORM_CFLAGS "-fPIC ${PLATFORM_CFLAGS}")
SET(PLATFORM_CXXFLAGS "-fPIC ${PLATFORM_CXXFLAGS}")
ENDIF(TARGET_X64 AND WITH_STATIC AND NOT WITH_STATIC_DRIVERS) ENDIF(TARGET_X64 AND WITH_STATIC AND NOT WITH_STATIC_DRIVERS)
SET(PLATFORM_CXXFLAGS "${PLATFORM_CFLAGS} -ftemplate-depth-48") SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -ftemplate-depth-48")
IF(NOT APPLE) IF(NOT APPLE)
SET(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,--no-undefined -Wl,--as-needed") SET(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,--no-undefined -Wl,--as-needed")