diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -37,11 +37,19 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") include(AddFlang) +if (MSVC) + set(_FLANG_ENABLE_WERROR_DEFAULT OFF) +else () + set(_FLANG_ENABLE_WERROR_DEFAULT ON) +endif() +option(FLANG_ENABLE_WERROR "Fail and stop building flang if a warning is triggered." + "${_FLANG_ENABLE_WERROR_DEFAULT}") + # Check for a standalone build and configure as appropriate from # there. if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) -message("Building Flang as a standalone project.") -project(Flang) + message("Building Flang as a standalone project.") + project(Flang) set(FLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) if (NOT MSVC_IDE) @@ -59,6 +67,8 @@ if(LLVM_ENABLE_ZLIB) find_package(ZLIB REQUIRED) endif() + option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON) + option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) include(CMakeParseArguments) include(AddLLVM) @@ -76,7 +86,6 @@ NO_DEFAULT_PATH) endif() - option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON) option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF) option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN @@ -235,8 +244,21 @@ ${FLANG_SOURCE_DIR}/include/flang/Config/config.h.cmake ${FLANG_BINARY_DIR}/include/flang/Config/config.h) -# Add global F18 flags. -set(CMAKE_CXX_FLAGS "-fno-rtti -fno-exceptions -pedantic -Wall -Wextra -Werror -Wcast-qual -Wimplicit-fallthrough -Wdelete-non-virtual-dtor ${CMAKE_CXX_FLAGS}") +if (FLANG_ENABLE_WERROR) + # The following is taken from llvm/cmake/modules/HandleLLVMOptions.cmake + # Keep this up-to-date with that file + if( MSVC ) + append("/WX" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + endif() + # Same as before, but LLVM_ENABLE_WERROR is changed to FLANG_ENABLE_WERROR + if ( LLVM_COMPILER_IS_GCC_COMPATIBLE ) + append_if(FLANG_ENABLE_WERROR "-Werror" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + append_if(FLANG_ENABLE_WERROR "-Wno-error" CMAKE_REQUIRED_FLAGS) + endif( LLVM_COMPILER_IS_GCC_COMPATIBLE ) + if (NOT LLVM_ENABLE_WERROR) + message(WARNING "FLANG_ENABLE_WERROR setting is different from LLVM_ENABLE_WERROR.") + endif() +endif() # Builtin check_cxx_compiler_flag doesn't seem to work correctly macro(check_compiler_flag flag resultVar) @@ -246,11 +268,11 @@ check_compiler_flag("-Werror -Wno-deprecated-copy" CXX_SUPPORTS_NO_DEPRECATED_COPY_FLAG) if (CXX_SUPPORTS_NO_DEPRECATED_COPY_FLAG) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-copy") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-copy") endif() check_compiler_flag("-Wstring-conversion" CXX_SUPPORTS_NO_STRING_CONVERSION_FLAG) if (CXX_SUPPORTS_NO_STRING_CONVERSION_FLAG) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-string-conversion") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-string-conversion") endif() # Add appropriate flags for GCC diff --git a/flang/lib/Optimizer/CMakeLists.txt b/flang/lib/Optimizer/CMakeLists.txt --- a/flang/lib/Optimizer/CMakeLists.txt +++ b/flang/lib/Optimizer/CMakeLists.txt @@ -1,5 +1,2 @@ -# Sources generated by tablegen have unused parameters. -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter") - add_subdirectory(Dialect) add_subdirectory(Support) diff --git a/flang/unittests/Evaluate/CMakeLists.txt b/flang/unittests/Evaluate/CMakeLists.txt --- a/flang/unittests/Evaluate/CMakeLists.txt +++ b/flang/unittests/Evaluate/CMakeLists.txt @@ -88,10 +88,12 @@ # IEEE exception flags (different use of the word "exception") # in the actual hardware floating-point status register, so ensure that # C++ exceptions are enabled for this test. -set_source_files_properties(real.cpp PROPERTIES COMPILE_FLAGS -fexceptions) +set(LLVM_REQUIRES_EH ON) +set(LLVM_REQUIRES_RTTI ON) add_executable(real-test real.cpp ) +llvm_update_compile_flags(real-test) target_link_libraries(real-test FortranEvaluateTesting diff --git a/flang/unittests/Runtime/CMakeLists.txt b/flang/unittests/Runtime/CMakeLists.txt --- a/flang/unittests/Runtime/CMakeLists.txt +++ b/flang/unittests/Runtime/CMakeLists.txt @@ -1,11 +1,12 @@ -if(CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions") -endif() set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +# RuntimeTesting needs exceptions enabled +set(LLVM_REQUIRES_EH ON) +set(LLVM_REQUIRES_RTTI ON) add_library(RuntimeTesting testing.cpp ) +llvm_update_compile_flags(RuntimeTesting) add_executable(format-test format.cpp