From bee64608d25f87cc24a1ced9715d2af10daee6b2 Mon Sep 17 00:00:00 2001 From: Scott Minster Date: Wed, 26 Sep 2018 15:12:59 -0500 Subject: [PATCH 1/3] Added CSM_LIBRARY define for Windows, added more Windows specific build instructions --- Makefile.win32 | 2 ++ PointCloudGM.cpp | 3 +++ PointCloudIsd.cpp | 2 ++ README | 3 +++ csmPointCloud.cpp | 3 +++ 5 files changed, 13 insertions(+) diff --git a/Makefile.win32 b/Makefile.win32 index 6ef3557..05c288b 100644 --- a/Makefile.win32 +++ b/Makefile.win32 @@ -11,6 +11,8 @@ LIBRARY=$(LIBNAME).dll INSTDIR=$(PWD)/win32 +# warning -- this target does not work because it ends up running the linker command from Makefile +# instead make 'csmapi.dll' all: $(LIBRARY) %.o: %.cpp diff --git a/PointCloudGM.cpp b/PointCloudGM.cpp index 9cfbf41..8a130a0 100644 --- a/PointCloudGM.cpp +++ b/PointCloudGM.cpp @@ -25,11 +25,14 @@ // getValidModelBounds function. // 22-Feb-2018 JPK Replaced macros for inclusion in a single // library. Reformatted for readability +// 26-Sep-2018 SCM Added define of CSM_LIBRARY for Windows. // // NOTES: // //############################################################################# +#define CSM_LIBRARY + #include #include "PointCloudGM.h" diff --git a/PointCloudIsd.cpp b/PointCloudIsd.cpp index e991b4c..0c22e95 100644 --- a/PointCloudIsd.cpp +++ b/PointCloudIsd.cpp @@ -15,11 +15,13 @@ // Date Author Comment // ----------- ------ ------- // 20-Mar-2013 SCM Initial Coding +// 26-Sep-2018 SCM Added define of CSM_LIBRARY for Windows. // // NOTES: // //############################################################################# +#define CSM_LIBRARY #include "PointCloudIsd.h" csm::Vlr::~Vlr() {} diff --git a/README b/README index 493d8ef..411cc69 100644 --- a/README +++ b/README @@ -12,3 +12,6 @@ By default, the built files are placed in an architecture subdirectory in the bu Compiling makes a 'csmapi' shared library (libcsmapi.so.3.0.3 on UNIX, csmapi.dll on Windows). This library must be used when creating both CSM plugins and Sensor Exploitation Tools (SETs) that use CSM. +When compiling on Windows, the "all" target does not do the right thing. Instead build with: + + make -f Makefile.win32 csmapi.dll install clean diff --git a/csmPointCloud.cpp b/csmPointCloud.cpp index 3053bd0..72f4271 100644 --- a/csmPointCloud.cpp +++ b/csmPointCloud.cpp @@ -21,10 +21,13 @@ // 22FEB2018 JPK Modified to use existing csm macros (since // point cloud is no longer in a separate library). // Other minor cleanup for consistency of code. +// 26-Sep-2018 SCM Added define of CSM_LIBRARY for Windows. +// // NOTES: // //############################################################################# +#define CSM_LIBRARY #include "csmPointCloud.h" #include "Error.h" #include From 25736d2bd5cc2ac6e64df28101f35e65b9bb9e9d Mon Sep 17 00:00:00 2001 From: Scott Minster Date: Mon, 29 Oct 2018 13:11:18 -0500 Subject: [PATCH 2/3] Added win32 compilation scripts --- Makefile.win32 | 6 +- README | 5 +- scripts/mscc | 65 +++++++++++++++++++++ scripts/mslink | 120 ++++++++++++++++++++++++++++++++++++++ scripts/objects_to_def | 127 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 319 insertions(+), 4 deletions(-) create mode 100755 scripts/mscc create mode 100755 scripts/mslink create mode 100755 scripts/objects_to_def diff --git a/Makefile.win32 b/Makefile.win32 index 05c288b..7277704 100644 --- a/Makefile.win32 +++ b/Makefile.win32 @@ -1,7 +1,7 @@ include Makefile -CC=mscc -LD=mslink +CC=./scripts/mscc +LD=./scripts/mslink CDEBUGFLAGS=-O2 COPTS=/nologo $(CDEBUGFLAGS) /Zm800 /MD /GR /W1 /EHa $(DEFINES) DEFINES=-D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_DEPRECATE @@ -22,7 +22,7 @@ all: $(LIBRARY) $(CC) -c $(COPTS) $< -Fo$@ $(LIBRARY): $(OBJS) - objects_to_def -dir . -proj $(@:%.dll=%) > $(@:%.dll=%.ldf) + ./scripts/objects_to_def -dir . -proj $(@:%.dll=%) > $(@:%.dll=%.ldf) $(LD) $(COPTS) $(LDOPTS) /DEF:$(@:%.dll=%.ldf) -o $@ $^ install:: diff --git a/README b/README index 411cc69..d469671 100644 --- a/README +++ b/README @@ -12,6 +12,9 @@ By default, the built files are placed in an architecture subdirectory in the bu Compiling makes a 'csmapi' shared library (libcsmapi.so.3.0.3 on UNIX, csmapi.dll on Windows). This library must be used when creating both CSM plugins and Sensor Exploitation Tools (SETs) that use CSM. -When compiling on Windows, the "all" target does not do the right thing. Instead build with: + +Windows +------- +Windows compliation requires the use of Cygwin to provide tools like 'make' and 'perl'. You should also be sure that Microsoft's Visual C++'s "cl.exe" is in your $PATH and that $INCLUDE and $LIB are set appropriately. When compiling on Windows, the "all" target does not do the right thing. Instead build with: make -f Makefile.win32 csmapi.dll install clean diff --git a/scripts/mscc b/scripts/mscc new file mode 100755 index 0000000..e77c62c --- /dev/null +++ b/scripts/mscc @@ -0,0 +1,65 @@ +#!/bin/sh +eval 'exec perl -x $0 ${1+"$@"}' + if 0; # [Construct to start `perl' when we do not know where it is.] +#!perl +############################################################################### +# FILE: mscc +# +# CLASSIFICATION: Unclassified +# +# DESCRIPTION: This is a wrapper script that mutates a Unix +# compile command into the MS Studio equivalent +# +# LIMITATIONS: Requires Cgywin's "cygpath" application to convert paths +# +############################################################################### + +my $debug = 0; + +# *** +# Convert optimization argument to mscc expected format +# Convert paths to Windows format +# *** +my $compile_debug = grep(/^-g$/, @ARGV); + +my @compile_args = (); +foreach (@ARGV) +{ + if ($compile_debug) + { + s/^\-O[0-9]/\/Od/; + } + else + { + s/^\-O/\/O/; + } + + if (/^\-I(.+)/) + { + chomp(my $winPath = `cygpath -w "$1"`); + $_ = "\/I$winPath"; + } + if (/^\-Fo(.+)/) + { + chomp(my $winPath = `cygpath -w "$1"`); + $_ = "-Fo$winPath"; + } + + if ($_ eq "-g") + { + push @compile_args, '/Yd'; + push @compile_args, '/Z7'; + $_ = ''; + } + + push @compile_args, $_ if ($_); +} + +# Build the compile command +$compile="cl.exe"; + +warn ">>> compile_args are {" . join(', ', @compile_args) . "}\n" if ($debug); + +# Execute the compile command +print "$compile " . join(' ', @compile_args) . "\n"; +exec $compile, @compile_args or die "Could not exec: $!\n"; diff --git a/scripts/mslink b/scripts/mslink new file mode 100755 index 0000000..62276e9 --- /dev/null +++ b/scripts/mslink @@ -0,0 +1,120 @@ +#!/bin/sh +eval 'exec perl -x $0 ${1+"$@"}' + if 0; # [Construct to start `perl' when we do not know where it is.] +#!perl +############################################################################### +# FILE: mslink +# +# CLASSIFICATION: Unclassified +# +# DESCRIPTION: This is a wrapper script that mutates a Unix +# link command into the MS Studio equivalent +# +# LIMITATIONS: None +# +############################################################################### + +$debug = 0; + +# *** +# Get the command line arguments. Unix needs the -I, -D and -O options +# so templates can be compiled at link time. Since Windows compiles +# templates at compile time, they need to be removed. Unix uses -l and +# -L options for specifying library names and library paths. These need +# to be replaced with the MS equivalent, DEFAULTLIB and LIBPATH. Replace +# the debug flag with /DEBUG. +# *** + +my @link_args; +my @mt_args; +$runmt = 0; + +$nextIsOutput = 0; +foreach (@ARGV) +{ + if ($_ eq "-o") + { + $nextIsOutput = 1; + next; + } + + if ($_ eq "-nomt") + { + $runmt = "dont!"; + next; + } + + if ($nextIsOutput) + { + if (/\.(exe|dll)$/ && !$runmt) + { + $runmt = "$_.manifest"; + if (/\.exe$/) + { + push @mt_args, "-outputresource:$_"; + } + elsif (/\.dll$/) + { + push @mt_args, "-outputresource:$_\\;2"; + } + push @mt_args, "-manifest"; + push @mt_args, "$_.manifest"; + push @mt_args, "/nologo"; + } + + $_ = "/OUT:$_"; + $nextIsOutput = 0; + } + + if (/^(-L|\/DEF:|\/OUT:)(\/\S+)/) + { + chomp(my $winPath = `cygpath -w "$2"`); + $_ = "$1$winPath"; + } + + # clear these arguments + s/^-(I|D|O).*//; + s/^\/(O[0-9]|Zm800|MD|GR|W1|TP|GX|EHa|fp:fast|D_.*)//; + + s|^-l(.*)|/DEFAULTLIB:$1|; + s|^-L(.*)|/LIBPATH:$1|; + s|^-g|/DEBUG|; + + push @link_args, $_ if ($_); +} + +# *** +# including BINMODE.OBJ in the link causes +# O_BINARY to be the default instead of O_TEXT +# *** +push @link_args, 'BINMODE.OBJ'; + +warn ">>> link_args arg {" . join(', ', @link_args) . "}\n" if ($debug); + +# Build the link command +$link = "link.exe"; + +# Execute the link command +print "$link " . join(' ', @link_args) . "\n"; +(system($link, @link_args) == 0) or die "Could not link!\n"; + + +if ($runmt && -e $runmt) +{ + # Build and execute the mt command + $mt = "mt.exe " . join(' ', @mt_args); + my $MAX_MT_TRIES = 5; + my $tries = 0; + while ($tries < $MAX_MT_TRIES) + { + if ($tries > 0) + { + print "mt failed, sleeping then trying again\n"; + sleep 1; + } + print "$mt\n"; + last if (system($mt) == 0); + $tries++; + } + die "Could not mt!\n" if ($tries >= $MAX_MT_TRIES); +} diff --git a/scripts/objects_to_def b/scripts/objects_to_def new file mode 100755 index 0000000..a7cb1e0 --- /dev/null +++ b/scripts/objects_to_def @@ -0,0 +1,127 @@ +#!/bin/sh -- +eval 'exec perl -x $0 ${1+"$@"}' # [Runs `perl' from `PATH'.] +#!perl +############################################################################## +# +# FILE: objects_to_def +# +# CLASSIFICATION: Unclassified +# +# DESCRIPTION: Generate a script to convert a library objects +# directory (libhxxx.objects) to a dynamic link object +# library definition file (libhxxx.def). +# +# Usage: objects_to_def libhxxx.objects > libhxxx.def +# OR objects_to_def -d -p > .def +# +# LIMITATIONS: This script is only needed to generate definition +# files for the creation of Win32 dlls. Requires 'nm' from +# cygwin to work properly. +# +############################################################################## + +# *** +# Check command line arguments +# *** +use File::Basename; +$program = basename($0); + +$ARGV = @ARGV; +$usage = "Usage: $program + NOTE: must be in the format libhxxx.def where \"xxx\" is + the name of the library. + +-OR- + +Usage: $program -dir -proj + + -dir - Directory containing the objects to convert. + -proj - Name of the project. + +Synopsis: + Convert a library objects directory to a dynamic link object library + definition file. +"; + + +# *** +# Get command line args +# *** +while ($#ARGV >= 0) { + $_ = shift; + if (/^-/ && !$end_of_options) { + if (/^--$/) { $end_of_options = 1; } + # These must match exactly: + elsif ("-debug" eq $_) { $debug = 1; } + # These may be abbreviated: + elsif (&match("-d|ir")) { die "$usage\n" unless !$dir_name && ($arg = shift); $dir_name=$arg; } + elsif (&match("-p|roj")) { die "$usage\n" unless !$lib_name && ($arg = shift); $lib_name=$arg; } + # Anything leftover: + else { push(@options, $_); } + } + else + { + die "$usage\n" unless !$dir_name; + $dir_name = $_; + } +} + +die "$usage\n" unless $dir_name && (@options==0); + +($lib_name) = $dir_name=~/lib(.+).objects/ unless $lib_name; + +# *** +# Verify objects directory exists +# *** +-d $dir_name || die "$0: $dir_name not found \n"; + +# *** +# Generate DEF header +# *** + +print "LIBRARY $lib_name\n\n"; +print "EXPORTS\n\n"; + +# *** +# Work inside object directory so expanded list of object files does not +# include the full path on each object, which could make the "nm" command line +# excessively long. +# *** +chdir $dir_name; + +@object_files = glob("*.o *.obj"); + +$command = "nm -e @object_files"; +warn ">>> Running: $command\n" if $debug; +open(NMPROC,"$command|") || die "$0:Unable to start nm process: $!\n"; + +# List external symbols, pass through text and global data ones that are mangled (have "@" in them) +# and C-style symbols with their leading underscore removed. +while() +{ + chomp; + my ($addr, $symType, $symName) = split(/ /, $_); + + if ($symType && $symType =~ /[TBDRC]/) + { + if ($symName && $symName =~ /@/ && + !($symName =~ /^\?\?_G.*@@UAEPAXI@Z/ || $symName =~ /^\?\?_E.*@@UAEPAXI@Z/)) + { + print "$symName\n"; + } + elsif ($symName && $symName =~ /^_/) + { + print substr($symName, 1) . "\n"; + } + } +} +close(NMPROC); + +######################################## +# Subroutine to check $_ for a possibly abbreviated option. TEMPLATE is may +# contain a `|', indicating all following characters are optional. Returns +# true on valid match. +sub match { + local($required,$optional) = split(/\|/, $_[0]); + return /^$required/ && "$required$optional" =~ /^$_/; +} From d08343dbd60a5b5a2b8934a7ba0bfb1a98542391 Mon Sep 17 00:00:00 2001 From: Scott Minster Date: Thu, 29 Nov 2018 07:35:55 -0500 Subject: [PATCH 3/3] Added MultiNitfIsd class --- Makefile | 4 +-- MultiNitfIsd.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++ MultiNitfIsd.h | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 MultiNitfIsd.cpp create mode 100644 MultiNitfIsd.h diff --git a/Makefile b/Makefile index 709ca76..de9f7cc 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ -HEADERS = csm.h Error.h Warning.h Version.h Isd.h BytestreamIsd.h NitfIsd.h Plugin.h Model.h GeometricModel.h RasterGM.h CorrelationModel.h FourParameterCorrelationModel.h LinearDecayCorrelationModel.h csmPointCloud.h PointCloudIsd.h PointCloudGM.h ModelIdentifier.h BundleGM.h Ellipsoid.h SettableEllipsoid.h +HEADERS = csm.h Error.h Warning.h Version.h Isd.h BytestreamIsd.h NitfIsd.h MultiNitfIsd.h Plugin.h Model.h GeometricModel.h RasterGM.h CorrelationModel.h FourParameterCorrelationModel.h LinearDecayCorrelationModel.h csmPointCloud.h PointCloudIsd.h PointCloudGM.h ModelIdentifier.h BundleGM.h Ellipsoid.h SettableEllipsoid.h -OBJS = Version.o Isd.o Plugin.o GeometricModel.o RasterGM.o CorrelationModel.o FourParameterCorrelationModel.o LinearDecayCorrelationModel.o csmPointCloud.o PointCloudIsd.o PointCloudGM.o ModelIdentifier.o BundleGM.o Ellipsoid.o SettableEllipsoid.o +OBJS = Version.o Isd.o Plugin.o GeometricModel.o RasterGM.o CorrelationModel.o FourParameterCorrelationModel.o LinearDecayCorrelationModel.o csmPointCloud.o PointCloudIsd.o PointCloudGM.o ModelIdentifier.o BundleGM.o Ellipsoid.o SettableEllipsoid.o MultiNitfIsd.o LIBNAME=libcsmapi diff --git a/MultiNitfIsd.cpp b/MultiNitfIsd.cpp new file mode 100644 index 0000000..caaaa84 --- /dev/null +++ b/MultiNitfIsd.cpp @@ -0,0 +1,79 @@ +//############################################################################# +// +// FILENAME: MultiNitfIsd.cpp +// +// CLASSIFICATION: Unclassified +// +// DESCRIPTION: +// +// This file contains the implementations for the functions defined in CSM. +// +// LIMITATIONS: None +// +// SOFTWARE HISTORY: +// Date Author Comment +// ----------- ------ ------- +// 28-NOV-2018 JPK Initial Version. +// 29-NOV-2018 SCM Cleanup formatting and added include of Error.h. +// +// NOTES: +// +//############################################################################# + +#ifndef CSM_LIBRARY +#define CSM_LIBRARY +#endif + +#include "MultiNitfIsd.h" +#include "Error.h" + +namespace csm +{ + +//***************************************************************************** +// MultiNitfIsd::MultiNitfIsd +//***************************************************************************** +MultiNitfIsd::MultiNitfIsd(const std::vector& isdList) + : + Isd("MULTINITF", ""), + theISDs(isdList) +{ +} + +//***************************************************************************** +// MultiNitfIsd::addIsd +//***************************************************************************** +void MultiNitfIsd::addIsd(const csm::NitfIsd &isd) +{ + theISDs.push_back(isd); +} + +//***************************************************************************** +// MultiNitfIsd::isdList +//***************************************************************************** +const std::vector& MultiNitfIsd::isdList() const +{ + return theISDs; +} + +//***************************************************************************** +// MultiNitfIsd::isdList +//***************************************************************************** +std::vector& MultiNitfIsd::isdList() +{ + return theISDs; +} + +//***************************************************************************** +// MultiNitfIsd::isd +//***************************************************************************** +const csm::NitfIsd& MultiNitfIsd::isd(std::size_t index) const +{ + if (index < theISDs.size()) return theISDs[index]; + + throw Error(Error::INDEX_OUT_OF_RANGE, + "ISD Index is out of range.", + "csm::MultiNitfIsd::isd"); +} + +} //namespace csm diff --git a/MultiNitfIsd.h b/MultiNitfIsd.h new file mode 100644 index 0000000..29f2ba0 --- /dev/null +++ b/MultiNitfIsd.h @@ -0,0 +1,88 @@ +//############################################################################# +// +// FILENAME: MultiNitfIsd.h +// +// CLASSIFICATION: Unclassified +// +// DESCRIPTION: +// +// Header for the MultiNitfIsd base class. MultiNitfIsd is encapsulated in a +// C++ class for transfer through the CSM (Plugin) interface. MultiNitfIsd +// holds a vector of csm::NitfIsds +// +// LIMITATIONS: None +// +// SOFTWARE HISTORY: +// +// Date Author Comment +// ----------- ------ ------- +// 28-NOV-2018 JPK Initial Version. +// 29-NOV-2018 SCM Cleanup formatting. Use std::size_t for size. +// +// NOTES: +// +//############################################################################# + +#ifndef __CSM_MULTINITFISD_H +#define __CSM_MULTINITFISD_H + +#include +#include + +#include "csm.h" +#include "NitfIsd.h" + +namespace csm +{ + +class CSM_EXPORT_API MultiNitfIsd : public Isd +{ +public: + MultiNitfIsd() : Isd("MULTINITF", ""), theISDs() {} + //> This constructor makes an empty image support data list. + //< + + explicit MultiNitfIsd(const std::vector& isdList); + //> This constructor stores one or more image support data objects. + //< + + const std::string& format() const { return theFormat; } + //> This method returns the format of the image support data (MULTINITF). + //< + + void addIsd(const csm::NitfIsd& isd); + //> This method adds a csm::NitfIsd to the MultiNitfIsd. + //< + + const std::vector& isdList() const; + //> This method allows const retrieval of the entire + // vector of available csm::NitfIsd objects. + //< + + std::vector& isdList(); + //> This method allows non-const retrieval of the + // vector of available csm::NitfIsd objects, allowing the + // vector to be modified (added to / deleted from). + //< + + void clearAllIsds() { theISDs.clear(); } + //> This method removes all the ISDs added to the vector. + //< + + std::size_t numberOfIsds() const {return theISDs.size();} + //> This method returns the number of available ISDs owned + // by this class. + //< + + const csm::NitfIsd& isd(std::size_t index) const; + //> This method returns the csm::NitfIsd at the specified + // index. + //< + +protected: + std::vector theISDs; +}; + +} // namespace csm + +#endif