diff --git a/CMakeLists.txt b/CMakeLists.txt index fed810d7..72fc37c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,111 +1,63 @@ -# PhotoshopAPI Requires C++ 20 -cmake_minimum_required (VERSION 3.20) -set (CMAKE_CXX_STANDARD 20) - -if(MSVC) - set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib") - add_definitions(-D_CRT_SECURE_NO_WARNINGS) -endif() - -# Link the MSVC Runtime libraries into the exe -set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - -# Enable Hot Reload for MSVC compilers if supported. -if (POLICY CMP0141) - cmake_policy(SET CMP0141 NEW) - set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$,$>,$<$:EditAndContinue>,$<$:ProgramDatabase>>") -endif() +cmake_minimum_required (VERSION 3.20) +project ("PhotoshopAPIBuild") # -------------------------------------------------------------------------- -# CMake Build Setup for the PhotoshopAPI -# -------------------------------------------------------------------------- -# -# A list of available options can be found below: -# -# PSAPI_BUILD_STATIC: default ON -# Build a static library version of the PhotoshopAPI -# PSAPI_BUILD_TESTS: default ON -# Build the tests associated with the PhotoshopAPI -# PSAPI_BUILD_EXAMPLES: default ON -# Build the examples associated with the PhotoshopAPI -# PSAPI_BUILD_BENCHMARKS: default ON -# Build the benchmarks associated with the PhotoshopAPI -# PSAPI_BUILD_DOCS: default ON -# Builds the documentation, requires some external installs which are documented in the README.md -# -project ("PhotoshopAPIBuild") +# Configurable options -# Initialize our options option(PSAPI_BUILD_STATIC "Build a static library version of the PhotoshopAPI" ON) option(PSAPI_BUILD_TESTS "Build the tests associated with the PhotoshopAPI" ON) option(PSAPI_BUILD_EXAMPLES "Build the examples associated with the PhotoshopAPI" ON) option(PSAPI_BUILD_BENCHMARKS "Build the benchmarks associated with the PhotoshopAPI" ON) option(PSAPI_BUILD_DOCS "Builds the documentation, requires some external installs which are documented in the README.md" ON) +# Build setup +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +set (CMAKE_CXX_STANDARD 20) # Add the cmake/ folder so the FindSphinx module is found # -------------------------------------------------------------------------- set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) -# Specify our own version of zlib-ng rather than the supplied one for blosc2. -# Switch to the debug library if that is the build target -# -------------------------------------------------------------------------- -set(PREFER_EXTERNAL_ZLIB ON) -if(CMAKE_BUILD_TYPE STREQUAL "Release") - set (ZLIB_NG_LIBRARY "${CMAKE_BINARY_DIR}/thirdparty/zlib-ng/zlibstatic-ng.lib") -else() - set (ZLIB_NG_LIBRARY "${CMAKE_BINARY_DIR}/thirdparty/zlib-ng/zlibstatic-ngd.lib") -endif() -set (ZLIB_NG_INCLUDE_DIR "${CMAKE_BINARY_DIR}/thirdparty/zlib-ng") - # Add thirdparty libraries # -------------------------------------------------------------------------- -# Modify zlib-ng to only build libs +# Add zlib-ng set(ZLIB_ENABLE_TESTS OFF) set(ZLIBNG_ENABLE_TESTS OFF) set(WITH_GZFILEOP OFF) -add_subdirectory ("${CMAKE_SOURCE_DIR}/thirdparty/zlib-ng" EXCLUDE_FROM_ALL) +add_subdirectory (thirdparty/zlib-ng EXCLUDE_FROM_ALL) -# Modify c-blosc2 to only build libs +# Add c-blosc2 +set(DEACTIVATE_ZLIB ON) +set(DEACTIVATE_ZSTD ON) set(BUILD_TESTS OFF) set(BUILD_FUZZERS OFF) set(BUILD_BENCHMARKS OFF) set(BUILD_EXAMPLES OFF) -add_subdirectory ("${CMAKE_SOURCE_DIR}/thirdparty/c-blosc2" EXCLUDE_FROM_ALL) +add_subdirectory (thirdparty/c-blosc2 EXCLUDE_FROM_ALL) + +# Add doctest +add_library(doctest INTERFACE) +target_include_directories(doctest INTERFACE thirdparty/doctest) -# Include PhotoshopAPI sub-projects. +# Projects # -------------------------------------------------------------------------- if(PSAPI_BUILD_STATIC) - add_subdirectory ("${CMAKE_SOURCE_DIR}/PhotoshopAPI") + add_subdirectory (PhotoshopAPI) endif() if(PSAPI_BUILD_TESTS) - add_subdirectory ("${CMAKE_SOURCE_DIR}/PhotoshopTest") + add_subdirectory (PhotoshopTest) endif() if(PSAPI_BUILD_BENCHMARKS) - add_subdirectory ("${CMAKE_SOURCE_DIR}/PhotoshopBenchmark") + add_subdirectory (PhotoshopBenchmark) endif() - -# Add our Example directories -# -------------------------------------------------------------------------- if(PSAPI_BUILD_EXAMPLES) - add_subdirectory ("${CMAKE_SOURCE_DIR}/PhotoshopExamples/CreateSimpleDocument") - add_subdirectory ("${CMAKE_SOURCE_DIR}/PhotoshopExamples/CreateGroups") - add_subdirectory ("${CMAKE_SOURCE_DIR}/PhotoshopExamples/AddLayerMasks") - add_subdirectory ("${CMAKE_SOURCE_DIR}/PhotoshopExamples/ModifyLayerStructure") + add_subdirectory (PhotoshopExamples/CreateSimpleDocument) + add_subdirectory (PhotoshopExamples/CreateGroups) + add_subdirectory (PhotoshopExamples/AddLayerMasks) + add_subdirectory (PhotoshopExamples/ModifyLayerStructure) endif() - -# Add our documentation dir -# -------------------------------------------------------------------------- if(PSAPI_BUILD_DOCS) - add_subdirectory ("${CMAKE_SOURCE_DIR}/docs/doxygen") -endif() - - -# Set the test project (PhotoshopTest) as the default target -# -------------------------------------------------------------------------- -add_custom_target(default_target ALL - DEPENDS PhotoshopTest - COMMENT "Building the default target: PhotoshopTest" -) \ No newline at end of file + add_subdirectory (docs/doxygen) +endif() \ No newline at end of file diff --git a/PhotoshopAPI/CMakeLists.txt b/PhotoshopAPI/CMakeLists.txt index 46dcc672..0543e602 100644 --- a/PhotoshopAPI/CMakeLists.txt +++ b/PhotoshopAPI/CMakeLists.txt @@ -1,69 +1,12 @@ # Define the project # -------------------------------------------------------------------------- -set(LIB PhotoshopAPI) -project(${LIB}) - -# Define MY_SOURCES to be a list of all the source files +project(PhotoshopAPI) file(GLOB_RECURSE MY_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/*.cpp") -# Copy the header files from /include and /src to the binary dir -# -------------------------------------------------------------------------- - -# Set the source directory -set(SOURCE_DIR ${PROJECT_SOURCE_DIR}/src) -# Gather a list of all header files -file(GLOB_RECURSE HEADER_FILES ${SOURCE_DIR}/*.h) -# Set the include dir in our binary -set(BIN_INCLUDE_DIR ${CMAKE_BINARY_DIR}/include) - -# Custom target for header file copying -add_custom_target(CopyHeaders - COMMENT "Copying header files to include directory" - VERBATIM -) - -# Copy header files to the include directory with folder structure intact -foreach(HEADER_FILE ${HEADER_FILES}) - # Get the relative path of the header file - file(RELATIVE_PATH RELATIVE_HEADER ${SOURCE_DIR} ${HEADER_FILE}) - - # Create the corresponding include directory for the header file - get_filename_component(INCLUDE_SUBDIR ${RELATIVE_HEADER} DIRECTORY) - set(DESTINATION_DIR ${BIN_INCLUDE_DIR}/${INCLUDE_SUBDIR}) - file(MAKE_DIRECTORY ${DESTINATION_DIR}) - - # Copy the header file to the include directory - add_custom_command(TARGET CopyHeaders - COMMAND ${CMAKE_COMMAND} -E copy ${HEADER_FILE} ${DESTINATION_DIR} - COMMENT "Copying ${HEADER_FILE} to ${DESTINATION_DIR}" - ) -endforeach() - -# Copy the /include/PhotoshopAPI.h separately -add_custom_command(TARGET CopyHeaders - COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/include/PhotoshopAPI.h" ${BIN_INCLUDE_DIR} - COMMENT "Copying ${PROJECT_SOURCE_DIR}/include/PhotoshopAPI.h to ${BIN_INCLUDE_DIR}" -) - -# Create our static lib -# -------------------------------------------------------------------------- -add_library (${LIB} STATIC ${MY_SOURCES}) - -# Add dependency to CopyHeaders -add_dependencies(${LIB} CopyHeaders) - -# Set some additional includes -target_include_directories(${LIB} PUBLIC - "${PROJECT_SOURCE_DIR}/src/" - "${PROJECT_SOURCE_DIR}/src/Util/" -) - -# Include blosc2 headers -target_include_directories(${LIB} PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/c-blosc2/include") -#include zlib-ng headers -target_include_directories(${LIB} PUBLIC "${CMAKE_BINARY_DIR}/thirdparty/zlib-ng") -target_include_directories(${LIB} PUBLIC "${CMAKE_SOURCE_DIR}/thirdparty/zlib-ng") +add_library(PhotoshopAPI STATIC ${MY_SOURCES}) +target_include_directories(PhotoshopAPI PUBLIC include ${CMAKE_SOURCE_DIR}/thirdparty/c-blosc2/include src src/Util) +target_link_libraries(PhotoshopAPI PUBLIC zlibstatic Blosc2::blosc2_static) if(MSVC) - target_compile_options(${LIB} PRIVATE /MP /DNOMINMAX) + target_compile_options(PhotoshopAPI PRIVATE /MP /DNOMINMAX) endif() \ No newline at end of file diff --git a/PhotoshopBenchmark/CMakeLists.txt b/PhotoshopBenchmark/CMakeLists.txt index d4da27d9..386bd6bf 100644 --- a/PhotoshopBenchmark/CMakeLists.txt +++ b/PhotoshopBenchmark/CMakeLists.txt @@ -1,28 +1,3 @@ -# This is a minimal CMake setup required to work with the PhotoshopAPI. - -# Initialize our Project -set (EXE PhotoshopBenchmark) -project(${EXE}) - -# Define MY_SOURCES to be a list of all the source files -file(GLOB_RECURSE MY_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/*.cpp") -add_executable(${EXE} ${MY_SOURCES}) - -# Include and link the PhotoshopAPI -target_include_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/PhotoshopAPI/include") -target_link_libraries(${EXE} PRIVATE PhotoshopAPI) - -# Include and link blosc2 -target_include_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/c-blosc2/include") -target_link_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/c-blosc2") -target_link_libraries(${EXE} PRIVATE blosc2_static) - -#include and link zlib-ng -target_include_directories(${EXE} PUBLIC "${CMAKE_BINARY_DIR}/thirdparty/zlib-ng") -target_include_directories(${EXE} PUBLIC "${CMAKE_SOURCE_DIR}/thirdparty/zlib-ng") -target_link_directories(${EXE} PUBLIC "${CMAKE_BINARY_DIR}/thirdparty/zlib-ng") -if(CMAKE_BUILD_TYPE STREQUAL "Release") - target_link_libraries(${EXE} PUBLIC zlibstatic-ng) -else() - target_link_libraries(${EXE} PUBLIC zlibstatic-ngd) -endif() \ No newline at end of file +file(GLOB_RECURSE MY_SOURCES CONFIGURE_DEPENDS "src/*.cpp") +add_executable(PhotoshopBenchmark ${MY_SOURCES}) +target_link_libraries(PhotoshopBenchmark PRIVATE PhotoshopAPI) \ No newline at end of file diff --git a/PhotoshopExamples/AddLayerMasks/CMakeLists.txt b/PhotoshopExamples/AddLayerMasks/CMakeLists.txt index 3fe41c31..9ae8e4c2 100644 --- a/PhotoshopExamples/AddLayerMasks/CMakeLists.txt +++ b/PhotoshopExamples/AddLayerMasks/CMakeLists.txt @@ -1,28 +1,2 @@ -# This is a minimal CMake setup required to work with the PhotoshopAPI. - -# Initialize our Project -set (EXE AddLayerMasks) -project(${EXE}) - -# Define MY_SOURCES to be a list of all the source files -file(GLOB_RECURSE MY_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/*.cpp") -add_executable(${EXE} ${MY_SOURCES}) - -# Include and link the PhotoshopAPI -target_include_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/PhotoshopAPI/include") -target_link_libraries(${EXE} PRIVATE PhotoshopAPI) - -# Include and link blosc2 -target_include_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/c-blosc2/include") -target_link_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/c-blosc2") -target_link_libraries(${EXE} PRIVATE blosc2_static) - -#include and link zlib-ng -target_include_directories(${EXE} PUBLIC "${CMAKE_BINARY_DIR}/thirdparty/zlib-ng") -target_include_directories(${EXE} PUBLIC "${CMAKE_SOURCE_DIR}/thirdparty/zlib-ng") -target_link_directories(${EXE} PUBLIC "${CMAKE_BINARY_DIR}/thirdparty/zlib-ng") -if(CMAKE_BUILD_TYPE STREQUAL "Release") - target_link_libraries(${EXE} PUBLIC zlibstatic-ng) -else() - target_link_libraries(${EXE} PUBLIC zlibstatic-ngd) -endif() \ No newline at end of file +add_executable(AddLayerMasks main.cpp) +target_link_libraries(AddLayerMasks PRIVATE PhotoshopAPI) \ No newline at end of file diff --git a/PhotoshopExamples/CreateGroups/CMakeLists.txt b/PhotoshopExamples/CreateGroups/CMakeLists.txt index abb125a2..2613edb7 100644 --- a/PhotoshopExamples/CreateGroups/CMakeLists.txt +++ b/PhotoshopExamples/CreateGroups/CMakeLists.txt @@ -1,28 +1,2 @@ -# This is a minimal CMake setup required to work with the PhotoshopAPI. - -# Initialize our Project -set (EXE CreateGroups) -project(${EXE}) - -# Define MY_SOURCES to be a list of all the source files -file(GLOB_RECURSE MY_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/*.cpp") -add_executable(${EXE} ${MY_SOURCES}) - -# Include and link the PhotoshopAPI -target_include_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/PhotoshopAPI/include") -target_link_libraries(${EXE} PRIVATE PhotoshopAPI) - -# Include and link blosc2 -target_include_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/c-blosc2/include") -target_link_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/c-blosc2") -target_link_libraries(${EXE} PRIVATE blosc2_static) - -#include and link zlib-ng -target_include_directories(${EXE} PUBLIC "${CMAKE_BINARY_DIR}/thirdparty/zlib-ng") -target_include_directories(${EXE} PUBLIC "${CMAKE_SOURCE_DIR}/thirdparty/zlib-ng") -target_link_directories(${EXE} PUBLIC "${CMAKE_BINARY_DIR}/thirdparty/zlib-ng") -if(CMAKE_BUILD_TYPE STREQUAL "Release") - target_link_libraries(${EXE} PUBLIC zlibstatic-ng) -else() - target_link_libraries(${EXE} PUBLIC zlibstatic-ngd) -endif() \ No newline at end of file +add_executable(CreateGroups main.cpp) +target_link_libraries(CreateGroups PRIVATE PhotoshopAPI) \ No newline at end of file diff --git a/PhotoshopExamples/CreateSimpleDocument/CMakeLists.txt b/PhotoshopExamples/CreateSimpleDocument/CMakeLists.txt index 373d122f..e420c961 100644 --- a/PhotoshopExamples/CreateSimpleDocument/CMakeLists.txt +++ b/PhotoshopExamples/CreateSimpleDocument/CMakeLists.txt @@ -1,28 +1,2 @@ -# This is a minimal CMake setup required to work with the PhotoshopAPI. - -# Initialize our Project -set (EXE CreateSimpleDocument) -project(${EXE}) - -# Define MY_SOURCES to be a list of all the source files -file(GLOB_RECURSE MY_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/*.cpp") -add_executable(${EXE} ${MY_SOURCES}) - -# Include and link the PhotoshopAPI -target_include_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/PhotoshopAPI/include") -target_link_libraries(${EXE} PRIVATE PhotoshopAPI) - -# Include and link blosc2 -target_include_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/c-blosc2/include") -target_link_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/c-blosc2") -target_link_libraries(${EXE} PRIVATE blosc2_static) - -#include and link zlib-ng -target_include_directories(${EXE} PUBLIC "${CMAKE_BINARY_DIR}/thirdparty/zlib-ng") -target_include_directories(${EXE} PUBLIC "${CMAKE_SOURCE_DIR}/thirdparty/zlib-ng") -target_link_directories(${EXE} PUBLIC "${CMAKE_BINARY_DIR}/thirdparty/zlib-ng") -if(CMAKE_BUILD_TYPE STREQUAL "Release") - target_link_libraries(${EXE} PUBLIC zlibstatic-ng) -else() - target_link_libraries(${EXE} PUBLIC zlibstatic-ngd) -endif() \ No newline at end of file +add_executable(CreateSimpleDocument main.cpp) +target_link_libraries(CreateSimpleDocument PRIVATE PhotoshopAPI) \ No newline at end of file diff --git a/PhotoshopExamples/ModifyLayerStructure/CMakeLists.txt b/PhotoshopExamples/ModifyLayerStructure/CMakeLists.txt index 25d8eb47..8dcb5f90 100644 --- a/PhotoshopExamples/ModifyLayerStructure/CMakeLists.txt +++ b/PhotoshopExamples/ModifyLayerStructure/CMakeLists.txt @@ -1,34 +1,2 @@ -# This is a minimal CMake setup required to work with the PhotoshopAPI. - -# Initialize our Project -set (EXE ModifyLayerStructure) -project(${EXE}) - -# Define MY_SOURCES to be a list of all the source files -file(GLOB_RECURSE MY_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/*.cpp") -add_executable(${EXE} ${MY_SOURCES}) - -# Include and link the PhotoshopAPI -target_include_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/PhotoshopAPI/include") -target_link_libraries(${EXE} PRIVATE PhotoshopAPI) - -# Include and link blosc2 -target_include_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/c-blosc2/include") -target_link_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/c-blosc2") -target_link_libraries(${EXE} PRIVATE blosc2_static) - -#include and link zlib-ng -target_include_directories(${EXE} PUBLIC "${CMAKE_BINARY_DIR}/thirdparty/zlib-ng") -target_include_directories(${EXE} PUBLIC "${CMAKE_SOURCE_DIR}/thirdparty/zlib-ng") -target_link_directories(${EXE} PUBLIC "${CMAKE_BINARY_DIR}/thirdparty/zlib-ng") -if(CMAKE_BUILD_TYPE STREQUAL "Release") - target_link_libraries(${EXE} PUBLIC zlibstatic-ng) -else() - target_link_libraries(${EXE} PUBLIC zlibstatic-ngd) -endif() - - -# Copy the LayeredFile.psd to our binary directory -add_custom_command(TARGET ${EXE} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${PROJECT_SOURCE_DIR}/LayeredFile.psd $/LayeredFile.psd) \ No newline at end of file +add_executable(ModifyLayerStructure main.cpp) +target_link_libraries(ModifyLayerStructure PRIVATE PhotoshopAPI) \ No newline at end of file diff --git a/PhotoshopTest/CMakeLists.txt b/PhotoshopTest/CMakeLists.txt index 5cb4c881..b97c397c 100644 --- a/PhotoshopTest/CMakeLists.txt +++ b/PhotoshopTest/CMakeLists.txt @@ -1,42 +1,8 @@ -# Initialize our Project -set (EXE PhotoshopTest) -project(${EXE}) +file(GLOB_RECURSE MY_SOURCES CONFIGURE_DEPENDS "src/*.cpp") +add_executable(PhotoshopTest ${MY_SOURCES}) -# Define MY_SOURCES to be a list of all the source files -file(GLOB_RECURSE MY_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/*.cpp") - -add_executable(${EXE} ${MY_SOURCES}) - -# Unfortunately, Wall doesnt compile with blosc2 due to its use of getenv if(MSVC) - target_compile_options(${EXE} PRIVATE /MP) + target_compile_options(PhotoshopTest PRIVATE /MP) endif() -# Include and link the PhotoshopAPI -target_include_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/PhotoshopAPI/include") -target_link_libraries(${EXE} PRIVATE PhotoshopAPI) - -# include doctest v2.4.11 library -target_include_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/doctest/") - -# Include and link blosc2 -target_include_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/c-blosc2/include") -target_link_directories(${EXE} PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/c-blosc2") -target_link_libraries(${EXE} PRIVATE blosc2_static) - - -#include and link zlib-ng -target_include_directories(${EXE} PUBLIC "${CMAKE_BINARY_DIR}/thirdparty/zlib-ng") -target_include_directories(${EXE} PUBLIC "${CMAKE_SOURCE_DIR}/thirdparty/zlib-ng") -target_link_directories(${EXE} PUBLIC "${CMAKE_BINARY_DIR}/thirdparty/zlib-ng") -if(CMAKE_BUILD_TYPE STREQUAL "Release") - target_link_libraries(${EXE} PUBLIC zlibstatic-ng) -else() - target_link_libraries(${EXE} PUBLIC zlibstatic-ngd) -endif() - - -# Copy the documents/ folder to the build dir -add_custom_command(TARGET ${EXE} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${PROJECT_SOURCE_DIR}/documents/ $/documents/) \ No newline at end of file +target_link_libraries(PhotoshopTest PRIVATE PhotoshopAPI doctest) \ No newline at end of file