From c9dd2066807b788367db2bbf61df25dec1fa45ba Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Thu, 7 Mar 2024 09:36:32 +0100 Subject: [PATCH] CMake: introduce mayo_config.h for global compile definitions --- CMakeLists.txt | 23 ++++++++++++------- src/app/command_system_information.cpp | 2 +- src/app/dialog_about.cpp | 3 ++- src/app/main.cpp | 2 +- src/io_assimp/io_assimp.cpp | 6 ++--- src/io_assimp/io_assimp.h | 6 +++-- src/io_gmio/io_gmio.h | 5 ++-- src/io_gmio/io_gmio_amf_writer.cpp | 6 ++--- src/mayo_config.h.cmake | 16 +++++++++++++ .../version.h.cmake => mayo_version.h.cmake} | 6 +++++ tests/test_base.cpp | 5 ++-- 11 files changed, 56 insertions(+), 24 deletions(-) create mode 100644 src/mayo_config.h.cmake rename src/{app/version.h.cmake => mayo_version.h.cmake} (54%) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5011905..dfe0cee5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,8 +55,6 @@ if(Git_FOUND) endif() endif() -configure_file(${PROJECT_SOURCE_DIR}/src/app/version.h.cmake app/version.h @ONLY) - list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") # Find bit size of the target machine @@ -204,7 +202,7 @@ set( Mayo_IncludeDirectories src/app src/3rdparty - ${CMAKE_BINARY_DIR}/app + ${CMAKE_BINARY_DIR} ) ########## @@ -276,7 +274,7 @@ if(Mayo_BuildTests) list(APPEND Mayo_HeaderFiles ${MayoTests_HeaderFiles}) list(APPEND Mayo_SourceFiles ${MayoTests_SourceFiles}) - list(APPEND Mayo_CompileDefinitions MAYO_WITH_TESTS) + set(MAYO_WITH_TESTS 1) list(APPEND Mayo_LinkLibraries Qt${QT_VERSION_MAJOR}::Test) file(GLOB MayoTests_InputFiles ${PROJECT_SOURCE_DIR}/tests/inputs/*.*) @@ -426,12 +424,13 @@ if(assimp_FOUND) list(APPEND Mayo_SourceFiles ${MayoPluginAssimp_SourceFiles}) list(APPEND Mayo_LinkLibraries ${ASSIMP_LIBRARIES}) - list(APPEND Mayo_CompileDefinitions HAVE_ASSIMP) + set(MAYO_HAVE_ASSIMP 1) list(GET ASSIMP_INCLUDE_DIRS 0 assimp_IncludeDir) file(READ "${assimp_IncludeDir}/assimp/version.h" assimp_FileVersionH) - if(NOT assimp_FileVersionH MATCHES "aiGetVersionPatch") - list(APPEND Mayo_CompileDefinitions NO_ASSIMP_aiGetVersionPatch) + if(assimp_FileVersionH MATCHES "aiGetVersionPatch") + set(MAYO_HAVE_ASSIMP_aiGetVersionPatch 1) + else() message(STATUS "Assimp function aiGetVersionPatch() not available") endif() endif() @@ -443,6 +442,13 @@ endif() # TODO +########## +# Configure files +########## + +configure_file(${PROJECT_SOURCE_DIR}/src/mayo_config.h.cmake common/mayo_config.h @ONLY) +configure_file(${PROJECT_SOURCE_DIR}/src/mayo_version.h.cmake common/mayo_version.h @ONLY) + ########## # Targets ########## @@ -491,7 +497,8 @@ add_custom_target( images/credits.txt scripts/bump-version.rb scripts/gen-cmake-opencascade-vars.bat - src/app/version.h.cmake + src/mayo_config.h.cmake + src/mayo_version.h.cmake README.md ) diff --git a/src/app/command_system_information.cpp b/src/app/command_system_information.cpp index 5fb843f9..05017e43 100644 --- a/src/app/command_system_information.cpp +++ b/src/app/command_system_information.cpp @@ -10,10 +10,10 @@ #include "command_system_information_occopengl.h" #include "qstring_conv.h" #include "qtwidgets_utils.h" -#include "version.h" #include "../base/meta_enum.h" #include "../base/filepath.h" #include "../base/io_system.h" +#include #include #include diff --git a/src/app/dialog_about.cpp b/src/app/dialog_about.cpp index 86d674bb..d117a6ba 100644 --- a/src/app/dialog_about.cpp +++ b/src/app/dialog_about.cpp @@ -8,7 +8,8 @@ #include "ui_dialog_about.h" #include "qstring_conv.h" -#include "version.h" +#include + #include namespace Mayo { diff --git a/src/app/main.cpp b/src/app/main.cpp index d7eed7ab..ec9d611d 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -32,11 +32,11 @@ #include "qstring_conv.h" #include "qtgui_utils.h" #include "theme.h" -#include "version.h" #include "widget_model_tree.h" #include "widget_model_tree_builder_mesh.h" #include "widget_model_tree_builder_xde.h" #include "widget_occ_view.h" +#include #include #include diff --git a/src/io_assimp/io_assimp.cpp b/src/io_assimp/io_assimp.cpp index 98d74fc3..8c03831c 100644 --- a/src/io_assimp/io_assimp.cpp +++ b/src/io_assimp/io_assimp.cpp @@ -7,9 +7,7 @@ #include "io_assimp.h" #include "io_assimp_reader.h" -#ifdef HAVE_ASSIMP -# include -#endif +#include namespace Mayo { namespace IO { @@ -47,7 +45,7 @@ std::string_view AssimpLib::strVersion() if (str.empty()) { str += std::to_string(aiGetVersionMajor()) + "." + std::to_string(aiGetVersionMinor()) -#ifndef NO_ASSIMP_aiGetVersionPatch +#ifdef MAYO_HAVE_ASSIMP_aiGetVersionPatch + "." + std::to_string(aiGetVersionPatch()) #else + ".?" diff --git a/src/io_assimp/io_assimp.h b/src/io_assimp/io_assimp.h index d8a25b04..5e30d1c7 100644 --- a/src/io_assimp/io_assimp.h +++ b/src/io_assimp/io_assimp.h @@ -6,6 +6,8 @@ #include "../base/io_reader.h" #include "../base/property.h" +#include + #include namespace Mayo { @@ -19,7 +21,7 @@ class AssimpFactoryReader : public FactoryReader { std::unique_ptr createProperties(Format format, PropertyGroup* parentGroup) const override; static std::unique_ptr create() { -#ifdef HAVE_ASSIMP +#ifdef MAYO_HAVE_ASSIMP return std::make_unique(); #else return {}; @@ -29,7 +31,7 @@ class AssimpFactoryReader : public FactoryReader { struct AssimpLib { static std::string_view strName() { return "Assimp"; } -#ifdef HAVE_ASSIMP +#ifdef MAYO_HAVE_ASSIMP static std::string_view strVersion(); static std::string_view strVersionDetails(); #else diff --git a/src/io_gmio/io_gmio.h b/src/io_gmio/io_gmio.h index 5ec737c0..f6c42cdf 100644 --- a/src/io_gmio/io_gmio.h +++ b/src/io_gmio/io_gmio.h @@ -8,6 +8,7 @@ #include "../base/io_writer.h" #include "../base/property.h" +#include #include @@ -22,7 +23,7 @@ class GmioFactoryWriter : public FactoryWriter { std::unique_ptr createProperties(Format format, PropertyGroup* parentGroup) const override; static std::unique_ptr create() { -#ifdef HAVE_GMIO +#ifdef MAYO_HAVE_GMIO return std::make_unique(); #else return {}; @@ -32,7 +33,7 @@ class GmioFactoryWriter : public FactoryWriter { struct GmioLib { static std::string_view strName() { return "gmio"; } -#ifdef HAVE_GMIO +#ifdef MAYO_HAVE_GMIO static std::string_view strVersion(); static std::string_view strVersionDetails() { return "(build)"; } #else diff --git a/src/io_gmio/io_gmio_amf_writer.cpp b/src/io_gmio/io_gmio_amf_writer.cpp index 8c2d0199..4222c816 100644 --- a/src/io_gmio/io_gmio_amf_writer.cpp +++ b/src/io_gmio/io_gmio_amf_writer.cpp @@ -64,13 +64,13 @@ gmio_task_iface gmio_createTask(TaskProgress* progress) return task; } -//#ifdef HAVE_GMIO +//#ifdef MAYO_HAVE_GMIO #if 0 Format System::probeFormat(const QString& filepath) const { QFile file(filepath); if (file.open(QIODevice::ReadOnly)) { -//#ifdef HAVE_GMIO +//#ifdef MAYO_HAVE_GMIO gmio_stream qtstream = gmio_stream_qiodevice(&file); const gmio_stl_format stlFormat = gmio_stl_format_probe(&qtstream); if (stlFormat != GMIO_STL_FORMAT_UNKNOWN) @@ -119,7 +119,7 @@ IO::Result IO::exportStl_gmio(ExportData data) return Result::error(file.errorString()); } -#endif // HAVE_GMIO +#endif // MAYO_HAVE_GMIO } // namespace diff --git a/src/mayo_config.h.cmake b/src/mayo_config.h.cmake new file mode 100644 index 00000000..57eab56c --- /dev/null +++ b/src/mayo_config.h.cmake @@ -0,0 +1,16 @@ +/**************************************************************************** +** Copyright (c) 2024, Fougue Ltd. +** All rights reserved. +** See license at https://github.com/fougue/mayo/blob/master/LICENSE.txt +****************************************************************************/ + +#pragma once + +#cmakedefine MAYO_WITH_TESTS +#cmakedefine MAYO_HAVE_ASSIMP +#cmakedefine MAYO_HAVE_ASSIMP_aiGetVersionPatch +#cmakedefine MAYO_HAVE_GMIO + +#ifdef HAVE_RAPIDJSON +# define OPENCASCADE_HAVE_RAPIDJSON +#endif diff --git a/src/app/version.h.cmake b/src/mayo_version.h.cmake similarity index 54% rename from src/app/version.h.cmake rename to src/mayo_version.h.cmake index 772191de..f4bb90e8 100644 --- a/src/app/version.h.cmake +++ b/src/mayo_version.h.cmake @@ -1,3 +1,9 @@ +/**************************************************************************** +** Copyright (c) 2024, Fougue Ltd. +** All rights reserved. +** See license at https://github.com/fougue/mayo/blob/master/LICENSE.txt +****************************************************************************/ + #pragma once namespace Mayo { diff --git a/tests/test_base.cpp b/tests/test_base.cpp index 74cfdef7..ee3baccf 100644 --- a/tests/test_base.cpp +++ b/tests/test_base.cpp @@ -39,6 +39,7 @@ #include "../src/io_off/io_off_writer.h" #include "../src/io_ply/io_ply_reader.h" #include "../src/io_ply/io_ply_writer.h" +#include #include #include @@ -608,7 +609,7 @@ void TestBase::IO_bugGitHub166_test_data() #if OCC_VERSION_HEX >= 0x070400 QTest::newRow("OBJ->PLY") << "tests/inputs/cube.obj" << "tests/outputs/cube.ply" << IO::Format_PLY; QTest::newRow("OBJ->STL") << "tests/inputs/cube.obj" << "tests/outputs/cube.stl" << IO::Format_STL; -# ifdef HAVE_RAPIDJSON +# ifdef OPENCASCADE_HAVE_RAPIDJSON QTest::newRow("glTF->PLY") << "tests/inputs/cube.gltf" << "tests/outputs/cube.ply" << IO::Format_PLY; QTest::newRow("glTF->STL") << "tests/inputs/cube.gltf" << "tests/outputs/cube.stl" << IO::Format_STL; # endif @@ -617,7 +618,7 @@ void TestBase::IO_bugGitHub166_test_data() #if OCC_VERSION_HEX >= 0x070600 QTest::newRow("PLY->OBJ") << "tests/inputs/cube.ply" << "tests/outputs/cube.obj" << IO::Format_OBJ; QTest::newRow("STL->OBJ") << "tests/inputs/cube.stla" << "tests/outputs/cube.obj" << IO::Format_OBJ; -# ifdef HAVE_RAPIDJSON +# ifdef OPENCASCADE_HAVE_RAPIDJSON QTest::newRow("glTF->OBJ") << "tests/inputs/cube.gltf" << "tests/outputs/cube.obj" << IO::Format_OBJ; QTest::newRow("OBJ->glTF") << "tests/inputs/cube.obj" << "tests/outputs/cube.glTF" << IO::Format_GLTF; # endif