Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions Build/Cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ option(ENABLE_WXWIDGETS "Build wxProfileDump GUI tool (requires wxWidg
option(ENABLE_SHARED_LIBS "Build dynamic link libraries" ON)
option(ENABLE_STATIC_LIBS "Build static libraries" ON)
option(ENABLE_ICCXML "Build IccXML library support" ON)
option(ENABLE_ICCJSON "Build IccJSON library support" ON)
option(ICC_TRACE_NAN_ENABLED "Enable tracing NaN inputs in debug builds" OFF)
option(ICC_CLUT_DEBUG "Enable CLUT debugging support" OFF)
option(ICC_ENABLE_ASSERTS "Enable ICC_ASSERT traps and debug assertions" OFF)
Expand Down Expand Up @@ -1155,6 +1156,29 @@ ENDIF()
# NOTE: IccXML and generated-header includes now propagated via
# target_include_directories(PUBLIC) on IccProfLib2 and IccXML2 targets

# Ensure generated version headers are available globally
include_directories(${CMAKE_CURRENT_BINARY_DIR}/IccProfLib)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/IccXML)

#
# JSON library (parallel to IccXML, uses nlohmann/json)
#
IF(ENABLE_ICCJSON)
message(STATUS "Adding subdirectory for IccJSON.")
add_subdirectory(IccJSON)

# Set default link target for IccJSON (matches build configuration)
IF(ENABLE_SHARED_LIBS)
set(TARGET_LIB_ICCJSON IccJSON2 CACHE INTERNAL "Link target for IccJSON2")
ELSE()
set(TARGET_LIB_ICCJSON IccJSON2-static CACHE INTERNAL "Link target for IccJSON2")
ENDIF()

# Ensure IccJSON headers are available globally
include_directories(${TOP_SOURCE_DIR}/IccJSON/IccLibJSON/)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/IccJSON)
ENDIF(ENABLE_ICCJSON)

# Diagnostic: Output current linker flags
if(VERBOSE_CONFIG)
message(STATUS "CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}")
Expand Down Expand Up @@ -1200,6 +1224,15 @@ IF(ENABLE_TOOLS)
# Add XML-related tools
ADD_SUBDIRECTORY(Tools/IccFromXml)
ADD_SUBDIRECTORY(Tools/IccToXml)

# Add JSON-related tools
IF(ENABLE_ICCJSON AND TARGET_LIB_ICCJSON)
message(STATUS "Adding Subdirectory IccFromJson.")
ADD_SUBDIRECTORY(Tools/IccFromJson)
message(STATUS "Adding Subdirectory IccToJson.")
ADD_SUBDIRECTORY(Tools/IccToJson)
ENDIF()
message(STATUS "Adding Subdirectory IccJpegDump.")
ADD_SUBDIRECTORY(Tools/IccJpegDump)
ADD_SUBDIRECTORY(Tools/IccApplyNamedCmm)
ADD_SUBDIRECTORY(Tools/IccDumpProfile)
Expand All @@ -1217,10 +1250,26 @@ IF(ENABLE_TOOLS)
ADD_DEPENDENCIES(iccToXml ${TARGET_LIB_ICCXML})
ENDIF()

# Ensure IccJSON-dependent tools are built after IccJSON library (safety net)
IF(ENABLE_ICCJSON)
IF(TARGET iccFromJson AND TARGET ${TARGET_LIB_ICCJSON})
ADD_DEPENDENCIES(iccFromJson ${TARGET_LIB_ICCJSON})
ENDIF()
IF(TARGET iccToJson AND TARGET ${TARGET_LIB_ICCJSON})
ADD_DEPENDENCIES(iccToJson ${TARGET_LIB_ICCJSON})
ENDIF()
ENDIF()


# PNG already found above; just add the tool
if(NOT PNG_FOUND)
message(FATAL_ERROR "PNG not found. Please install libpng-dev or install via vcpkg.")
# --- PNG (already found above) ---
message(STATUS "Checking for PNG...")

