Skip to content

Commit

Permalink
improve print out of CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
ptahmose committed Oct 30, 2023
1 parent 3011476 commit 19d5645
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 7 deletions.
61 changes: 59 additions & 2 deletions Src/CZICmd/cmdlineoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ CCmdLineOptions::ParseResult CCmdLineOptions::Parse(int argc, char** argv)
string argument_generatorpixeltype;
bool argument_versionflag = false;
string argument_source_stream_class;
string argument_source_stream_creation_propbag;

// editorconfig-checker-disable
cli_app.add_option("-c,--command", argument_command,
Expand Down Expand Up @@ -580,6 +581,9 @@ CCmdLineOptions::ParseResult CCmdLineOptions::Parse(int argc, char** argv)
cli_app.add_option("--source-stream-class", argument_source_stream_class,
"Specifies the stream-class used for reading the source CZI-file. If not specified, the default file-reader stream-class is used.")
->option_text("STREAMCLASS");
cli_app.add_option("--source-stream-creation-propbag", argument_source_stream_creation_propbag,
"Specifies the property-bag used for creating the stream used for reading the source CZI-file. The data is given in JSON-notation.")
->option_text("PROPBAG");
cli_app.add_option("-o,--output", argument_output_filename,
"specifies the output-filename. A suffix will be appended to the name given here depending on the type of the file.")
->option_text("OUTPUTFILE");
Expand Down Expand Up @@ -741,14 +745,20 @@ CCmdLineOptions::ParseResult CCmdLineOptions::Parse(int argc, char** argv)

try
{
if (!argument_source_filename.empty())
{
this->cziFilename = convertUtf8ToUCS2(argument_source_filename);
}

if (!argument_source_stream_class.empty())
{
this->source_stream_class = argument_source_stream_class;
}

if (!argument_source_filename.empty())
if (!argument_source_stream_creation_propbag.empty())
{
this->cziFilename = convertUtf8ToUCS2(argument_source_filename);
const bool b = TryParseInputStreamCreationPropertyBag(argument_source_stream_creation_propbag, &this->property_bag_for_stream_class);
// TODO ThrowIfFalse(b, "-r,--rect", argument_rect);
}

if (!argument_output_filename.empty())
Expand Down Expand Up @@ -2162,3 +2172,50 @@ void CCmdLineOptions::PrintHelpStreamsObjects()

return false;
}

/*static*/bool CCmdLineOptions::TryParseInputStreamCreationPropertyBag(const std::string& s, std::map<int, libCZI::StreamsFactory::Property>* property_bag)
{
std::map<int, libCZI::StreamsFactory::Property> map;
rapidjson::Document document;
document.Parse(s.c_str());
if (document.HasParseError() || !document.IsObject())
{
return false;
}

for (rapidjson::Value::ConstMemberIterator itr = document.MemberBegin(); itr != document.MemberEnd(); ++itr)
{
if (!itr->name.IsString())
{
return false;
}

string name = itr->name.GetString();
libCZI::StreamsFactory::Property property;
if (itr->value.IsString())
{
property = libCZI::StreamsFactory::Property(itr->value.GetString());
}
else if (itr->value.IsDouble())
{
property = libCZI::StreamsFactory::Property(itr->value.GetDouble());
}
else if (itr->value.IsBool())
{
property = libCZI::StreamsFactory::Property(itr->value.GetBool());
}
else
{
return false;
}

// map[libCZI::StreamsFactory::GetStreamPropertyId(name)] = property;
}

if (property_bag != nullptr)
{
property_bag->swap(map);
}

return true;
}
4 changes: 3 additions & 1 deletion Src/CZICmd/cmdlineoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class CCmdLineOptions
Command command;
std::wstring cziFilename;
std::string source_stream_class;
std::map<int, libCZI::StreamsFactory::Property> property_bag_for_stream_class;
libCZI::CDimCoordinate planeCoordinate;

bool rectModeAbsoluteOrRelative; // true->absolute, false->relative
Expand Down Expand Up @@ -215,7 +216,7 @@ class CCmdLineOptions
std::shared_ptr<ILog> GetLog() const { return this->log; }
Command GetCommand() const { return this->command; }
const std::wstring& GetCZIFilename() const { return this->cziFilename; }
const std::string& GetInputStreamClassName() const{ return this->source_stream_class; }
const std::string& GetInputStreamClassName() const { return this->source_stream_class; }
const libCZI::CDimCoordinate& GetPlaneCoordinate() const { return this->planeCoordinate; }
const std::map<int, ChannelDisplaySettings>& GetMultiChannelCompositeChannelInfos() const { return this->multiChannelCompositeChannelInfos; }
bool GetUseDisplaySettingsFromDocument() const { return this->useDisplaySettingsFromDocument; }
Expand Down Expand Up @@ -304,6 +305,7 @@ class CCmdLineOptions
static bool TryParseSubBlockMetadataKeyValue(const std::string& s, std::map<std::string, std::string>* subblock_metadata_property_bag);
static bool TryParseCompressionOptions(const std::string& s, libCZI::Utils::CompressionOption* compression_option);
static bool TryParseGeneratorPixeltype(const std::string& s, libCZI::PixelType* pixel_type);
static bool TryParseInputStreamCreationPropertyBag(const std::string& s, std::map<int, libCZI::StreamsFactory::Property>* property_bag);

static void ThrowIfFalse(bool b, const std::string& argument_switch, const std::string& argument);
};
22 changes: 18 additions & 4 deletions Src/JxrDecode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
include(CheckSymbolExists)
include(CheckCSourceCompiles)

