llvm.org GIT mirror llvm / e6f17d4
[cmake] Move blocks out of redundant else( MSVC ); NFC Address post-commit comment on D66256 regarding the `else( MSVC )` block containing only blocks guarded with `LLVM_COMPILER_IS_GCC_COMPATIBLE`, which would imply `NOT MSVC`. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369221 91177308-0d34-0410-b5e6-96231b3b80d8 Hubert Tong 2 months ago
1 changed file(s) with 63 addition(s) and 64 deletion(s). Raw diff Collapse all Expand all
430430 endif()
431431 endif()
432432 endif()
433
434 else( MSVC )
435 # Warnings-as-errors handling for GCC-compatible compilers:
436 if ( LLVM_COMPILER_IS_GCC_COMPATIBLE )
437 append_if(LLVM_ENABLE_WERROR "-Werror" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
438 append_if(LLVM_ENABLE_WERROR "-Wno-error" CMAKE_REQUIRED_FLAGS)
439 endif( LLVM_COMPILER_IS_GCC_COMPATIBLE )
440
441 # Specific default warnings-as-errors for compilers accepting GCC-compatible warning flags:
442 if ( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" )
443 add_flag_if_supported("-Werror=date-time" WERROR_DATE_TIME)
444 add_flag_if_supported("-Werror=unguarded-availability-new" WERROR_UNGUARDED_AVAILABILITY_NEW)
445 endif( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" )
446
447 # C++ language standard selection for compilers accepting the GCC-style option:
448 if ( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" )
449 check_cxx_compiler_flag("-std=${LLVM_CXX_STD}" CXX_SUPPORTS_CXX_STD)
450 if (CXX_SUPPORTS_CXX_STD)
451 if (CYGWIN OR MINGW)
452 # MinGW and Cygwin are a bit stricter and lack things like
453 # 'strdup', 'stricmp', etc in c++11 mode.
454 string(REPLACE "c++" "gnu++" gnu_LLVM_CXX_STD "${LLVM_CXX_STD}")
455 append("-std=${gnu_LLVM_CXX_STD}" CMAKE_CXX_FLAGS)
456 else()
457 append("-std=${LLVM_CXX_STD}" CMAKE_CXX_FLAGS)
458 endif()
433 endif( MSVC )
434
435 # Warnings-as-errors handling for GCC-compatible compilers:
436 if ( LLVM_COMPILER_IS_GCC_COMPATIBLE )
437 append_if(LLVM_ENABLE_WERROR "-Werror" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
438 append_if(LLVM_ENABLE_WERROR "-Wno-error" CMAKE_REQUIRED_FLAGS)
439 endif( LLVM_COMPILER_IS_GCC_COMPATIBLE )
440
441 # Specific default warnings-as-errors for compilers accepting GCC-compatible warning flags:
442 if ( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" )
443 add_flag_if_supported("-Werror=date-time" WERROR_DATE_TIME)
444 add_flag_if_supported("-Werror=unguarded-availability-new" WERROR_UNGUARDED_AVAILABILITY_NEW)
445 endif( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" )
446
447 # C++ language standard selection for compilers accepting the GCC-style option:
448 if ( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" )
449 check_cxx_compiler_flag("-std=${LLVM_CXX_STD}" CXX_SUPPORTS_CXX_STD)
450 if (CXX_SUPPORTS_CXX_STD)
451 if (CYGWIN OR MINGW)
452 # MinGW and Cygwin are a bit stricter and lack things like
453 # 'strdup', 'stricmp', etc in c++11 mode.
454 string(REPLACE "c++" "gnu++" gnu_LLVM_CXX_STD "${LLVM_CXX_STD}")
455 append("-std=${gnu_LLVM_CXX_STD}" CMAKE_CXX_FLAGS)
459456 else()
460 message(FATAL_ERROR "The host compiler does not support '-std=${LLVM_CXX_STD}'.")
461 endif()
462 endif( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" )
463
464 # Modules enablement for GCC-compatible compilers:
465 if ( LLVM_COMPILER_IS_GCC_COMPATIBLE AND LLVM_ENABLE_MODULES )
466 set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
467 set(module_flags "-fmodules -fmodules-cache-path=${PROJECT_BINARY_DIR}/module.cache")
468 if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
469 # On Darwin -fmodules does not imply -fcxx-modules.
470 set(module_flags "${module_flags} -fcxx-modules")
471 endif()
472 if (LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY)
473 set(module_flags "${module_flags} -Xclang -fmodules-local-submodule-visibility")
474 endif()
475 if (LLVM_ENABLE_MODULE_DEBUGGING AND
476 ((uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") OR
477 (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")))
478 set(module_flags "${module_flags} -gmodules")
479 endif()
480 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${module_flags}")
481
482 # Check that we can build code with modules enabled, and that repeatedly
483 # including still manages to respect NDEBUG properly.
484 CHECK_CXX_SOURCE_COMPILES("#undef NDEBUG
485 #include
486 #define NDEBUG
487 #include
488 int main() { assert(this code is not compiled); }"
489 CXX_SUPPORTS_MODULES)
490 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
491 if (CXX_SUPPORTS_MODULES)
492 append("${module_flags}" CMAKE_CXX_FLAGS)
493 else()
494 message(FATAL_ERROR "LLVM_ENABLE_MODULES is not supported by this compiler")
495 endif()
496 endif( LLVM_COMPILER_IS_GCC_COMPATIBLE AND LLVM_ENABLE_MODULES )
497 endif( MSVC )
457 append("-std=${LLVM_CXX_STD}" CMAKE_CXX_FLAGS)
458 endif()
459 else()
460 message(FATAL_ERROR "The host compiler does not support '-std=${LLVM_CXX_STD}'.")
461 endif()
462 endif( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" )
463
464 # Modules enablement for GCC-compatible compilers:
465 if ( LLVM_COMPILER_IS_GCC_COMPATIBLE AND LLVM_ENABLE_MODULES )
466 set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
467 set(module_flags "-fmodules -fmodules-cache-path=${PROJECT_BINARY_DIR}/module.cache")
468 if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
469 # On Darwin -fmodules does not imply -fcxx-modules.
470 set(module_flags "${module_flags} -fcxx-modules")
471 endif()
472 if (LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY)
473 set(module_flags "${module_flags} -Xclang -fmodules-local-submodule-visibility")
474 endif()
475 if (LLVM_ENABLE_MODULE_DEBUGGING AND
476 ((uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") OR
477 (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")))
478 set(module_flags "${module_flags} -gmodules")
479 endif()
480 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${module_flags}")
481
482 # Check that we can build code with modules enabled, and that repeatedly
483 # including still manages to respect NDEBUG properly.
484 CHECK_CXX_SOURCE_COMPILES("#undef NDEBUG
485 #include
486 #define NDEBUG
487 #include
488 int main() { assert(this code is not compiled); }"
489 CXX_SUPPORTS_MODULES)
490 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
491 if (CXX_SUPPORTS_MODULES)
492 append("${module_flags}" CMAKE_CXX_FLAGS)
493 else()
494 message(FATAL_ERROR "LLVM_ENABLE_MODULES is not supported by this compiler")
495 endif()
496 endif( LLVM_COMPILER_IS_GCC_COMPATIBLE AND LLVM_ENABLE_MODULES )
498497
499498 if (MSVC)
500499 if (NOT CLANG_CL)