if(PNG_FOUND)
message(STATUS "PNG Library : ${PNG_LIBRARIES}")
message(STATUS "PNG Include Directory : ${PNG_INCLUDE_DIRS}")
message(STATUS "PNG Version : ${PNG_VERSION}")
else()
message(FATAL_ERROR " PNG not found. Please install libpng-dev or install via vcpkg.")
endif()
if(VERBOSE_CONFIG)
message(STATUS "Adding Subdirectory IccPngDump.")
Expand Down
141 changes: 141 additions & 0 deletions Build/Cmake/IccJSON/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#################################################################################
# IccJSON CMake Project Configuration | iccMAX Project
# Copyright (C) 2024-2026 The International Color Consortium.
# All rights reserved.
#
# Parallel implementation to IccXML using nlohmann/json (JSON for Modern C++).
#
#################################################################################

SET( TARGET_NAME IccJSON2 )

SET( SRC_PATH ../../.. )
SET( CFILES
${SRC_PATH}/IccJSON/IccLibJSON/IccIoJson.cpp
${SRC_PATH}/IccJSON/IccLibJSON/IccMpeJson.cpp
${SRC_PATH}/IccJSON/IccLibJSON/IccMpeJsonFactory.cpp
${SRC_PATH}/IccJSON/IccLibJSON/IccProfileJson.cpp
${SRC_PATH}/IccJSON/IccLibJSON/IccTagJson.cpp
${SRC_PATH}/IccJSON/IccLibJSON/IccTagJsonFactory.cpp
${SRC_PATH}/IccJSON/IccLibJSON/IccUtilJson.cpp
)

IF(ENABLE_INSTALL_RIM)
SET( HEADERS_PUBLIC
${SRC_PATH}/IccJSON/IccLibJSON/IccIoJson.h
${SRC_PATH}/IccJSON/IccLibJSON/IccJsonConfig.h
${SRC_PATH}/IccJSON/IccLibJSON/IccMpeJson.h
${SRC_PATH}/IccJSON/IccLibJSON/IccMpeJsonFactory.h
${SRC_PATH}/IccJSON/IccLibJSON/IccProfileJson.h
${SRC_PATH}/IccJSON/IccLibJSON/IccTagJson.h
${SRC_PATH}/IccJSON/IccLibJSON/IccTagJsonFactory.h
${SRC_PATH}/IccJSON/IccLibJSON/IccUtilJson.h
)
INSTALL( FILES
${HEADERS_PUBLIC}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${TARGET_INCLUDE_FOLDER}/${TARGET_NAME} )
ENDIF(ENABLE_INSTALL_RIM)

# Generate version header with git commit hash (reuses the project version string)
if(GIT_COMMIT_HASH)
set(ICCLIBXML_VERSION_STRING "${${PROJECT_UP_NAME}_VERSION}+${GIT_COMMIT_HASH}")
else()
set(ICCLIBXML_VERSION_STRING "${${PROJECT_UP_NAME}_VERSION}")
endif()

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/../../../IccJSON/IccLibJSON/IccLibJSONVer.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/IccLibJSONVer.h"
@ONLY
)

include_directories("${CMAKE_CURRENT_BINARY_DIR}")

SET(SOURCES ${CFILES})

IF(APPLE)
INCLUDE_DIRECTORIES(/Developer/Headers/FlatCarbon)
FIND_LIBRARY(CARBON_LIBRARY Carbon)
FIND_LIBRARY(IOKIT_LIBRARY IOKit)
MARK_AS_ADVANCED(CARBON_LIBRARY)
MARK_AS_ADVANCED(IOKIT_LIBRARY)
SET(EXTRA_LIBS_CS ${CARBON_LIBRARY} ${IOKIT_LIBRARY})
ENDIF()

# IccJSON has no IccXML dependency – all utilities are in IccProfLib

