diff --git a/CMakeLists.txt b/CMakeLists.txt index d48d9980b..63649e49d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -352,6 +352,9 @@ if(TOM) if(BUILD_TESTS) target_compile_definitions(${TinyOrm_target} PUBLIC TINYTOM_TESTS_CODE) endif() + + # Set TINYORM_LTO macro based on the INTERPROCEDURAL_OPTIMIZATION target property + tiny_set_lto_compile_definition(${TinyOrm_target}) endif() if(TOM_EXAMPLE) diff --git a/cmake/CommonModules/TinyHelpers.cmake b/cmake/CommonModules/TinyHelpers.cmake index 937c55bdf..71c8b386e 100644 --- a/cmake/CommonModules/TinyHelpers.cmake +++ b/cmake/CommonModules/TinyHelpers.cmake @@ -173,6 +173,16 @@ ${TINY_UNPARSED_ARGUMENTS}") endfunction() +# Set TINYORM_LTO macro based on the INTERPROCEDURAL_OPTIMIZATION target property +# Used by the tom about command to show if the LTO is enabled +function(tiny_set_lto_compile_definition target) + + get_target_property(tinyHasLTO ${target} INTERPROCEDURAL_OPTIMIZATION) + + target_compile_definitions(${target} PRIVATE -DTINYORM_LTO=${tinyHasLTO}) + +endfunction() + # Create an empty SQLite database file if it does not exist function(tiny_create_sqlite_db db_filepath) diff --git a/src/orm/libraryinfo.cpp b/src/orm/libraryinfo.cpp index 3b423d5f6..b64bf582f 100644 --- a/src/orm/libraryinfo.cpp +++ b/src/orm/libraryinfo.cpp @@ -111,6 +111,10 @@ std::map LibraryInfo::ormCMacrosMap() #else {sl("TINYORM_INLINE_CONSTANTS"), OFF}, #endif +// CMake ON/OFF +#ifdef TINYORM_LTO + {sl("TINYORM_LTO"), TINY_CMAKE_BOOL(TINYORM_LTO)}, +#endif #ifdef TINYORM_MYSQL_PING {sl("TINYORM_MYSQL_PING"), ON}, #else diff --git a/tom/src/tom/commands/aboutcommand.cpp b/tom/src/tom/commands/aboutcommand.cpp index e41f53833..21cfe35bf 100644 --- a/tom/src/tom/commands/aboutcommand.cpp +++ b/tom/src/tom/commands/aboutcommand.cpp @@ -299,7 +299,7 @@ QVector AboutCommand::gatherAllAboutInformation() const }; } -#ifdef TINYORM_MSVC_RUNTIME_DYNAMIC +#if defined(TINYORM_MSVC_RUNTIME_DYNAMIC) || defined(TINYORM_LTO) using Orm::Constants::OFF; using Orm::Constants::ON; @@ -331,6 +331,10 @@ QVector AboutCommand::gatherEnvironmentInformation() const {sl("Link type"), "Static"}, #endif // CMake ON/OFF +// qmake has bad support for ltcg so it's not handled in qmake (don't do it in future) +#ifdef TINYORM_LTO + {sl("Link Time Optimization"), TINY_CMAKE_BOOL(TINYORM_LTO)}, +#endif #ifdef TINYORM_MSVC_RUNTIME_DYNAMIC {sl("MSVC Runtime dynamic"), TINY_CMAKE_BOOL(TINYORM_MSVC_RUNTIME_DYNAMIC)},