From b8658cefe06b0f279a669993b4db6bb56e67c2ef Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 5 Apr 2022 18:48:45 +0200 Subject: [PATCH 01/12] Link std_image statically. --- code/AssetLib/M3D/M3DWrapper.h | 1 + code/Common/Assimp.cpp | 1 + code/Pbrt/PbrtExporter.cpp | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/code/AssetLib/M3D/M3DWrapper.h b/code/AssetLib/M3D/M3DWrapper.h index 7cc2d0eef..fac63d099 100644 --- a/code/AssetLib/M3D/M3DWrapper.h +++ b/code/AssetLib/M3D/M3DWrapper.h @@ -59,6 +59,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Share stb_image's PNG loader with other importers/exporters instead of bringing our own copy. #define STBI_ONLY_PNG +#define STB_IMAGE_STATIC #include #include "m3d.h" diff --git a/code/Common/Assimp.cpp b/code/Common/Assimp.cpp index 71e312cee..bd3861f2e 100644 --- a/code/Common/Assimp.cpp +++ b/code/Common/Assimp.cpp @@ -1290,6 +1290,7 @@ ASSIMP_API void aiQuaternionInterpolate( # endif # define STB_IMAGE_IMPLEMENTATION +# define STB_IMAGE_STATIC # include "stb/stb_image.h" # if _MSC_VER diff --git a/code/Pbrt/PbrtExporter.cpp b/code/Pbrt/PbrtExporter.cpp index 25061f517..ea29860d3 100644 --- a/code/Pbrt/PbrtExporter.cpp +++ b/code/Pbrt/PbrtExporter.cpp @@ -83,7 +83,16 @@ Other: #include #include +#if _MSC_VER // "unreferenced function has been removed" (SSE2 detection routine in x64 builds) +#pragma warning(push) +#pragma warning(disable : 4505) +#endif +#define STB_IMAGE_STATIC +#define STB_IMAGE_IMPLEMENTATION #include "stb/stb_image.h" +#if _MSC_VER +#pragma warning(pop) +#endif using namespace Assimp; From fa5a8476ee446b57a19910a55c82bc96d45d06f6 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 5 Apr 2022 19:04:29 +0200 Subject: [PATCH 02/12] Fix gcc warning: unused function --- code/Pbrt/PbrtExporter.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/code/Pbrt/PbrtExporter.cpp b/code/Pbrt/PbrtExporter.cpp index ea29860d3..c088e3851 100644 --- a/code/Pbrt/PbrtExporter.cpp +++ b/code/Pbrt/PbrtExporter.cpp @@ -86,12 +86,17 @@ Other: #if _MSC_VER // "unreferenced function has been removed" (SSE2 detection routine in x64 builds) #pragma warning(push) #pragma warning(disable : 4505) +#else +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-variable" #endif #define STB_IMAGE_STATIC #define STB_IMAGE_IMPLEMENTATION #include "stb/stb_image.h" #if _MSC_VER #pragma warning(pop) +#else +#pragma GCC diagnostic pop #endif using namespace Assimp; From 97c7ab3c05346664788ad33db3f552a171d29680 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 5 Apr 2022 19:53:41 +0200 Subject: [PATCH 03/12] Move stb_image header into its own header file. --- code/AssetLib/M3D/M3DWrapper.h | 6 ++-- code/CMakeLists.txt | 1 + code/Common/Assimp.cpp | 15 +-------- code/Common/StbCommon.h | 59 ++++++++++++++++++++++++++++++++++ code/Pbrt/PbrtExporter.cpp | 16 +-------- 5 files changed, 66 insertions(+), 31 deletions(-) create mode 100644 code/Common/StbCommon.h diff --git a/code/AssetLib/M3D/M3DWrapper.h b/code/AssetLib/M3D/M3DWrapper.h index fac63d099..00303153a 100644 --- a/code/AssetLib/M3D/M3DWrapper.h +++ b/code/AssetLib/M3D/M3DWrapper.h @@ -59,8 +59,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Share stb_image's PNG loader with other importers/exporters instead of bringing our own copy. #define STBI_ONLY_PNG -#define STB_IMAGE_STATIC -#include + +#if ASSIMP_NEEDS_STB_IMAGE +#include "Common/StbCommon.h" +#endif #include "m3d.h" diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 2eff6117f..f15087fe8 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -167,6 +167,7 @@ SET( Logging_SRCS SOURCE_GROUP(Logging FILES ${Logging_SRCS}) SET( Common_SRCS + Common/StbCommon.h Common/Compression.cpp Common/Compression.h Common/BaseImporter.cpp diff --git a/code/Common/Assimp.cpp b/code/Common/Assimp.cpp index bd3861f2e..9cd8f1560 100644 --- a/code/Common/Assimp.cpp +++ b/code/Common/Assimp.cpp @@ -1283,18 +1283,5 @@ ASSIMP_API void aiQuaternionInterpolate( #endif #if ASSIMP_NEEDS_STB_IMAGE - -# if _MSC_VER // "unreferenced function has been removed" (SSE2 detection routine in x64 builds) -# pragma warning(push) -# pragma warning(disable: 4505) -# endif - -# define STB_IMAGE_IMPLEMENTATION -# define STB_IMAGE_STATIC -# include "stb/stb_image.h" - -# if _MSC_VER -# pragma warning(pop) -# endif - +#include "Common/StbCommon.h" #endif diff --git a/code/Common/StbCommon.h b/code/Common/StbCommon.h new file mode 100644 index 000000000..47d5f1fbb --- /dev/null +++ b/code/Common/StbCommon.h @@ -0,0 +1,59 @@ +/* +Open Asset Import Library (assimp) +---------------------------------------------------------------------- + +Copyright (c) 2006-2022, assimp team + +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the +following conditions are met: + +* Redistributions of source code must retain the above +copyright notice, this list of conditions and the +following disclaimer. + +* Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the +following disclaimer in the documentation and/or other +materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its +contributors may be used to endorse or promote products +derived from this software without specific prior +written permission of the assimp team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +---------------------------------------------------------------------- +*/ +#pragma once + +#if _MSC_VER // "unreferenced function has been removed" (SSE2 detection routine in x64 builds) +#pragma warning(push) +#pragma warning(disable : 4505) +#else +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-variable" +#endif + +#define STB_IMAGE_STATIC +#define STB_IMAGE_IMPLEMENTATION +#include "stb/stb_image.h" + +#if _MSC_VER +#pragma warning(pop) +#else +#pragma GCC diagnostic pop +#endif diff --git a/code/Pbrt/PbrtExporter.cpp b/code/Pbrt/PbrtExporter.cpp index c088e3851..18ca7b595 100644 --- a/code/Pbrt/PbrtExporter.cpp +++ b/code/Pbrt/PbrtExporter.cpp @@ -83,21 +83,7 @@ Other: #include #include -#if _MSC_VER // "unreferenced function has been removed" (SSE2 detection routine in x64 builds) -#pragma warning(push) -#pragma warning(disable : 4505) -#else -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-variable" -#endif -#define STB_IMAGE_STATIC -#define STB_IMAGE_IMPLEMENTATION -#include "stb/stb_image.h" -#if _MSC_VER -#pragma warning(pop) -#else -#pragma GCC diagnostic pop -#endif +#include "Common/StbCommon.h" using namespace Assimp; From 5c438963c0aa6991fe88fb5f50f2381999d8f7ac Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 5 Apr 2022 19:59:36 +0200 Subject: [PATCH 04/12] Disable correct compiler-warning: unused-function. --- code/Common/StbCommon.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Common/StbCommon.h b/code/Common/StbCommon.h index 47d5f1fbb..94f8f32f0 100644 --- a/code/Common/StbCommon.h +++ b/code/Common/StbCommon.h @@ -45,7 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma warning(disable : 4505) #else #pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wunused-function" #endif #define STB_IMAGE_STATIC From 4e226354065545c5fe712564d5cbf80019574b0f Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 31 May 2022 18:31:19 +0200 Subject: [PATCH 05/12] Update PbrtExporter.cpp --- code/Pbrt/PbrtExporter.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/Pbrt/PbrtExporter.cpp b/code/Pbrt/PbrtExporter.cpp index 6a26d3261..fddee26a2 100644 --- a/code/Pbrt/PbrtExporter.cpp +++ b/code/Pbrt/PbrtExporter.cpp @@ -83,7 +83,9 @@ Other: #include #include +#if ASSIMP_NEEDS_STB_IMAGE #include "Common/StbCommon.h" +#endif using namespace Assimp; From b00923ebcd5d31d2d93ea6bbfbc7bdf351409f74 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 31 May 2022 19:08:29 +0200 Subject: [PATCH 06/12] Update Assimp.cpp --- code/Common/Assimp.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/code/Common/Assimp.cpp b/code/Common/Assimp.cpp index 9cd8f1560..528708792 100644 --- a/code/Common/Assimp.cpp +++ b/code/Common/Assimp.cpp @@ -5,8 +5,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2022, assimp team - - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -1283,5 +1281,6 @@ ASSIMP_API void aiQuaternionInterpolate( #endif #if ASSIMP_NEEDS_STB_IMAGE -#include "Common/StbCommon.h" +# define STB_IMAGE_IMPLEMENTATION +# include "Common/StbCommon.h" #endif From c0e141a6a981c1fd9d2301a7073a459249c084e8 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 31 May 2022 19:08:46 +0200 Subject: [PATCH 07/12] Update StbCommon.h --- code/Common/StbCommon.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/code/Common/StbCommon.h b/code/Common/StbCommon.h index 94f8f32f0..f2954f3ab 100644 --- a/code/Common/StbCommon.h +++ b/code/Common/StbCommon.h @@ -48,8 +48,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma GCC diagnostic ignored "-Wunused-function" #endif -#define STB_IMAGE_STATIC -#define STB_IMAGE_IMPLEMENTATION #include "stb/stb_image.h" #if _MSC_VER From 4b25eb6c4b9564eb3340e383551823a401950ae8 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 31 May 2022 19:09:22 +0200 Subject: [PATCH 08/12] Update Assimp.cpp --- code/Common/Assimp.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/Common/Assimp.cpp b/code/Common/Assimp.cpp index 528708792..4875cdac7 100644 --- a/code/Common/Assimp.cpp +++ b/code/Common/Assimp.cpp @@ -1280,7 +1280,9 @@ ASSIMP_API void aiQuaternionInterpolate( # define STBI_ONLY_PNG #endif +// Ensure all symbols are linked correctly #if ASSIMP_NEEDS_STB_IMAGE +# define STB_IMAGE_STATIC # define STB_IMAGE_IMPLEMENTATION # include "Common/StbCommon.h" #endif From e5cd85ac0c578555f243feb46289c0f952e5d3c3 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 31 May 2022 19:16:46 +0200 Subject: [PATCH 09/12] Update M3DWrapper.h --- code/AssetLib/M3D/M3DWrapper.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/code/AssetLib/M3D/M3DWrapper.h b/code/AssetLib/M3D/M3DWrapper.h index 00303153a..c75ff1027 100644 --- a/code/AssetLib/M3D/M3DWrapper.h +++ b/code/AssetLib/M3D/M3DWrapper.h @@ -57,12 +57,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Assimp specific M3D configuration. Comment out these defines to remove functionality //#define ASSIMP_USE_M3D_READFILECB -// Share stb_image's PNG loader with other importers/exporters instead of bringing our own copy. -#define STBI_ONLY_PNG - -#if ASSIMP_NEEDS_STB_IMAGE #include "Common/StbCommon.h" -#endif #include "m3d.h" From e28becbaf5ff19c4ff0a7487874c8ec8442c6a25 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 31 May 2022 19:17:08 +0200 Subject: [PATCH 10/12] Update Assimp.cpp --- code/Common/Assimp.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/Common/Assimp.cpp b/code/Common/Assimp.cpp index 4875cdac7..10cfe7902 100644 --- a/code/Common/Assimp.cpp +++ b/code/Common/Assimp.cpp @@ -1282,6 +1282,8 @@ ASSIMP_API void aiQuaternionInterpolate( // Ensure all symbols are linked correctly #if ASSIMP_NEEDS_STB_IMAGE + // Share stb_image's PNG loader with other importers/exporters instead of bringing our own copy. +# define STBI_ONLY_PNG # define STB_IMAGE_STATIC # define STB_IMAGE_IMPLEMENTATION # include "Common/StbCommon.h" From de4fe01c9448a78eb5078334ccb508e0eec5b137 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 31 May 2022 20:08:26 +0200 Subject: [PATCH 11/12] Fix clang build --- code/Common/StbCommon.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/Common/StbCommon.h b/code/Common/StbCommon.h index 47d5f1fbb..3e1fb5460 100644 --- a/code/Common/StbCommon.h +++ b/code/Common/StbCommon.h @@ -45,7 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma warning(disable : 4505) #else #pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wunused-function" #endif #define STB_IMAGE_STATIC @@ -57,3 +57,4 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #else #pragma GCC diagnostic pop #endif + From b7a70ac707cfabe73b18ec8219cb80fd3d201805 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 31 May 2022 23:24:31 +0200 Subject: [PATCH 12/12] Add compiler switgxh for using static linkage for std_image --- code/Common/Assimp.cpp | 4 +++- code/Pbrt/PbrtExporter.cpp | 2 -- test/unit/Main.cpp | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/code/Common/Assimp.cpp b/code/Common/Assimp.cpp index 10cfe7902..ee798238e 100644 --- a/code/Common/Assimp.cpp +++ b/code/Common/Assimp.cpp @@ -1284,7 +1284,9 @@ ASSIMP_API void aiQuaternionInterpolate( #if ASSIMP_NEEDS_STB_IMAGE // Share stb_image's PNG loader with other importers/exporters instead of bringing our own copy. # define STBI_ONLY_PNG -# define STB_IMAGE_STATIC +# ifdef ASSIMP_USE_STB_IMAGE_STATIC +# define STB_IMAGE_STATIC +# endif # define STB_IMAGE_IMPLEMENTATION # include "Common/StbCommon.h" #endif diff --git a/code/Pbrt/PbrtExporter.cpp b/code/Pbrt/PbrtExporter.cpp index fddee26a2..6a26d3261 100644 --- a/code/Pbrt/PbrtExporter.cpp +++ b/code/Pbrt/PbrtExporter.cpp @@ -83,9 +83,7 @@ Other: #include #include -#if ASSIMP_NEEDS_STB_IMAGE #include "Common/StbCommon.h" -#endif using namespace Assimp; diff --git a/test/unit/Main.cpp b/test/unit/Main.cpp index d5049faad..573c26a96 100644 --- a/test/unit/Main.cpp +++ b/test/unit/Main.cpp @@ -1,6 +1,5 @@ #include "../../include/assimp/DefaultLogger.hpp" #include "UnitTestPCH.h" - #include #include