From 22f11f42b856d8d0c60e7018e467642be4757a23 Mon Sep 17 00:00:00 2001 From: "J. Daniel Smith" Date: Mon, 20 Nov 2023 14:57:12 -0500 Subject: [PATCH] build as a DLL in Visual Studio (#603) * project changes to minimize changes when building a DLL * CODA_OSS -> NITRO_NITFCPP * build NITF-C++ as a DLL * Revert "build NITF-C++ as a DLL" This reverts commit 617449079da348d7f713e210b2d5e3d5ef5effd6. * more exports from CODA-OSS * link against CODA-OSS.DLL * Function uses '18832' bytes of stack. Consider moving some data to heap. This reverts commit 163e0eddd3c8f3f2152b6ba0447486473ea73649. * get ready to make NITF-C a DLL * fix errors when building as a DLL * need to export all of NRT too * more tweaks in preparation for building DLLs * export functions for unit-testing * build as DLLs in Visual Studio * NRT_DLL -> NITRO_NRT_DLL * remove CODA_OSS_DLL from VCXPROJ * trying to fix cmake build * Revert "trying to fix cmake build" This reverts commit 3caedb8c435aedd5477f39a01ca1b75528770ddb. * back to building LIBs for CMake/WAF * Build as DLLs (this branch only) * let the C-preprocessor know whether we're building SHARED or STATIC * WIP: fix imports and exports for VS * fix imports and exports for Visual Studio * Fix AdditionalLibraryDirectories --- UnitTest/UnitTest.vcxproj | 4 +-- UnitTest/pch.h | 3 ++ externals/coda-oss/cmake/CodaBuild.cmake | 4 +++ .../coda-oss/modules/c++/coda-oss.vcxproj | 8 ++--- .../c++/config/include/config/Exports.h | 31 ++++++++++++------- externals/coda-oss/modules/c++/pch.h | 3 ++ modules/c++/nitf-c++.vcxproj | 8 ++--- .../nitf/apps/show_nitf++/show_nitf++.vcxproj | 4 +-- modules/c++/nitf/include/nitf/exports.hpp | 31 ++++++++++++------- modules/c++/pch.h | 3 ++ modules/c/j2k/J2KCompress.vcxproj | 4 +-- modules/c/j2k/J2KDecompress.vcxproj | 4 +-- modules/c/nitf-c.vcxproj | 12 +++---- modules/c/nitf/TEST_DES.vcxproj | 10 +++--- modules/c/nrt/include/nrt/Defines.h | 10 +++--- modules/c/nrt/include/nrt/Exports.h | 31 ++++++++++++------- modules/c/pch.h | 3 ++ 17 files changed, 107 insertions(+), 66 deletions(-) diff --git a/UnitTest/UnitTest.vcxproj b/UnitTest/UnitTest.vcxproj index c488c71f1..547527c2a 100644 --- a/UnitTest/UnitTest.vcxproj +++ b/UnitTest/UnitTest.vcxproj @@ -58,7 +58,7 @@ Level4 true $(ProjectDir);$(SolutionDir)modules\c\nrt\include;$(SolutionDir)modules\c\nitf\include;$(SolutionDir)modules\c++\nitf\include;$(SolutionDir)modules\c\j2k\include;$(SolutionDir)modules\c;$(SolutionDir)modules\c++;$(SolutionDir)externals\coda-oss\modules\c++;$(SolutionDir)externals\coda-oss\out\install\$(Platform)-$(Configuration)\include;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) - _DEBUG;%(PreprocessorDefinitions) + _DEBUG;%(PreprocessorDefinitions);CODA_OSS_LIBRARY_SHARED=1 true pch.h AdvancedVectorExtensions2 @@ -84,7 +84,7 @@ true true $(ProjectDir);$(SolutionDir)modules\c\nrt\include;$(SolutionDir)modules\c\nitf\include;$(SolutionDir)modules\c++\nitf\include;$(SolutionDir)modules\c\j2k\include;$(SolutionDir)modules\c;$(SolutionDir)modules\c++;$(SolutionDir)externals\coda-oss\modules\c++;$(SolutionDir)externals\coda-oss\out\install\$(Platform)-$(Configuration)\include;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) - NDEBUG;%(PreprocessorDefinitions) + NDEBUG;%(PreprocessorDefinitions);CODA_OSS_LIBRARY_SHARED=1 true pch.h AdvancedVectorExtensions2 diff --git a/UnitTest/pch.h b/UnitTest/pch.h index 24ccf55db..86707841a 100644 --- a/UnitTest/pch.h +++ b/UnitTest/pch.h @@ -20,6 +20,9 @@ // We're building in Visual Studio ... used to control where we get a little bit of config info #define NITRO_PCH 1 +#ifndef CODA_OSS_LIBRARY_SHARED +#define CODA_OSS_LIBRARY_SHARED 1 +#endif #include #include diff --git a/externals/coda-oss/cmake/CodaBuild.cmake b/externals/coda-oss/cmake/CodaBuild.cmake index 142773788..5ac3ed962 100644 --- a/externals/coda-oss/cmake/CodaBuild.cmake +++ b/externals/coda-oss/cmake/CodaBuild.cmake @@ -128,8 +128,12 @@ macro(coda_initialize_build) option(BUILD_SHARED_LIBS "Build shared libraries instead of static." OFF) if(BUILD_SHARED_LIBS) set(CODA_LIBRARY_TYPE "shared") + add_definitions(-DCODA_OSS_LIBRARY_SHARED=1) + add_definitions(-UCODA_OSS_LIBRARY_STATIC) else() set(CODA_LIBRARY_TYPE "static") + add_definitions(-DCODA_OSS_LIBRARY_STATIC=1) + add_definitions(-UCODA_OSS_LIBRARY_SHARED) endif() option(CODA_BUILD_TESTS "build tests" ON) diff --git a/externals/coda-oss/modules/c++/coda-oss.vcxproj b/externals/coda-oss/modules/c++/coda-oss.vcxproj index c500dcd82..7278051f6 100644 --- a/externals/coda-oss/modules/c++/coda-oss.vcxproj +++ b/externals/coda-oss/modules/c++/coda-oss.vcxproj @@ -531,12 +531,12 @@ - StaticLibrary + DynamicLibrary true v143 - StaticLibrary + DynamicLibrary false v143 true @@ -566,7 +566,7 @@ Level4 true - _DEBUG;%(PreprocessorDefinitions);MT_DEFAULT_PINNING=0;RE_ENABLE_STD_REGEX=1 + _DEBUG;%(PreprocessorDefinitions);MT_DEFAULT_PINNING=0;RE_ENABLE_STD_REGEX=1;CODA_OSS_EXPORTS;CODA_OSS_LIBRARY_SHARED=1 pch.h cli\include;coda_oss\include;config\include;dbi\include;except\include;gsl\include;hdf5.lite\include;io\include;logging\include;math\include;math.linear\include;math.poly\include;mem\include;mt\include;net\include;net.ssl\include;plugin\include;polygon\include;re\include;sio.lite\include;std\include;str\include;sys\include;tiff\include;types\include;unique\include;units\include;xml.lite\include;zip\include;$(ProjectDir)include;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include;$(SolutionDir)externals\$(ProjectName)\out\install\$(Platform)-$(Configuration)\include Use @@ -596,7 +596,7 @@ true true true - NDEBUG;%(PreprocessorDefinitions);MT_DEFAULT_PINNING=0;RE_ENABLE_STD_REGEX=1 + NDEBUG;%(PreprocessorDefinitions);MT_DEFAULT_PINNING=0;RE_ENABLE_STD_REGEX=1;CODA_OSS_EXPORTS;CODA_OSS_LIBRARY_SHARED=1 pch.h cli\include;coda_oss\include;config\include;dbi\include;except\include;gsl\include;hdf5.lite\include;io\include;logging\include;math\include;math.linear\include;math.poly\include;mem\include;mt\include;net\include;net.ssl\include;plugin\include;polygon\include;re\include;sio.lite\include;std\include;str\include;sys\include;tiff\include;types\include;unique\include;units\include;xml.lite\include;zip\include;$(ProjectDir)include;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include;$(SolutionDir)externals\$(ProjectName)\out\install\$(Platform)-$(Configuration)\include Use diff --git a/externals/coda-oss/modules/c++/config/include/config/Exports.h b/externals/coda-oss/modules/c++/config/include/config/Exports.h index 50ea06c85..71949e7c7 100644 --- a/externals/coda-oss/modules/c++/config/include/config/Exports.h +++ b/externals/coda-oss/modules/c++/config/include/config/Exports.h @@ -2,22 +2,29 @@ #include "config/compiler_extensions.h" -// Need to specify how this code will be consumed, either CODA_OSS_LIB (static library) -// or CODA_OSS_DLL (aka "shared" library). For DLLs, it needs to be set for BOTH +// Need to specify how this code will be consumed, either CODA_OSS_LIB_ (static library) +// or CODA_OSS_DLL_ (aka "shared" library). For DLLs, it needs to be set for BOTH // "exporting" (building this code) and "importing" (consuming). // // Use Windows naming conventions (DLL, LIB) because this really only matters for _MSC_VER, see below. -#if !defined(CODA_OSS_LIB) && !defined(CODA_OSS_DLL) - //#define CODA_OSS_DLL 1 // Symbols must be exported and imported (see below). - #define CODA_OSS_LIB 1 // Static library, all symbols visible. +#if !defined(CODA_OSS_LIB_) && !defined(CODA_OSS_DLL_) + #if CODA_OSS_LIBRARY_SHARED + #if CODA_OSS_LIBRARY_STATIC + #error "CODA_OSS_LIBRARY_SHARED already #define'd'" + #endif + #define CODA_OSS_DLL_ 1 // Symbols must be exported and imported (see below). + #else + // CODA_OSS_LIBRARY_STATIC doesn't have to be defined + #define CODA_OSS_LIB_ 1 // Static library, all symbols visible. + #endif #endif -#if !defined(CODA_OSS_LIB) && !defined(CODA_OSS_DLL) - #error "One of CODA_OSS_LIB pr CODA_OSS_DLL must be #define'd'" +#if !defined(CODA_OSS_LIB_) && !defined(CODA_OSS_DLL_) + #error "One of CODA_OSS_LIB_ pr CODA_OSS_DLL_ must be #define'd'" #endif -#if defined(CODA_OSS_LIB) && defined(CODA_OSS_DLL) - #error "Both CODA_OSS_LIB and CODA_OSS_DLL are #define'd'" +#if defined(CODA_OSS_LIB_) && defined(CODA_OSS_DLL_) + #error "Both CODA_OSS_LIB_ and CODA_OSS_DLL_ are #define'd'" #endif -#if defined(CODA_OSS_EXPORTS) && defined(CODA_OSS_LIB) +#if defined(CODA_OSS_EXPORTS) && defined(CODA_OSS_LIB_) #error "Can't export from a LIB'" #endif @@ -36,10 +43,10 @@ // We need to know whether we're consuming (importing) a DLL or static LIB // The default is a static LIB as that's what existing code/builds expect. - #ifdef CODA_OSS_DLL + #ifdef CODA_OSS_DLL_ // Actually, it seems that the linker is able to figure this out from the .LIB, so // there doesn't seem to be a need for __declspec(dllimport). Clients don't - // need to #define CODA_OSS_DLL ... ? Well, almost ... it looks + // need to #define CODA_OSS_DLL_ ... ? Well, almost ... it looks // like __declspec(dllimport) is needed to get virtual "inline"s (e.g., // destructors) correct. #define CODA_OSS_API CODA_OSS_library_import diff --git a/externals/coda-oss/modules/c++/pch.h b/externals/coda-oss/modules/c++/pch.h index 664d700de..5cda65986 100644 --- a/externals/coda-oss/modules/c++/pch.h +++ b/externals/coda-oss/modules/c++/pch.h @@ -9,6 +9,9 @@ // We're building in Visual Studio ... used to control where we get a little bit // of config info #define CODA_OSS_PCH 1 +#ifndef CODA_OSS_LIBRARY_SHARED +#define CODA_OSS_LIBRARY_SHARED 1 +#endif #include "coda_oss/CPlusPlus.h" #include "config/disable_compiler_warnings.h" diff --git a/modules/c++/nitf-c++.vcxproj b/modules/c++/nitf-c++.vcxproj index ab90809a3..730f30fae 100644 --- a/modules/c++/nitf-c++.vcxproj +++ b/modules/c++/nitf-c++.vcxproj @@ -188,11 +188,11 @@ - StaticLibrary + DynamicLibrary v143 - StaticLibrary + DynamicLibrary v143 true @@ -219,7 +219,7 @@ Level4 true - _DEBUG;%(PreprocessorDefinitions); + _DEBUG;%(PreprocessorDefinitions);;NITRO_NITFCPP_EXPORTS;CODA_OSS_LIBRARY_SHARED=1 true $(ProjectDir)nitf\include;$(ProjectDir)..\c\nrt\include;$(ProjectDir)..\c\nitf\include;$(ProjectDir)..\c\j2k\include;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include;$(SolutionDir)externals\coda-oss\out\install\$(Platform)-$(Configuration)\include Use @@ -253,7 +253,7 @@ true true true - NDEBUG;%(PreprocessorDefinitions); + NDEBUG;%(PreprocessorDefinitions);;NITRO_NITFCPP_EXPORTS;CODA_OSS_LIBRARY_SHARED=1 true $(ProjectDir)nitf\include;$(ProjectDir)..\c\nrt\include;$(ProjectDir)..\c\nitf\include;$(ProjectDir)..\c\j2k\include;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include;$(SolutionDir)externals\coda-oss\out\install\$(Platform)-$(Configuration)\include Use diff --git a/modules/c++/nitf/apps/show_nitf++/show_nitf++.vcxproj b/modules/c++/nitf/apps/show_nitf++/show_nitf++.vcxproj index 17cc8f186..503ebe7f5 100644 --- a/modules/c++/nitf/apps/show_nitf++/show_nitf++.vcxproj +++ b/modules/c++/nitf/apps/show_nitf++/show_nitf++.vcxproj @@ -49,7 +49,7 @@ Level4 true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + _DEBUG;_CONSOLE;%(PreprocessorDefinitions);CODA_OSS_LIBRARY_SHARED=1 true $(SolutionDir)modules\c\nrt\include;$(SolutionDir)modules\c\nitf\include;$(SolutionDir)modules\c\jpeg\include;$(SolutionDir)modules\c\j2k\include;$(SolutionDir)modules\c\cgm\include;$(SolutionDir)modules\c;$(SolutionDir)modules\c++;$(SolutionDir)modules\c++\nitf\include;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include;$(SolutionDir)externals\coda-oss\out\install\$(Platform)-$(Configuration)\include Use @@ -78,7 +78,7 @@ true true true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + NDEBUG;_CONSOLE;%(PreprocessorDefinitions);CODA_OSS_LIBRARY_SHARED=1 true $(SolutionDir)modules\c\nrt\include;$(SolutionDir)modules\c\nitf\include;$(SolutionDir)modules\c\jpeg\include;$(SolutionDir)modules\c\j2k\include;$(SolutionDir)modules\c\cgm\include;$(SolutionDir)modules\c;$(SolutionDir)modules\c++;$(SolutionDir)modules\c++\nitf\include;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include;$(SolutionDir)externals\coda-oss\out\install\$(Platform)-$(Configuration)\include Use diff --git a/modules/c++/nitf/include/nitf/exports.hpp b/modules/c++/nitf/include/nitf/exports.hpp index 54e22b906..7d3b61f8f 100644 --- a/modules/c++/nitf/include/nitf/exports.hpp +++ b/modules/c++/nitf/include/nitf/exports.hpp @@ -2,22 +2,29 @@ #include "config/compiler_extensions.h" -// Need to specify how this code will be consumed, either NITRO_NITFCPP_LIB (static library) -// or NITRO_NITFCPP_DLL (aka "shared" library). For DLLs, it needs to be set for BOTH +// Need to specify how this code will be consumed, either NITRO_NITFCPP_LIB_ (static library) +// or NITRO_NITFCPP_DLL_ (aka "shared" library). For DLLs, it needs to be set for BOTH // "exporting" (building this code) and "importing" (consuming). // // Use Windows naming conventions (DLL, LIB) because this really only matters for _MSC_VER, see below. -#if !defined(NITRO_NITFCPP_LIB) && !defined(NITRO_NITFCPP_DLL) - //#define NITRO_NITFCPP_DLL 1 // Symbols must be exported and imported (see below). - #define NITRO_NITFCPP_LIB 1 // Static library, all symbols visible. +#if !defined(NITRO_NITFCPP_LIB_) && !defined(NITRO_NITFCPP_DLL_) + #if CODA_OSS_LIBRARY_SHARED + #if CODA_OSS_LIBRARY_STATIC + #error "CODA_OSS_LIBRARY_SHARED already #define'd'" + #endif + #define NITRO_NITFCPP_DLL_ 1 // Symbols must be exported and imported (see below). + #else + // CODA_OSS_LIBRARY_STATIC doesn't have to be defined + #define NITRO_NITFCPP_LIB_ 1 // Static library, all symbols visible. + #endif #endif -#if !defined(NITRO_NITFCPP_LIB) && !defined(NITRO_NITFCPP_DLL) - #error "One of NITRO_NITFCPP_LIB pr NITRO_NITFCPP_DLL must be #define'd'" +#if !defined(NITRO_NITFCPP_LIB_) && !defined(NITRO_NITFCPP_DLL_) + #error "One of NITRO_NITFCPP_LIB_ pr NITRO_NITFCPP_DLL_ must be #define'd'" #endif -#if defined(NITRO_NITFCPP_LIB) && defined(NITRO_NITFCPP_DLL) - #error "Both NITRO_NITFCPP_LIB and NITRO_NITFCPP_DLL are #define'd'" +#if defined(NITRO_NITFCPP_LIB_) && defined(NITRO_NITFCPP_DLL_) + #error "Both NITRO_NITFCPP_LIB_ and NITRO_NITFCPP_DLL_ are #define'd'" #endif -#if defined(NITRO_NITFCPP_EXPORTS) && defined(NITRO_NITFCPP_LIB) +#if defined(NITRO_NITFCPP_EXPORTS) && defined(NITRO_NITFCPP_LIB_) #error "Can't export from a LIB'" #endif @@ -36,10 +43,10 @@ // We need to know whether we're consuming (importing) a DLL or static LIB // The default is a static LIB as that's what existing code/builds expect. - #ifdef NITRO_NITFCPP_DLL + #ifdef NITRO_NITFCPP_DLL_ // Actually, it seems that the linker is able to figure this out from the .LIB, so // there doesn't seem to be a need for __declspec(dllimport). Clients don't - // need to #define NITRO_NITFCPP_DLL ... ? Well, almost ... it looks + // need to #define NITRO_NITFCPP_DLL_ ... ? Well, almost ... it looks // like __declspec(dllimport) is needed to get virtual "inline"s (e.g., destructors) correct. #define NITRO_NITFCPP_API CODA_OSS_library_import #else diff --git a/modules/c++/pch.h b/modules/c++/pch.h index 00108586f..5598704d5 100644 --- a/modules/c++/pch.h +++ b/modules/c++/pch.h @@ -51,6 +51,9 @@ CODA_OSS_disable_warning_pop // We're building in Visual Studio ... used to control where we get a little bit of config info #define NITRO_PCH 1 +#ifndef CODA_OSS_LIBRARY_SHARED +#define CODA_OSS_LIBRARY_SHARED 1 +#endif // Yes, these are our files ... but they don't change very often, and if they do // change we want to rebuild everything anyway. diff --git a/modules/c/j2k/J2KCompress.vcxproj b/modules/c/j2k/J2KCompress.vcxproj index 021fcb706..7a6a02369 100644 --- a/modules/c/j2k/J2KCompress.vcxproj +++ b/modules/c/j2k/J2KCompress.vcxproj @@ -64,7 +64,7 @@ Level4 true - _DEBUG;_LIB;%(PreprocessorDefinitions);NRT_MODULE_EXPORTS;NITRO_PCH;HAVE_J2K_H + _DEBUG;_LIB;%(PreprocessorDefinitions);NITRO_NRT_EXPORTS;NITRO_PCH;HAVE_J2K_H;CODA_OSS_LIBRARY_SHARED=1 true $(ProjectDir)include;$(ProjectDir)..\nrt\include;$(ProjectDir)..\nitf\include;%(AdditionalIncludeDirectories) /FS %(AdditionalOptions) @@ -91,7 +91,7 @@ true true true - NDEBUG;_LIB;%(PreprocessorDefinitions);NRT_MODULE_EXPORTS;NITRO_PCH;HAVE_J2K_H + NDEBUG;_LIB;%(PreprocessorDefinitions);NITRO_NRT_EXPORTS;NITRO_PCH;HAVE_J2K_H;CODA_OSS_LIBRARY_SHARED=1 true $(ProjectDir)include;$(ProjectDir)..\nrt\include;$(ProjectDir)..\nitf\include;%(AdditionalIncludeDirectories) /FS %(AdditionalOptions) diff --git a/modules/c/j2k/J2KDecompress.vcxproj b/modules/c/j2k/J2KDecompress.vcxproj index 366e0b421..3fc0690be 100644 --- a/modules/c/j2k/J2KDecompress.vcxproj +++ b/modules/c/j2k/J2KDecompress.vcxproj @@ -64,7 +64,7 @@ Level4 true - _DEBUG;_LIB;%(PreprocessorDefinitions);NRT_MODULE_EXPORTS;NITRO_PCH;HAVE_J2K_H + _DEBUG;_LIB;%(PreprocessorDefinitions);NITRO_NRT_EXPORTS;NITRO_PCH;HAVE_J2K_H;CODA_OSS_LIBRARY_SHARED=1 true $(ProjectDir)include;$(ProjectDir)..\nrt\include;$(ProjectDir)..\nitf\include;%(AdditionalIncludeDirectories) /FS %(AdditionalOptions) @@ -91,7 +91,7 @@ true true true - NDEBUG;_LIB;%(PreprocessorDefinitions);NRT_MODULE_EXPORTS;NITRO_PCH;HAVE_J2K_H + NDEBUG;_LIB;%(PreprocessorDefinitions);NITRO_NRT_EXPORTS;NITRO_PCH;HAVE_J2K_H;CODA_OSS_LIBRARY_SHARED=1 true $(ProjectDir)include;$(ProjectDir)..\nrt\include;$(ProjectDir)..\nitf\include;%(AdditionalIncludeDirectories) /FS %(AdditionalOptions) diff --git a/modules/c/nitf-c.vcxproj b/modules/c/nitf-c.vcxproj index 0195fdf5f..78b0a8b31 100644 --- a/modules/c/nitf-c.vcxproj +++ b/modules/c/nitf-c.vcxproj @@ -20,11 +20,11 @@ - StaticLibrary + DynamicLibrary v143 - StaticLibrary + DynamicLibrary v143 true @@ -50,7 +50,7 @@ Level4 true - _DEBUG;%(PreprocessorDefinitions);HAVE_OPENJPEG_H + _DEBUG;%(PreprocessorDefinitions);HAVE_OPENJPEG_H;NITRO_NRT_EXPORTS;CODA_OSS_LIBRARY_SHARED=1 true $(ProjectDir)nrt\include;$(ProjectDir)nitf\include;$(ProjectDir)jpeg\include;$(ProjectDir)j2k\include;$(ProjectDir)cgm\include;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include;$(SolutionDir)externals\coda-oss\out\install\$(Platform)-$(Configuration)\include;%(AdditionalIncludeDirectories) Use @@ -74,7 +74,7 @@ true - $(SolutionDir)externals\coda-oss\out\install\$(Platform)-$(Configuration)\lib\ + $(SolutionDir)out\install\$(Platform)-$(Configuration)\lib\;$(SolutionDir)externals\coda-oss\out\install\$(Platform)-$(Configuration)\lib\ @@ -82,7 +82,7 @@ true true true - NDEBUG;%(PreprocessorDefinitions);HAVE_OPENJPEG_H + NDEBUG;%(PreprocessorDefinitions);HAVE_OPENJPEG_H;NITRO_NRT_EXPORTS;CODA_OSS_LIBRARY_SHARED=1 true $(ProjectDir)nrt\include;$(ProjectDir)nitf\include;$(ProjectDir)jpeg\include;$(ProjectDir)j2k\include;$(ProjectDir)cgm\include;$(SolutionDir)out\install\$(Platform)-$(Configuration)\include;$(SolutionDir)externals\coda-oss\out\install\$(Platform)-$(Configuration)\include;%(AdditionalIncludeDirectories) Use @@ -104,7 +104,7 @@ true true true - $(SolutionDir)externals\coda-oss\out\install\$(Platform)-$(Configuration)\lib\ + $(SolutionDir)out\install\$(Platform)-$(Configuration)\lib\;$(SolutionDir)externals\coda-oss\out\install\$(Platform)-$(Configuration)\lib\ diff --git a/modules/c/nitf/TEST_DES.vcxproj b/modules/c/nitf/TEST_DES.vcxproj index 5f4c1ef73..1457b9fd3 100644 --- a/modules/c/nitf/TEST_DES.vcxproj +++ b/modules/c/nitf/TEST_DES.vcxproj @@ -64,7 +64,7 @@ Level4 true - _DEBUG;_LIB;%(PreprocessorDefinitions);NRT_MODULE_EXPORTS;NITRO_PCH + _DEBUG;_LIB;%(PreprocessorDefinitions);NRT_MODULE_EXPORTS;NITRO_PCH;CODA_OSS_LIBRARY_SHARED=1 true $(ProjectDir)include;$(ProjectDir)..\nrt\include;%(AdditionalIncludeDirectories) /FS %(AdditionalOptions) @@ -81,7 +81,8 @@ true - $(SolutionDir)out\install\$(Platform)-$(Configuration)\lib\;$(SolutionDir)externals\coda-oss\out\install\$(Platform)-$(Configuration)\lib\;$(SolutionDir)\target-$(Configuration)\installwindows-latestCMake-Github\lib\ + + @@ -90,7 +91,7 @@ true true true - NDEBUG;_LIB;%(PreprocessorDefinitions);NRT_MODULE_EXPORTS;NITRO_PCH + NDEBUG;_LIB;%(PreprocessorDefinitions);NRT_MODULE_EXPORTS;NITRO_PCH;CODA_OSS_LIBRARY_SHARED=1 true $(ProjectDir)include;$(ProjectDir)..\nrt\include;%(AdditionalIncludeDirectories) /FS %(AdditionalOptions) @@ -106,7 +107,8 @@ true true true - $(SolutionDir)out\install\$(Platform)-$(Configuration)\lib\;$(SolutionDir)externals\coda-oss\out\install\$(Platform)-$(Configuration)\lib\;$(SolutionDir)\target-$(Configuration)\installwindows-latestCMake-Github\lib\ + + diff --git a/modules/c/nrt/include/nrt/Defines.h b/modules/c/nrt/include/nrt/Defines.h index ae969fdf7..7c0fea965 100644 --- a/modules/c/nrt/include/nrt/Defines.h +++ b/modules/c/nrt/include/nrt/Defines.h @@ -76,14 +76,16 @@ #define NRT_SNPRINTF snprintf #define NRT_VSNPRINTF vsnprintf -// Export no matter what ... when you KNOW you're building a DLL/SO, e.g. a TRE +// Export no matter what ... when you KNOW you're building a DLL/SO, e.g. a plugin #define NRTEXPORT(RT) NRT_C NITRO_NRT_library_export RT // extern "C" __declspec(dllexport) void* foo(); // Adjust the above ... but w/o chaning too much :-( -#if defined(NITRO_NRT_DLL) // See Exports.h - #ifdef NRTAPI - #undef NRTAPI +#if defined(NRTAPI) && defined(CODA_OSS_LIBRARY_SHARED) + #undef NRTAPI + #ifdef NITRO_NRT_EXPORTS // See Exports.h #define NRTAPI(RT) NRTEXPORT(RT) + #else + #define NRTAPI(RT) NRT_C NITRO_NRT_library_import RT // extern "C" __declspec(dllimport) void* foo(); #endif #endif diff --git a/modules/c/nrt/include/nrt/Exports.h b/modules/c/nrt/include/nrt/Exports.h index e701de0c7..da4a07d5c 100644 --- a/modules/c/nrt/include/nrt/Exports.h +++ b/modules/c/nrt/include/nrt/Exports.h @@ -23,22 +23,29 @@ #pragma once -// Need to specify how this code will be consumed, either NITRO_NRT_LIB (static library) -// or NITRO_NRT_DLL (aka "shared" library). For DLLs, it needs to be set for BOTH +// Need to specify how this code will be consumed, either NITRO_NRT_LIB_ (static library) +// or NITRO_NRT_DLL_ (aka "shared" library). For DLLs, it needs to be set for BOTH // "exporting" (building this code) and "importing" (consuming). // // Use Windows naming conventions (DLL, LIB) because this really only matters for _MSC_VER, see below. -#if !defined(NITRO_NRT_LIB) && !defined(NITRO_NRT_DLL) - //#define NITRO_NRT_DLL 1 // Symbols must be exported and imported (see below). - #define NITRO_NRT_LIB 1 // Static library, all symbols visible. +#if !defined(NITRO_NRT_LIB_) && !defined(NITRO_NRT_DLL_) + #if CODA_OSS_LIBRARY_SHARED + #if CODA_OSS_LIBRARY_STATIC + #error "CODA_OSS_LIBRARY_SHARED already #define'd'" + #endif + #define NITRO_NRT_DLL_ 1 // Symbols must be exported and imported (see below). + #else + // CODA_OSS_LIBRARY_STATIC doesn't have to be defined + #define NITRO_NRT_LIB_ 1 // Static library, all symbols visible. + #endif #endif -#if !defined(NITRO_NRT_LIB) && !defined(NITRO_NRT_DLL) - #error "One of NITRO_NRT_LIB pr NITRO_NRT_DLL must be #define'd'" +#if !defined(NITRO_NRT_LIB_) && !defined(NITRO_NRT_DLL_) + #error "One of NITRO_NRT_LIB_ pr NITRO_NRT_DLL_ must be #define'd'" #endif -#if defined(NITRO_NRT_LIB) && defined(NITRO_NRT_DLL) - #error "Both NITRO_NRT_LIB and NITRO_NRT_DLL are #define'd'" +#if defined(NITRO_NRT_LIB_) && defined(NITRO_NRT_DLL_) + #error "Both NITRO_NRT_LIB_ and NITRO_NRT_DLL_ are #define'd'" #endif -#if defined(NITRO_NRT_EXPORTS) && defined(NITRO_NRT_LIB) +#if defined(NITRO_NRT_EXPORTS) && defined(NITRO_NRT_LIB_) #error "Can't export from a LIB'" #endif @@ -83,10 +90,10 @@ // We need to know whether we're consuming (importing) a DLL or static LIB // The default is a static LIB as that's what existing code/builds expect. - #ifdef NITRO_NRT_DLL + #ifdef NITRO_NRT_DLL_ // Actually, it seems that the linker is able to figure this out from the .LIB, so // there doesn't seem to be a need for __declspec(dllimport). Clients don't - // need to #define NITRO_NRT_DLL ... ? Well, almost ... it looks + // need to #define NITRO_NRT_DLL_ ... ? Well, almost ... it looks // like __declspec(dllimport) is needed to get virtual "inline"s (e.g., // destructors) correct. #define NITRO_NRT_API NITRO_NRT_library_import diff --git a/modules/c/pch.h b/modules/c/pch.h index e4397b81c..04f052c4f 100644 --- a/modules/c/pch.h +++ b/modules/c/pch.h @@ -2,6 +2,9 @@ // We're building in Visual Studio ... used to control where we get a little bit of config info #define NITRO_PCH 1 +#ifndef CODA_OSS_LIBRARY_SHARED +#define CODA_OSS_LIBRARY_SHARED 1 +#endif // TODO: get rid of these someday? ... from Visual Studio code-analysis #pragma warning(disable: 6385) // Reading invalid data from '...': the readable size is '...' bytes, but '...' bytes may be read.