From af4ed15c36592042ddf715fa86a8bab4896a6c3a Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 3 Oct 2012 22:31:12 +0200 Subject: [PATCH] Changed: CXXFLAGS and CPPFLAGS support in CMake Changed: Use LIBRARY_ARCHITECTURE to override CMAKE_LIBRARY_ARCHITECTURE --- code/CMakeModules/nel.cmake | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/code/CMakeModules/nel.cmake b/code/CMakeModules/nel.cmake index 5a2abc665..4875be6d6 100644 --- a/code/CMakeModules/nel.cmake +++ b/code/CMakeModules/nel.cmake @@ -407,28 +407,40 @@ MACRO(NL_SETUP_BUILD) ENDIF("${HOST_CPU}" STREQUAL "${TARGET_CPU}") # 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}") # Remove -g and -O flag because we are managing them ourself 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_CXXFLAGS ${PLATFORM_CXXFLAGS}) # Strip spaces STRING(STRIP ${PLATFORM_CFLAGS} PLATFORM_CFLAGS) + STRING(STRIP ${PLATFORM_CXXFLAGS} PLATFORM_CXXFLAGS) STRING(STRIP ${PLATFORM_LINKFLAGS} PLATFORM_LINKFLAGS) IF(TARGET_CPU STREQUAL "x86_64") SET(TARGET_X64 1) SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DHAVE_X86_64") + SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -DHAVE_X86_64") ELSEIF(TARGET_CPU STREQUAL "x86") SET(TARGET_X86 1) SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DHAVE_X86") + SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -DHAVE_X86") ELSEIF(TARGET_CPU STREQUAL "arm") SET(TARGET_ARM 1) SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DHAVE_ARM") + SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -DHAVE_ARM") 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 IF(CMAKE_LIBRARY_ARCHITECTURE) 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) 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) # Fix a bug with Intellisense SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} /D_WIN64") + SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} /D_WIN64") # Fix a compilation error for some big C++ files SET(MIN_OPTIMIZATIONS "${MIN_OPTIMIZATIONS} /bigobj") ELSE(TARGET_X64) @@ -473,7 +487,7 @@ MACRO(NL_SETUP_BUILD) ENDIF(TARGET_X64) # Exceptions are only set for C++ - SET(PLATFORM_CXXFLAGS "${PLATFORM_CFLAGS} /EHa") + SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} /EHa") IF(WITH_SYMBOLS) SET(NL_RELEASE_CFLAGS "/Zi ${NL_RELEASE_CFLAGS}") @@ -494,33 +508,41 @@ MACRO(NL_SETUP_BUILD) IF(APPLE) IF(TARGET_CPU STREQUAL "x86") SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -arch i386") + SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -arch i386") ENDIF(TARGET_CPU STREQUAL "x86") IF(TARGET_CPU STREQUAL "x86_64") SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -arch x86_64") + SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -arch x86_64") ENDIF(TARGET_CPU STREQUAL "x86_64") ELSE(APPLE) IF(HOST_CPU STREQUAL "x86_64" AND TARGET_CPU STREQUAL "x86") 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") IF(HOST_CPU STREQUAL "x86" AND TARGET_CPU STREQUAL "x86_64") SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -m64") + SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -m64") ENDIF(HOST_CPU STREQUAL "x86" AND TARGET_CPU STREQUAL "x86_64") 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_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") SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -ansi") + SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -ansi") ENDIF(NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") IF(WITH_COVERAGE) SET(PLATFORM_CFLAGS "-fprofile-arcs -ftest-coverage ${PLATFORM_CFLAGS}") + SET(PLATFORM_CXXFLAGS "-fprofile-arcs -ftest-coverage ${PLATFORM_CXXFLAGS}") ENDIF(WITH_COVERAGE) IF(APPLE) SET(PLATFORM_CFLAGS "-gdwarf-2 ${PLATFORM_CFLAGS}") + SET(PLATFORM_CXXFLAGS "-gdwarf-2 ${PLATFORM_CXXFLAGS}") ENDIF(APPLE) IF(APPLE AND XCODE) @@ -538,6 +560,7 @@ MACRO(NL_SETUP_BUILD) IF(CMAKE_OSX_SYSROOT) SET(PLATFORM_CFLAGS "-isysroot ${CMAKE_OSX_SYSROOT} ${PLATFORM_CFLAGS}") + SET(PLATFORM_CXXFLAGS "-isysroot ${CMAKE_OSX_SYSROOT} ${PLATFORM_CXXFLAGS}") ELSE(CMAKE_OSX_SYSROOT) MESSAGE(FATAL_ERROR "CMAKE_OSX_SYSROOT can't be determinated") ENDIF(CMAKE_OSX_SYSROOT) @@ -545,10 +568,12 @@ MACRO(NL_SETUP_BUILD) IF(CMAKE_OSX_ARCHITECTURES) FOREACH(_ARCH ${CMAKE_OSX_ARCHITECTURES}) SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -arch ${_ARCH}") + SET(PLATFORM_CXXFLAGS "${PLATFORM_CXXFLAGS} -arch ${_ARCH}") ENDFOREACH(_ARCH) ENDIF(CMAKE_OSX_ARCHITECTURES) IF(CMAKE_C_OSX_DEPLOYMENT_TARGET_FLAG) 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) 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 IF(TARGET_X64 AND WITH_STATIC AND NOT WITH_STATIC_DRIVERS) SET(PLATFORM_CFLAGS "-fPIC ${PLATFORM_CFLAGS}") + SET(PLATFORM_CXXFLAGS "-fPIC ${PLATFORM_CXXFLAGS}") 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) SET(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,--no-undefined -Wl,--as-needed")