- CMakeLists.txt: adds AppConfig to converter_core sources, LibRaw fallback find_library for MinGW, CPack config for NSIS+ZIP (Windows) and TGZ+DEB (Linux), install rules for binary and example config - cmake/toolchain-mingw64.cmake: x86_64-w64-mingw32 toolchain, static libgcc/libstdc++ linking, optional vcpkg x64-mingw-static triplet Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
183 lines
7.2 KiB
CMake
183 lines
7.2 KiB
CMake
cmake_minimum_required(VERSION 3.20)
|
|
project(photo-converter
|
|
VERSION 0.1.0
|
|
DESCRIPTION "Analog film negative to digital positive converter"
|
|
LANGUAGES CXX
|
|
)
|
|
|
|
# ──────────────────────────────────────────────
|
|
# C++ Standard
|
|
# ──────────────────────────────────────────────
|
|
set(CMAKE_CXX_STANDARD 23)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
# ──────────────────────────────────────────────
|
|
# Build options
|
|
# ──────────────────────────────────────────────
|
|
option(BUILD_TESTS "Build unit tests" ON)
|
|
option(BUILD_GUI "Build GUI (requires Qt 6)" ON)
|
|
|
|
# ──────────────────────────────────────────────
|
|
# Platform detection
|
|
# ──────────────────────────────────────────────
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
|
set(PHOTOCONV_WINDOWS TRUE)
|
|
else()
|
|
set(PHOTOCONV_WINDOWS FALSE)
|
|
endif()
|
|
|
|
# ──────────────────────────────────────────────
|
|
# Dependencies
|
|
# ──────────────────────────────────────────────
|
|
# Minimum 4.10 for production; 4.6+ accepted for development.
|
|
# Lower the version bound here if building against an older system install.
|
|
find_package(OpenCV 4.6 REQUIRED COMPONENTS core imgproc imgcodecs)
|
|
|
|
# LibRaw: try pkg-config first (Linux/macOS), fall back to find_package (vcpkg Windows)
|
|
if(NOT PHOTOCONV_WINDOWS)
|
|
find_package(PkgConfig REQUIRED)
|
|
pkg_check_modules(LIBRAW REQUIRED IMPORTED_TARGET libraw)
|
|
set(LIBRAW_TARGET PkgConfig::LIBRAW)
|
|
else()
|
|
# On Windows with vcpkg: find_package(libraw CONFIG) works.
|
|
find_package(libraw CONFIG QUIET)
|
|
if(libraw_FOUND)
|
|
set(LIBRAW_TARGET libraw::libraw)
|
|
else()
|
|
# Fallback: try manual path (MinGW cross-compilation sysroot)
|
|
find_library(LIBRAW_LIB raw REQUIRED)
|
|
find_path(LIBRAW_INCLUDE libraw/libraw.h REQUIRED)
|
|
add_library(libraw_compat INTERFACE IMPORTED)
|
|
target_link_libraries(libraw_compat INTERFACE ${LIBRAW_LIB})
|
|
target_include_directories(libraw_compat INTERFACE ${LIBRAW_INCLUDE})
|
|
set(LIBRAW_TARGET libraw_compat)
|
|
endif()
|
|
endif()
|
|
|
|
if(BUILD_GUI)
|
|
find_package(Qt6 6.8 REQUIRED COMPONENTS Widgets)
|
|
qt_standard_project_setup()
|
|
endif()
|
|
|
|
# ──────────────────────────────────────────────
|
|
# Core converter library (no Qt dependency)
|
|
# ──────────────────────────────────────────────
|
|
add_library(converter_core STATIC
|
|
src/config/AppConfig.cpp
|
|
src/converter/pipeline/Pipeline.cpp
|
|
src/converter/rawloader/RawLoader.cpp
|
|
src/converter/preprocess/Preprocessor.cpp
|
|
src/converter/negative/NegativeDetector.cpp
|
|
src/converter/invert/Inverter.cpp
|
|
src/converter/color/ColorCorrector.cpp
|
|
src/converter/crop/CropProcessor.cpp
|
|
src/converter/output/OutputWriter.cpp
|
|
src/cli/CliRunner.cpp
|
|
)
|
|
|
|
target_include_directories(converter_core PUBLIC
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
)
|
|
|
|
target_link_libraries(converter_core PUBLIC
|
|
${OpenCV_LIBS}
|
|
${LIBRAW_TARGET}
|
|
)
|
|
|
|
target_compile_options(converter_core PRIVATE
|
|
$<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -Wpedantic>
|
|
$<$<CXX_COMPILER_ID:Clang>:-Wall -Wextra -Wpedantic>
|
|
$<$<CXX_COMPILER_ID:MSVC>:/W4>
|
|
)
|
|
|
|
# ──────────────────────────────────────────────
|
|
# Main executable
|
|
# ──────────────────────────────────────────────
|
|
if(BUILD_GUI)
|
|
qt_add_executable(photo-converter
|
|
src/main.cpp
|
|
src/gui/MainWindow.cpp
|
|
src/gui/MainWindow.h
|
|
)
|
|
|
|
target_link_libraries(photo-converter PRIVATE
|
|
converter_core
|
|
Qt6::Widgets
|
|
)
|
|
|
|
target_include_directories(photo-converter PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
)
|
|
else()
|
|
# CLI-only build (no Qt)
|
|
add_executable(photo-converter
|
|
src/main.cpp
|
|
)
|
|
|
|
target_link_libraries(photo-converter PRIVATE
|
|
converter_core
|
|
)
|
|
|
|
target_compile_definitions(photo-converter PRIVATE NO_GUI=1)
|
|
|
|
target_include_directories(photo-converter PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
)
|
|
endif()
|
|
|
|
# Windows: link against winsock / windows socket libraries needed by OpenCV
|
|
if(PHOTOCONV_WINDOWS)
|
|
target_link_libraries(photo-converter PRIVATE ws2_32)
|
|
endif()
|
|
|
|
# ──────────────────────────────────────────────
|
|
# Install rules
|
|
# ──────────────────────────────────────────────
|
|
include(GNUInstallDirs)
|
|
|
|
install(TARGETS photo-converter
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
)
|
|
|
|
install(FILES config.ini
|
|
DESTINATION ${CMAKE_INSTALL_DOCDIR}
|
|
RENAME config.ini.example
|
|
)
|
|
|
|
# ──────────────────────────────────────────────
|
|
# CPack packaging
|
|
# ──────────────────────────────────────────────
|
|
set(CPACK_PACKAGE_NAME "photo-converter")
|
|
set(CPACK_PACKAGE_VENDOR "photo-converter project")
|
|
set(CPACK_PACKAGE_DESCRIPTION_SHORT "${PROJECT_DESCRIPTION}")
|
|
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
|
|
set(CPACK_PACKAGE_INSTALL_DIRECTORY "photo-converter")
|
|
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" )
|
|
|
|
if(PHOTOCONV_WINDOWS)
|
|
# NSIS installer for Windows
|
|
set(CPACK_GENERATOR "NSIS;ZIP")
|
|
set(CPACK_NSIS_DISPLAY_NAME "Photo Converter ${PROJECT_VERSION}")
|
|
set(CPACK_NSIS_PACKAGE_NAME "photo-converter")
|
|
set(CPACK_NSIS_MODIFY_PATH ON)
|
|
set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/assets/icon.ico")
|
|
set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}/assets/icon.ico")
|
|
else()
|
|
# TGZ + DEB for Linux / ZIP for macOS
|
|
set(CPACK_GENERATOR "TGZ;DEB")
|
|
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "photo-converter project")
|
|
set(CPACK_DEBIAN_PACKAGE_DEPENDS
|
|
"libopencv-core4.10 | libopencv4-java, libraw23, libqt6widgets6")
|
|
endif()
|
|
|
|
include(CPack)
|
|
|
|
# ──────────────────────────────────────────────
|
|
# Tests
|
|
# ──────────────────────────────────────────────
|
|
if(BUILD_TESTS)
|
|
enable_testing()
|
|
add_subdirectory(tests)
|
|
endif()
|