From: Jarkko Pöyry Date: Thu, 26 Feb 2015 20:51:49 +0000 (-0800) Subject: Fail build early if compiler is configured incorrectly. X-Git-Tag: upstream/0.1.0~1896^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c4729614f38fba324af8d2990fff4faeb78a7ddc;p=platform%2Fupstream%2FVK-GL-CTS.git Fail build early if compiler is configured incorrectly. - Detect and fail if CC and CXX are inconsistent in CMake script. - Issue #error if DE_COMPILER does not match the detected. This can be caused if make is invoked by CMake that fails compiler detection. Change-Id: I930f752c155de5a0a5c04b8bdfd23954117a75ae --- diff --git a/framework/delibs/cmake/Defs.cmake b/framework/delibs/cmake/Defs.cmake index 462c9d5..f34bba5 100644 --- a/framework/delibs/cmake/Defs.cmake +++ b/framework/delibs/cmake/Defs.cmake @@ -61,6 +61,13 @@ DE_MAKE_ENV_BOOL("DE_OS" "OSX") DE_MAKE_ENV_BOOL("DE_OS" "ANDROID") DE_MAKE_ENV_BOOL("DE_OS" "IOS") +# Prevent mixed compile with GCC and Clang +if (NOT ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU") EQUAL ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")) + message(FATAL_ERROR "CMake C and CXX compilers do not match. Both or neither must be GNU.") +elseif (NOT ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang") EQUAL ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")) + message(FATAL_ERROR "CMake C and CXX compilers do not match. Both or neither must be Clang.") +endif () + # Compiler detection if (NOT DEFINED DE_COMPILER) # \note " x" postfix is to work around bug in CMake that causes diff --git a/framework/delibs/debase/deDefs.h b/framework/delibs/debase/deDefs.h index b02a74d..3c3abbf 100644 --- a/framework/delibs/debase/deDefs.h +++ b/framework/delibs/debase/deDefs.h @@ -30,16 +30,42 @@ #define DE_COMPILER_CLANG 3 /*!< LLVM Clang Compiler. */ /* Compiler detection. */ -#if defined(DE_COMPILER) - /* Allow definitions from outside. */ -#elif defined(_MSC_VER) -# define DE_COMPILER DE_COMPILER_MSC /*!< Compiler identification (set to one of DE_COMPILER_*). */ +#if defined(_MSC_VER) +# define DE_DETAIL_DETECTED_COMPILER DE_COMPILER_MSC #elif defined(__clang__) -# define DE_COMPILER DE_COMPILER_CLANG +# define DE_DETAIL_DETECTED_COMPILER DE_COMPILER_CLANG #elif defined(__GNUC__) -# define DE_COMPILER DE_COMPILER_GCC +# define DE_DETAIL_DETECTED_COMPILER DE_COMPILER_GCC #else -# error Unknown compiler. + /* DE_DETAIL_DETECTED_COMPILER not set */ +#endif + +/* Compiler setting. */ +#if defined(DE_COMPILER) + /* Allow definitions from outside, but fail early if it conflicts with our detection */ +# if defined(DE_DETAIL_DETECTED_COMPILER) && (DE_COMPILER != DE_DETAIL_DETECTED_COMPILER) + /* conflict, print a nice error messages for the most common misconfigs, + * GCC and Clang, and a generic for other conflicts. + */ +# if (DE_DETAIL_DETECTED_COMPILER == DE_COMPILER_CLANG) && (DE_COMPILER == DE_COMPILER_GCC) +# error Detected compiler is Clang, but got DE_COMPILER == DE_COMPILER_GCC +# elif (DE_DETAIL_DETECTED_COMPILER == DE_COMPILER_GCC) && (DE_COMPILER == DE_COMPILER_CLANG) +# error Detected compiler is GCC, but got DE_COMPILER == DE_COMPILER_CLANG +# else +# error Detected compiler does not match the supplied compiler. +# endif +# endif + /* Clear autodetect vars. */ +# if defined(DE_DETAIL_DETECTED_COMPILER) +# undef DE_DETAIL_DETECTED_COMPILER +# endif +#else + /* No definition given from outside, try to autodetect */ +# if defined(DE_DETAIL_DETECTED_COMPILER) +# define DE_COMPILER DE_DETAIL_DETECTED_COMPILER /*!< Compiler identification (set to one of DE_COMPILER_*). */ +# else +# error Unknown compiler. +# endif #endif /* Operating systems. */ @@ -47,7 +73,7 @@ #define DE_OS_WIN32 1 /*!< Microsoft Windows desktop */ #define DE_OS_UNIX 2 /*!< Unix (or compatible) */ #define DE_OS_WINCE 3 /*!< Windows CE, Windows Mobile or Pocket PC */ -#define DE_OS_OSX 4 /*!< Mac OS X */ +#define DE_OS_OSX 4 /*!< Mac OS X */ #define DE_OS_ANDROID 5 /*!< Android */ #define DE_OS_SYMBIAN 6 /*!< Symbian OS */ #define DE_OS_IOS 7 /*!< iOS */