216 lines
6.4 KiB
CMake
216 lines
6.4 KiB
CMake
cmake_minimum_required(VERSION 3.20)
|
|
|
|
project(media-image-service
|
|
VERSION 0.1.0
|
|
DESCRIPTION "Polymech image resize service (CLI, REST, IPC) — libvips"
|
|
LANGUAGES CXX
|
|
)
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/dist")
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/dist")
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}/dist")
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_SOURCE_DIR}/dist")
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_SOURCE_DIR}/dist")
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
|
|
|
# Windows: official libvips dev tree (see scripts/fetch-vips-windows.ps1) — vips-dev-* under third_party/
|
|
if(WIN32)
|
|
file(GLOB _MEDIA_VIPS_SDK "${CMAKE_CURRENT_SOURCE_DIR}/third_party/vips-dev-*")
|
|
if(_MEDIA_VIPS_SDK)
|
|
list(APPEND CMAKE_PREFIX_PATH ${_MEDIA_VIPS_SDK})
|
|
endif()
|
|
endif()
|
|
|
|
include(FetchContent)
|
|
|
|
set(JSON_BuildTests OFF CACHE BOOL "" FORCE)
|
|
|
|
FetchContent_Declare(
|
|
cli11
|
|
GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git
|
|
GIT_TAG v2.4.2
|
|
GIT_SHALLOW TRUE
|
|
)
|
|
|
|
FetchContent_Declare(
|
|
asio
|
|
GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git
|
|
GIT_TAG asio-1-28-0
|
|
GIT_SHALLOW TRUE
|
|
)
|
|
|
|
FetchContent_Declare(
|
|
nlohmann_json
|
|
GIT_REPOSITORY https://github.com/nlohmann/json.git
|
|
GIT_TAG v3.11.3
|
|
GIT_SHALLOW TRUE
|
|
)
|
|
|
|
FetchContent_Declare(
|
|
cpp_httplib
|
|
GIT_REPOSITORY https://github.com/yhirose/cpp-httplib.git
|
|
GIT_TAG v0.16.3
|
|
GIT_SHALLOW TRUE
|
|
)
|
|
|
|
FetchContent_MakeAvailable(cli11 asio nlohmann_json cpp_httplib)
|
|
|
|
# libcurl — HTTP(S) URL inputs (minimal static build; SChannel on Windows, OpenSSL on Linux).
|
|
set(CMAKE_POLICY_VERSION_MINIMUM 3.5 CACHE STRING "" FORCE)
|
|
FetchContent_Declare(
|
|
CURL
|
|
URL https://github.com/curl/curl/releases/download/curl-8_12_1/curl-8.12.1.tar.xz
|
|
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
|
|
)
|
|
set(BUILD_CURL_EXE OFF CACHE BOOL "" FORCE)
|
|
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
|
|
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
|
|
if(WIN32)
|
|
set(CURL_USE_OPENSSL OFF CACHE BOOL "" FORCE)
|
|
set(CURL_USE_SCHANNEL ON CACHE BOOL "" FORCE)
|
|
else()
|
|
set(CURL_USE_SCHANNEL OFF CACHE BOOL "" FORCE)
|
|
set(CURL_USE_OPENSSL ON CACHE BOOL "" FORCE)
|
|
endif()
|
|
set(CURL_ZLIB OFF CACHE BOOL "" FORCE)
|
|
set(CURL_BROTLI OFF CACHE BOOL "" FORCE)
|
|
set(CURL_ZSTD OFF CACHE BOOL "" FORCE)
|
|
set(USE_NGHTTP2 OFF CACHE BOOL "" FORCE)
|
|
set(CURL_USE_LIBSSH2 OFF CACHE BOOL "" FORCE)
|
|
set(CURL_USE_LIBPSL OFF CACHE BOOL "" FORCE)
|
|
set(CURL_DISABLE_LDAP ON CACHE BOOL "" FORCE)
|
|
set(CURL_DISABLE_LDAPS ON CACHE BOOL "" FORCE)
|
|
FetchContent_MakeAvailable(CURL)
|
|
|
|
# PicoSHA2 — header-only SHA256 for cache keys.
|
|
FetchContent_Declare(
|
|
picosha2
|
|
GIT_REPOSITORY https://github.com/okdshin/PicoSHA2.git
|
|
GIT_TAG master
|
|
GIT_SHALLOW TRUE
|
|
)
|
|
FetchContent_GetProperties(picosha2)
|
|
if(NOT picosha2_POPULATED)
|
|
FetchContent_Populate(picosha2)
|
|
endif()
|
|
|
|
# p-ranav/glob — same as packages/kbot/cpp (glob / rglob for **).
|
|
FetchContent_Declare(
|
|
pranav_glob
|
|
GIT_REPOSITORY https://github.com/p-ranav/glob.git
|
|
GIT_TAG master
|
|
GIT_SHALLOW TRUE
|
|
)
|
|
FetchContent_GetProperties(pranav_glob)
|
|
if(NOT pranav_glob_POPULATED)
|
|
FetchContent_Populate(pranav_glob)
|
|
endif()
|
|
add_library(pranav_glob STATIC ${pranav_glob_SOURCE_DIR}/source/glob.cpp)
|
|
target_include_directories(pranav_glob PUBLIC ${pranav_glob_SOURCE_DIR}/include)
|
|
target_compile_features(pranav_glob PUBLIC cxx_std_17)
|
|
if(MSVC)
|
|
target_compile_options(pranav_glob PRIVATE /permissive-)
|
|
endif()
|
|
|
|
# laserpants/dotenv-cpp — load .env (same pattern as packages/kbot/cpp).
|
|
FetchContent_Declare(
|
|
laserpants_dotenv
|
|
GIT_REPOSITORY https://github.com/laserpants/dotenv-cpp.git
|
|
GIT_TAG master
|
|
GIT_SHALLOW TRUE
|
|
)
|
|
FetchContent_GetProperties(laserpants_dotenv)
|
|
if(NOT laserpants_dotenv_POPULATED)
|
|
FetchContent_Populate(laserpants_dotenv)
|
|
endif()
|
|
add_library(laserpants_dotenv INTERFACE)
|
|
target_include_directories(laserpants_dotenv INTERFACE ${laserpants_dotenv_SOURCE_DIR}/include)
|
|
add_library(laserpants::dotenv ALIAS laserpants_dotenv)
|
|
|
|
find_package(Vips REQUIRED)
|
|
|
|
add_executable(media-img
|
|
src/main.cpp
|
|
src/core/cache.cpp
|
|
src/core/glob_paths.cpp
|
|
src/core/output_path.cpp
|
|
src/core/resize.cpp
|
|
src/core/url_fetch.cpp
|
|
src/http/serve.cpp
|
|
src/ipc/ipc_serve.cpp
|
|
)
|
|
|
|
target_include_directories(media-img PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
${asio_SOURCE_DIR}/asio/include
|
|
${picosha2_SOURCE_DIR}
|
|
)
|
|
|
|
target_compile_definitions(media-img PRIVATE
|
|
ASIO_STANDALONE
|
|
ASIO_NO_DEPRECATED
|
|
CPPHTTPLIB_NO_EXCEPTIONS=0
|
|
)
|
|
|
|
if(WIN32)
|
|
target_compile_definitions(media-img PRIVATE
|
|
_WIN32_WINNT=0x0A00
|
|
NOMINMAX
|
|
)
|
|
endif()
|
|
|
|
target_link_libraries(media-img PRIVATE
|
|
CLI11::CLI11
|
|
nlohmann_json::nlohmann_json
|
|
httplib::httplib
|
|
laserpants::dotenv
|
|
pranav_glob
|
|
CURL::libcurl
|
|
Vips::vips
|
|
)
|
|
|
|
# GObject (g_object_ref / g_object_unref) — not re-exported through libvips import lib on MSVC.
|
|
if(WIN32)
|
|
file(GLOB _MEDIA_VIPS_SDK_LIST "${CMAKE_CURRENT_SOURCE_DIR}/third_party/vips-dev-*")
|
|
if(_MEDIA_VIPS_SDK_LIST)
|
|
list(GET _MEDIA_VIPS_SDK_LIST 0 _MEDIA_VIPS_SDK)
|
|
if(EXISTS "${_MEDIA_VIPS_SDK}/lib/libgobject-2.0.lib")
|
|
target_link_libraries(media-img PRIVATE
|
|
"${_MEDIA_VIPS_SDK}/lib/libgobject-2.0.lib"
|
|
"${_MEDIA_VIPS_SDK}/lib/libglib-2.0.lib"
|
|
)
|
|
endif()
|
|
endif()
|
|
endif()
|
|
|
|
if(UNIX AND NOT APPLE)
|
|
target_link_libraries(media-img PRIVATE pthread)
|
|
endif()
|
|
|
|
target_compile_definitions(media-img PRIVATE
|
|
"MEDIA_IMG_VERSION=\"${PROJECT_VERSION}\""
|
|
)
|
|
|
|
# Runtime: libvips and deps are DLLs next to media-img.exe (Windows dev bundle bin/).
|
|
if(WIN32)
|
|
file(GLOB _MEDIA_VIPS_SDK_LIST "${CMAKE_CURRENT_SOURCE_DIR}/third_party/vips-dev-*")
|
|
if(_MEDIA_VIPS_SDK_LIST)
|
|
list(GET _MEDIA_VIPS_SDK_LIST 0 _MEDIA_VIPS_SDK)
|
|
if(EXISTS "${_MEDIA_VIPS_SDK}/bin")
|
|
add_custom_command(
|
|
TARGET media-img
|
|
POST_BUILD
|
|
COMMAND "${CMAKE_COMMAND}" -E copy_directory
|
|
"${_MEDIA_VIPS_SDK}/bin"
|
|
"${CMAKE_SOURCE_DIR}/dist"
|
|
COMMENT "Copy libvips DLLs to dist/"
|
|
)
|
|
endif()
|
|
endif()
|
|
endif()
|