From 8b78deb46edfdb91ae1fd45271663ec1240b56d7 Mon Sep 17 00:00:00 2001 From: silverqx Date: Fri, 8 Oct 2021 21:03:33 +0200 Subject: [PATCH] qmake/cmake inline/extern constants edge cases Enhanced qmake/cmake builds during testing of all Win32 build types. - throw fatal error for unsupported build types - cmake do not show INLINE_CONSTANTS option for MinGW clang shared build because it causes crashes --- CMakeLists.txt | 16 +++++++++++----- cmake/CommonModules/TinyHelpers.cmake | 10 ++++++++++ cmake/Modules/TinyInitDefaultVariables.cmake | 12 ++++++++---- include/orm/tiny/model.hpp | 1 + qmake/common.pri | 9 +++++++++ qmake/features/inline_constants.prf | 8 ++++++++ 6 files changed, 47 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 52df530bf..197ea0ad7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,11 +63,6 @@ feature_option(BUILD_SHARED_LIBS feature_option(BUILD_TESTS "Build Qt tests" OFF ) -feature_option_dependent(INLINE_CONSTANTS - "Use inline constants instead of extern constants in the shared build. \ -OFF is highly recommended for the shared build; is always ON for the static build" OFF - "BUILD_SHARED_LIBS" ON -) # TODO make it also dependend on NOT isMultiConfig silverqx # Depends on tiny_init_cmake_variables_pre() call feature_option_dependent(MATCH_EQUAL_EXPORTED_BUILDTREE @@ -84,6 +79,14 @@ feature_option(VERBOSE_CONFIGURE "Show information about PACKAGES_FOUND and PACKAGES_NOT_FOUND in the configure \ output" OFF ) +# MinGW clang shared build crashes with inline constants +if(NOT MINGW OR NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR NOT BUILD_SHARED_LIBS) + feature_option_dependent(INLINE_CONSTANTS + "Use inline constants instead of extern constants in the shared build. \ +OFF is highly recommended for the shared build; is always ON for the static build" OFF + "BUILD_SHARED_LIBS" ON + ) +endif() mark_as_advanced(MATCH_EQUAL_EXPORTED_BUILDTREE) @@ -102,6 +105,9 @@ OFF to disable /MP completely.") tiny_init_cmake_variables() tiny_init_tiny_variables() +# Throw a fatal error for unsupported environments +tiny_check_unsupported_build() + # TinyORM library header and source files # --- diff --git a/cmake/CommonModules/TinyHelpers.cmake b/cmake/CommonModules/TinyHelpers.cmake index 7e40465db..78220728e 100644 --- a/cmake/CommonModules/TinyHelpers.cmake +++ b/cmake/CommonModules/TinyHelpers.cmake @@ -194,3 +194,13 @@ macro(tiny_set_rc_flags) set(TINY_RC_FLAGS_BACKUP "${ARGN}") endmacro() + +# Throw a fatal error for unsupported environments +function(tiny_check_unsupported_build) + + if(MINGW AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT BUILD_SHARED_LIBS) + message(FATAL_ERROR "MinGW clang static build is not supported, problem with \ +inline constants :/.") + endif() + +endfunction() diff --git a/cmake/Modules/TinyInitDefaultVariables.cmake b/cmake/Modules/TinyInitDefaultVariables.cmake index d69833bfa..ebfce6247 100644 --- a/cmake/Modules/TinyInitDefaultVariables.cmake +++ b/cmake/Modules/TinyInitDefaultVariables.cmake @@ -164,11 +164,15 @@ ${CMAKE_BINARY_DIR}/tests/auto/utils${TINY_PATH_SEPARATOR}$ENV{PATH}") # Specifies which global constant types will be used if(BUILD_SHARED_LIBS AND NOT INLINE_CONSTANTS) - set(TINY_EXTERN_CONSTANTS ON CACHE INTERNAL - "Determine whether the project will be built with extern constants") + set(tinyExternConstants ON) + message(VERBOSE "Using extern constants") else() - set(TINY_EXTERN_CONSTANTS OFF CACHE INTERNAL - "Determine whether the project will be built with extern constants") + set(tinyExternConstants OFF) + message(VERBOSE "Using inline constants") endif() + set(TINY_EXTERN_CONSTANTS ${tinyExternConstants} CACHE INTERNAL + "Determine whether ${TinyOrm_target} library will be built with extern or inline \ +constants") + unset(tinyExternConstants) endmacro() diff --git a/include/orm/tiny/model.hpp b/include/orm/tiny/model.hpp index fb8da8763..0a3d8a16d 100644 --- a/include/orm/tiny/model.hpp +++ b/include/orm/tiny/model.hpp @@ -103,6 +103,7 @@ namespace Relations { // CUR enable QT_ASCII_CAST_WARNINGS silverqx // CUR autoconfigure qmake with qmake/TinyOrm.pri and TINY_ROOT_DIR and TINY_TINYORM_BUILDS_DIR silverqx // CUR rename export_global.hpp to export_common.hpp silverqx + // CUR RC file and manifest for tests silverqx /*! Base model class. */ template class Model : diff --git a/qmake/common.pri b/qmake/common.pri index ea575f875..383c8f508 100644 --- a/qmake/common.pri +++ b/qmake/common.pri @@ -1,3 +1,12 @@ +# Unsupported build types +# --- +win32-clang-g++: { + CONFIG(static, dll|shared|static|staticlib) | \ + CONFIG(staticlib, dll|shared|static|staticlib): \ + error( "MinGW clang static build is not supported, contains a problem with\ + duplicit symbols, you can try to fix it :)." ) +} + # Common Configuration ( also for tests ) # --- diff --git a/qmake/features/inline_constants.prf b/qmake/features/inline_constants.prf index d2cd548b6..257ef7395 100644 --- a/qmake/features/inline_constants.prf +++ b/qmake/features/inline_constants.prf @@ -1,3 +1,11 @@ +win32-clang-g++: { + CONFIG(shared, dll|shared|static|staticlib) | \ + CONFIG(dll, dll|shared|static|staticlib): \ + error( "inline constants (inline_constants CONFIG option) cause crashes with\ + an shared library on MinGW clang, please use\ + \"CONFIG += extern_constants\" instead." ) +} + CONFIG -= extern_constants DEFINES -= TINYORM_EXTERN_CONSTANTS