diff --git a/CMakeLists.txt b/CMakeLists.txt index e5de98d609..498a7c9afa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,10 +37,20 @@ macro(set_var_to_condition var) endif() endmacro() +get_property(MIOPEN_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + # This has to be initialized before the project() command appears -# Set the default of CMAKE_BUILD_TYPE to be release, unless user specifies with -D. MSVC_IDE does not use CMAKE_BUILD_TYPE -if( NOT MSVC_IDE AND NOT CMAKE_BUILD_TYPE ) - set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." ) +# Set the default of CMAKE_BUILD_TYPE to be release, unless user specifies with -D. +if(MIOPEN_GENERATOR_IS_MULTI_CONFIG) + if (NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo;MinSizeRel" CACHE STRING + "Available build types (configurations) on multi-config generators") + endif() +else() + if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release CACHE STRING + "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel.") + endif() endif() # Default installation path @@ -254,8 +264,7 @@ endif() message(STATUS "Hip compiler flags: ${HIP_COMPILER_FLAGS}") -add_definitions("-DHIP_COMPILER_FLAGS=${HIP_COMPILER_FLAGS}") - +add_compile_definitions($<$:HIP_COMPILER_FLAGS="${HIP_COMPILER_FLAGS}">) # HIP if( MIOPEN_BACKEND STREQUAL "HIP" OR MIOPEN_BACKEND STREQUAL "HIPOC" OR MIOPEN_BACKEND STREQUAL "HIPNOGPU") diff --git a/cmake/EnableCompilerWarnings.cmake b/cmake/EnableCompilerWarnings.cmake index 82a8116eb7..03a26b0c09 100644 --- a/cmake/EnableCompilerWarnings.cmake +++ b/cmake/EnableCompilerWarnings.cmake @@ -26,89 +26,104 @@ # - Enable warning all for gcc/clang or use /W4 for visual studio ## Strict warning level -if (MSVC) - # Use the highest warning level for visual studio. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /w") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /w") - # set(CMAKE_CXX_WARNING_LEVEL 4) - # if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") - # string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - # else () - # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") - # endif () +set(__msvc_cxx_compile_options /W4) - # set(CMAKE_C_WARNING_LEVEL 4) - # if (CMAKE_C_FLAGS MATCHES "/W[0-4]") - # string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - # else () - # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4") - # endif () +set(__default_cxx_compile_options + -Wall + -Wextra + -Wcomment + -Wendif-labels + -Wformat + -Winit-self + -Wreturn-type + -Wsequence-point + -Wswitch + -Wtrigraphs + -Wundef + -Wuninitialized + -Wunreachable-code + -Wunused + -Wno-ignored-qualifiers + -Wno-sign-compare +) -else() - foreach(COMPILER C CXX) - set(CMAKE_COMPILER_WARNINGS) - # use -Wall for gcc and clang - list(APPEND CMAKE_COMPILER_WARNINGS - -Wall - -Wextra - -Wcomment - -Wendif-labels - -Wformat - -Winit-self - -Wreturn-type - -Wsequence-point - # Shadow is broken on gcc when using lambdas - # -Wshadow - -Wswitch - -Wtrigraphs - -Wundef - -Wuninitialized - -Wunreachable-code - -Wunused - -Wno-ignored-qualifiers - -Wno-sign-compare - ) - if (CMAKE_${COMPILER}_COMPILER_ID MATCHES "Clang") - list(APPEND CMAKE_COMPILER_WARNINGS - -Weverything - -Wno-c++98-compat - -Wno-c++98-compat-pedantic - -Wno-conversion - -Wno-double-promotion - -Wno-exit-time-destructors - -Wno-extra-semi - -Wno-extra-semi-stmt - -Wno-float-conversion - -Wno-gnu-anonymous-struct - -Wno-gnu-zero-variadic-macro-arguments - -Wno-missing-prototypes - -Wno-nested-anon-types - -Wno-option-ignored - -Wno-padded - -Wno-return-std-move-in-c++11 - -Wno-shorten-64-to-32 - -Wno-sign-conversion - -Wno-unknown-warning-option - -Wno-unused-command-line-argument - -Wno-weak-vtables - -Wno-covered-switch-default - -Wno-unused-result - -Wno-unsafe-buffer-usage - -Wno-deprecated-declarations - -Wno-shadow-uncaptured-local - ) - else() - if (CMAKE_${COMPILER}_COMPILER_ID MATCHES "GNU" AND ${COMPILER} MATCHES "CXX") - # cmake 3.5.2 does not support >=. - if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.1") - list(APPEND CMAKE_COMPILER_WARNINGS - -Wno-ignored-attributes) - endif() - endif() - list(APPEND CMAKE_COMPILER_WARNINGS - -Wno-missing-field-initializers - ) - endif() - add_definitions(${CMAKE_COMPILER_WARNINGS}) - endforeach() -endif () +set(__clang_cxx_compile_options + -Weverything + -Wno-c++98-compat + -Wno-c++98-compat-pedantic + -Wno-conversion + -Wno-double-promotion + -Wno-exit-time-destructors + -Wno-extra-semi + -Wno-extra-semi-stmt + -Wno-float-conversion + -Wno-gnu-anonymous-struct + -Wno-gnu-zero-variadic-macro-arguments + -Wno-missing-prototypes + -Wno-nested-anon-types + -Wno-option-ignored + -Wno-padded + -Wno-return-std-move-in-c++11 + -Wno-shorten-64-to-32 + -Wno-sign-conversion + -Wno-unknown-warning-option + -Wno-unused-command-line-argument + -Wno-weak-vtables + -Wno-covered-switch-default + -Wno-unused-result + -Wno-unsafe-buffer-usage + -Wno-deprecated-declarations + -Wno-shadow-uncaptured-local + -Wno-global-constructors + -Wno-reserved-identifier + -Wno-zero-as-null-pointer-constant + -Wno-ignored-attributes + -Wno-deprecated + -Wno-incompatible-pointer-types + -Wno-old-style-cast + -Wno-unknown-attributes + -Wno-microsoft-cpp-macro + -Wno-microsoft-enum-value + -Wno-language-extension-token + -Wno-c++11-narrowing + -Wno-float-equal + -Wno-redundant-parens + -Wno-format-nonliteral + -Wno-unused-template + -Wno-comma + -Wno-suggest-destructor-override + -Wno-switch-enum + -Wno-shift-sign-overflow + -Wno-suggest-override + -Wno-inconsistent-missing-destructor-override + -Wno-cast-function-type + -Wno-nonportable-system-include-path + -Wno-incompatible-pointer-types + -Wno-documentation + -Wno-deprecated-builtins + -Wno-enum-constexpr-conversion + -Wno-unused-value + -Wno-unused-parameter + -Wno-missing-noreturn + -Wno-tautological-constant-out-of-range-compare) +if(WIN32) + list(APPEND __clang_cxx_compile_options + -fdelayed-template-parsing + -fms-extensions + -fms-compatibility) +endif() + +set(__gnu_cxx_compile_options + -Wno-missing-field-initializers +) + +add_compile_options( + "$<$:${__msvc_cxx_compile_options}>" + "$<$:${__default_cxx_compile_options};${__clang_cxx_compile_options}>" + "$<$:${__default_cxx_compile_options};${__gnu_cxx_compile_options}>" +) + +unset(__msvc_cxx_compile_options) +unset(__default_cxx_compile_options) +unset(__gnu_cxx_compile_options) +unset(__clang_cxx_compile_options) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 68674fdc5f..c34f935f78 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -58,7 +58,9 @@ configure_file( "${PROJECT_SOURCE_DIR}/include/miopen/miopen.h" "${PROJECT_BINAR endif() message( STATUS "MIOpen_VERSION= ${MIOpen_VERSION}" ) -message( STATUS "CMAKE_BUILD_TYPE= ${CMAKE_BUILD_TYPE}" ) +if(NOT MIOPEN_GENERATOR_IS_MULTI_CONFIG) + message( STATUS "CMAKE_BUILD_TYPE= ${CMAKE_BUILD_TYPE}" ) +endif() # This is incremented when the ABI to the library changes set( MIOpen_SOVERSION 1.0 ) diff --git a/src/sqlite/CMakeLists.txt b/src/sqlite/CMakeLists.txt index 8be3d45bf3..823a44cb7a 100644 --- a/src/sqlite/CMakeLists.txt +++ b/src/sqlite/CMakeLists.txt @@ -29,13 +29,11 @@ add_library( OBJECT memvfs.cpp ) -if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") -# using Clang -set_source_files_properties(memvfs.cpp PROPERTIES COMPILE_FLAGS "-Wno-everything ") -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") -# using GCC -set_source_files_properties(memvfs.cpp PROPERTIES COMPILE_FLAGS "-w ") -endif() + +target_compile_options(sqlite_memvfs PRIVATE + $<$:-Wno-everything> + $<$:-w>) + target_include_directories(sqlite_memvfs SYSTEM PRIVATE ${SQLITE3_STATIC_INCLUDE_DIRS}) # set_target_properties( # sqlite_memvfs