IF(ENABLE_SHARED_LIBS)
ADD_LIBRARY(${TARGET_NAME} SHARED ${SOURCES})
set_target_properties(${TARGET_NAME}
PROPERTIES
VERSION "${${PROJECT_UP_NAME}_VERSION}"
SOVERSION "${${PROJECT_UP_NAME}_MAJOR_VERSION}"
)

if(WIN32)
set_target_properties(${TARGET_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()

target_compile_features(${TARGET_NAME} PUBLIC cxx_std_17)

target_include_directories(${TARGET_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../../IccJSON/IccLibJSON>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../..>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${TARGET_INCLUDE_FOLDER}/${TARGET_NAME}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

TARGET_LINK_LIBRARIES(${TARGET_NAME} PUBLIC ${TARGET_LIB_ICCPROFLIB} nlohmann_json::nlohmann_json ${EXTRA_LIBS} ${EXTRA_LIBS_CS})

IF(ENABLE_INSTALL_RIM)
INSTALL(TARGETS ${TARGET_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
ENDIF()
ENDIF()

IF(ENABLE_STATIC_LIBS)
ADD_LIBRARY(${TARGET_NAME}-static STATIC ${SOURCES})
SET_TARGET_PROPERTIES(${TARGET_NAME}-static PROPERTIES OUTPUT_NAME "${TARGET_NAME}-static")
target_compile_features(${TARGET_NAME}-static PUBLIC cxx_std_17)

target_include_directories(${TARGET_NAME}-static PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../../IccJSON/IccLibJSON>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../..>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${TARGET_INCLUDE_FOLDER}/${TARGET_NAME}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

TARGET_LINK_LIBRARIES(${TARGET_NAME}-static PUBLIC ${TARGET_LIB_ICCPROFLIB} nlohmann_json::nlohmann_json ${EXTRA_LIBS} ${EXTRA_LIBS_CS})

IF(ENABLE_INSTALL_RIM)
INSTALL(TARGETS ${TARGET_NAME}-static
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
ENDIF()

IF(WIN32 AND ENABLE_SHARED_LIBS)
ADD_CUSTOM_COMMAND(TARGET ${TARGET_NAME}-static POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:${TARGET_NAME}-static>"
"$<TARGET_FILE_DIR:${TARGET_NAME}-static>/${TARGET_NAME}.lib"
COMMENT "Aliasing ${TARGET_NAME}-static.lib to ${TARGET_NAME}.lib for MSVC compatibility")
ENDIF()

IF(NOT ENABLE_SHARED_LIBS)
ADD_LIBRARY(${TARGET_NAME} ALIAS ${TARGET_NAME}-static)
ENDIF()
ENDIF()

# Resolve linking target for parent scope
IF(ENABLE_SHARED_LIBS)
SET(TARGET_LIB ${TARGET_NAME})
ELSE()
SET(TARGET_LIB ${TARGET_NAME}-static)
ENDIF()

SET(TARGET_LIB ${TARGET_LIB} PARENT_SCOPE)
26 changes: 26 additions & 0 deletions Build/Cmake/Tools/IccFromJson/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#################################################################################
# iccFromJson CMake Configuration | iccDEV Project
# Copyright (C) 2024-2026 The International Color Consortium.
# All rights reserved.
#
# Converts a JSON ICC profile to a binary ICC profile file.
#################################################################################

SET( SRC_PATH ../../../.. )
SET( SOURCES ${SRC_PATH}/IccJSON/CmdLine/IccFromJson/IccFromJson.cpp )
SET( TARGET_NAME iccFromJson )

ADD_EXECUTABLE( ${TARGET_NAME} ${SOURCES} )

# Ensure IccJSON2 is built before linking
IF(ENABLE_SHARED_LIBS)
ADD_DEPENDENCIES( ${TARGET_NAME} IccJSON2 )
ELSE()
ADD_DEPENDENCIES( ${TARGET_NAME} IccJSON2-static )
ENDIF()

TARGET_LINK_LIBRARIES( ${TARGET_NAME} ${TARGET_LIB_ICCJSON} )

IF(ENABLE_INSTALL_RIM)
INSTALL (TARGETS ${TARGET_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
ENDIF(ENABLE_INSTALL_RIM)
26 changes: 26 additions & 0 deletions Build/Cmake/Tools/IccToJson/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#################################################################################
# iccToJson CMake Configuration | iccDEV Project
# Copyright (C) 2024-2026 The International Color Consortium.
# All rights reserved.
#
# Converts a binary ICC profile to a JSON file.
#################################################################################

SET( SRC_PATH ../../../.. )
SET( SOURCES ${SRC_PATH}/IccJSON/CmdLine/IccToJson/IccToJson.cpp )
SET( TARGET_NAME iccToJson )

ADD_EXECUTABLE( ${TARGET_NAME} ${SOURCES} )

# Ensure IccJSON2 is built before linking
IF(ENABLE_SHARED_LIBS)
ADD_DEPENDENCIES( ${TARGET_NAME} IccJSON2 )
ELSE()
ADD_DEPENDENCIES( ${TARGET_NAME} IccJSON2-static )
ENDIF()

TARGET_LINK_LIBRARIES( ${TARGET_NAME} ${TARGET_LIB_ICCJSON} )

IF(ENABLE_INSTALL_RIM)
INSTALL (TARGETS ${TARGET_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
ENDIF(ENABLE_INSTALL_RIM)
74 changes: 74 additions & 0 deletions IccJSON/CmdLine/IccFromJson/IccFromJson.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// IccFromJson.cpp : Convert a JSON ICC profile to a binary ICC profile file.
//

#include <cstdio>
#include "IccTagJsonFactory.h"
#include "IccMpeJsonFactory.h"
#include "IccProfileJson.h"
#include "IccIO.h"
#include "IccUtil.h"
#include "IccProfLibVer.h"
#include "IccLibJSONVer.h"
#include <cstring>

int main(int argc, char* argv[])
{
if (argc <= 2) {
printf("IccFromJson built with IccProfLib Version " ICCPROFLIBVER ", IccLibJSON Version " ICCLIBJSONVER "\n\n");
printf("Usage: IccFromJson json_file saved_profile_file {-noid}\n");
return 0;
}

CIccTagCreator::PushFactory(new CIccTagJsonFactory());
CIccMpeCreator::PushFactory(new CIccMpeJsonFactory());

CIccProfileJson profile;
std::string reason;

bool bNoId = false;
for (int i = 3; i < argc; i++) {
if (!stricmp(argv[i], "-noid"))
bNoId = true;
}

if (!profile.LoadJson(argv[1], &reason)) {
printf("%s", reason.c_str());
printf("Unable to Parse '%s'\n", argv[1]);
return -1;
}

std::string valid_report;

if (profile.Validate(valid_report) <= icValidateWarning) {
int i;
for (i = 0; i < 16; i++) {
if (profile.m_Header.profileID.ID8[i])
break;
}
if (SaveIccProfile(argv[2], &profile, bNoId ? icNeverWriteID : (i < 16 ? icAlwaysWriteID : icVersionBasedID))) {
printf("Profile parsed and saved correctly\n");
}
else {
printf("Unable to save profile as '%s'\n", argv[2]);
return -1;
}
}
else {
int i;
for (i = 0; i < 16; i++) {
if (profile.m_Header.profileID.ID8[i])
break;
}
if (SaveIccProfile(argv[2], &profile, bNoId ? icNeverWriteID : (i < 16 ? icAlwaysWriteID : icVersionBasedID))) {
printf("Profile parsed. Profile is invalid, but saved correctly\n");
}
else {
printf("Unable to save profile - profile is invalid!\n");
return -1;
}
printf("%s", valid_report.c_str());
}

printf("\n");
return 0;
}
Loading
Loading