diff --git a/CMakeLists.txt b/CMakeLists.txt index 57c5765eacc..2ff9866d7d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -304,6 +304,24 @@ if(UNIX AND NOT HAIKU) endif() endif() +include(CheckCXXSourceCompiles) + +if(UNIX OR APPLE) + # Some systems require the __STDC_FORMAT_MACROS macro to be defined + # to get the fixed-width integer type formatter macros. + check_cxx_source_compiles("#include + #include + int main() + { + int64_t i64{}; + std::printf(\"%\" PRId64, i64); + }" + HAVE_STDC_FORMAT_MACROS) + if(NOT HAVE_STDC_FORMAT_MACROS) + add_definitions(-D__STDC_FORMAT_MACROS) + endif() +endif() + # configure ccache if requested include(cmake/ccache.cmake) diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template index 034497df7fb..f274da5442a 100644 --- a/templates/CMakeLists.txt.template +++ b/templates/CMakeLists.txt.template @@ -427,6 +427,24 @@ endif() endif() + include(CheckCXXSourceCompiles) + + if(UNIX OR APPLE) + # Some systems require the __STDC_FORMAT_MACROS macro to be defined + # to get the fixed-width integer type formatter macros. + check_cxx_source_compiles("#include + #include + int main() + { + int64_t i64{}; + std::printf(\"%\" PRId64, i64); + }" + HAVE_STDC_FORMAT_MACROS) + if(NOT HAVE_STDC_FORMAT_MACROS) + add_definitions(-D__STDC_FORMAT_MACROS) + endif() + endif() + # configure ccache if requested include(cmake/ccache.cmake)