function(BoolToYesNo var result_text)
if (${var})
set( ${result_text} "yes" PARENT_SCOPE)
else()
set( ${result_text} "no" PARENT_SCOPE)
endif()
endfunction()

add_library(JxrDecodeStatic OBJECT
"JxrDecode.h"
"JxrDecode.cpp"
Expand Down Expand Up @@ -69,12 +77,16 @@ check_c_source_compiles(
"#include <byteswap.h>
int main() {__builtin_bswap32(0x12345678);}"
jxrdecode_Has_builtin_bswap32)
message("jxrdecode_Has_builtin_bswap32 = ${jxrdecode_Has_builtin_bswap32}.")
BoolToYesNo(jxrdecode_Has_builtin_bswap32 jxrdecode_result_text)
message("jxrdecode_Has_builtin_bswap32 = ${jxrdecode_result_text}.")
if (NOT jxrdecode_Has_builtin_bswap32)
check_symbol_exists(_byteswap_ulong "stdlib.h" jxrdecode_Has_byteswap_long_in_stdlib)
message("jxrdecode_Has_byteswap_long_in_stdlib = ${jxrdecode_Has_byteswap_long_in_stdlib}.")
BoolToYesNo(jxrdecode_Has_byteswap_long_in_stdlib jxrdecode_result_text)
message("jxrdecode_Has_byteswap_long_in_stdlib = ${jxrdecode_result_text}.")
if (NOT jxrdecode_Has_byteswap_long_in_stdlib)
check_symbol_exists(bswap32 "sys/endian.h" jxrdecode_Has_bswap_long_in_sys_endian)
BoolToYesNo(jxrdecode_Has_bswap_long_in_sys_endian jxrdecode_result_text)
message("jxrdecode_Has_bswap_long_in_sys_endian = ${jxrdecode_result_text}.")
endif()
endif()

Expand All @@ -91,14 +103,16 @@ endif()
# Here we check for the _rotl() function - c.f. https://stackoverflow.com/questions/776508/best-practices-for-circular-shift-rotate-operations-in-c
# With MSVC, it is found in <intrin.h>, with gcc it is expected to be found in <x86intrin.h>.
check_symbol_exists(_rotl "intrin.h" jxrdecode_Has_rotl_with_intrin)
message("jxrdecode_Has_rotl_with_intrin = ${jxrdecode_Has_rotl_with_intrin}.")
BoolToYesNo(jxrdecode_Has_rotl_with_intrin jxrdecode_result_text)
message("jxrdecode_Has_rotl_with_intrin = ${jxrdecode_result_text}.")
if (NOT jxrdecode_Has_rotl_with_intrin)
set (jxrdecode_Has_rotl_with_intrin 0)
endif()

if (NOT jxrdecode_Has_rotl_with_intrin )
check_symbol_exists(_rotl "x86intrin.h" jxrdecode_Has_rotl_with_x86intrin)
message("jxrdecode_Has_rotl_with_x86intrin= ${jxrdecode_Has_rotl_with_x86intrin}.")
BoolToYesNo(jxrdecode_Has_rotl_with_x86intrin jxrdecode_result_text)
message("jxrdecode_Has_rotl_with_x86intrin= ${jxrdecode_result_text}.")
endif()
if (NOT jxrdecode_Has_rotl_with_x86intrin)
set (jxrdecode_Has_rotl_with_x86intrin 0)
Expand Down

0 comments on commit 19d5645

Please sign in to comment.