From 5d22c3c680f01efeb2bdaa5160b5d871351be79e Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Fri, 1 Sep 2023 00:05:49 +0200 Subject: [PATCH 1/3] cmake: a few fixes for multi-config generators --- CMakeLists.txt | 19 ++- cmake/EnableCompilerWarnings.cmake | 183 ++++++++++++++++------------- src/CMakeLists.txt | 4 +- src/sqlite/CMakeLists.txt | 12 +- 4 files changed, 121 insertions(+), 97 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d95378708..4f78da5565 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,10 +37,20 @@ macro(set_var_to_condition var) endif() endmacro() +get_property(_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(_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 @@ -256,8 +266,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..e81acd3d57 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 + -Wno-undef + -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 c0bc457b93..d4378c2f0a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,7 +55,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 _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 From 1ffcfefcb21b657b316d0f178cc66f075f77e5b1 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Mon, 13 Nov 2023 20:50:23 +0100 Subject: [PATCH 2/3] Update CMakeLists.txt Co-authored-by: Artem Tamazov --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4793d47e66..55f6a53080 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,7 @@ macro(set_var_to_condition var) endif() endmacro() -get_property(_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +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. From e923f11ff5f130fb10eea29568071cae6a7e9585 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Mon, 13 Nov 2023 20:56:09 +0100 Subject: [PATCH 3/3] incorporate review feedback --- CMakeLists.txt | 2 +- cmake/EnableCompilerWarnings.cmake | 2 +- src/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 55f6a53080..ac0bd5cc62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,7 @@ get_property(MIOPEN_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI # 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. -if(_GENERATOR_IS_MULTI_CONFIG) +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") diff --git a/cmake/EnableCompilerWarnings.cmake b/cmake/EnableCompilerWarnings.cmake index e81acd3d57..03a26b0c09 100644 --- a/cmake/EnableCompilerWarnings.cmake +++ b/cmake/EnableCompilerWarnings.cmake @@ -39,7 +39,7 @@ set(__default_cxx_compile_options -Wsequence-point -Wswitch -Wtrigraphs - -Wno-undef + -Wundef -Wuninitialized -Wunreachable-code -Wunused diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9e0d2b5552..3f922f5970 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -59,7 +59,7 @@ configure_file( "${PROJECT_SOURCE_DIR}/include/miopen/miopen.h" "${PROJECT_BINAR endif() message( STATUS "MIOpen_VERSION= ${MIOpen_VERSION}" ) -if(NOT _GENERATOR_IS_MULTI_CONFIG) +if(NOT MIOPEN_GENERATOR_IS_MULTI_CONFIG) message( STATUS "CMAKE_BUILD_TYPE= ${CMAKE_BUILD_TYPE}" ) endif()