libragephoto/CMakeLists.txt
Syping e08b45d980 low level improvements and data type changes
- RagePhoto: removed setFormatLoadFunction (will be replaced with a
better solution later)
- RagePhoto: code updates for the RagePhotoData changes
- RagePhotoA: have now RagePhoto enum's available
- RagePhotoData: changed description, json, header and title types to
char*
- RagePhotoData: removed photoLoaded in favour of nullptr check
- examples: prepared for the API update
2023-01-07 20:43:11 +01:00

194 lines
6.4 KiB
CMake

#[[**************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021-2023 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* This software is provided as-is, no warranties are given to you, we are not
* responsible for anything with use of the software, you are self responsible.
****************************************************************************]]
cmake_minimum_required(VERSION 3.7)
project(ragephoto VERSION 0.2.0 LANGUAGES CXX)
include(GNUInstallDirs)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# RagePhoto CMake includes
include(cmake/unicode.cmake)
# RagePhoto WebAssembly ON
if (EMSCRIPTEN)
set(EM_ON ON)
else()
set(EM_ON OFF)
endif()
# RagePhoto Top Level ON
if (${CMAKE_PROJECT_NAME} STREQUAL "ragephoto")
set(RPTL_ON ON)
else()
set(RPTL_ON OFF)
endif()
# RagePhoto Source files
set(RAGEPHOTO_HEADERS
src/RagePhoto.h
src/RagePhotoData.h
)
set(RAGEPHOTO_SOURCES
src/RagePhoto.cpp
)
# RagePhoto Library Type
option(RAGEPHOTO_STATIC "Build libragephoto as static library" ${EM_ON})
if (RAGEPHOTO_STATIC)
option(RAGEPHOTO_C_API "Build libragephoto with C API support" ${EM_ON})
set(LIBRAGEPHOTO_LIBTYPE LIBRAGEPHOTO_STATIC)
else()
option(RAGEPHOTO_C_API "Build libragephoto with C API support" ON)
set(LIBRAGEPHOTO_LIBTYPE LIBRAGEPHOTO_SHARED)
endif()
# RagePhoto Benchmark
option(RAGEPHOTO_BENCHMARK "Build with libragephoto benchmark" OFF)
if (RAGEPHOTO_BENCHMARK)
list(APPEND LIBRAGEPHOTO_DEFINES
RAGEPHOTO_BENCHMARK
)
endif()
# RagePhoto C API
if (RAGEPHOTO_C_API)
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_API)
list(APPEND RAGEPHOTO_HEADERS
src/RagePhotoA.h
src/RagePhotoC.h
)
else()
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_NOAPI)
endif()
# RagePhoto Win32 Shared Resources
if (WIN32)
string(TIMESTAMP ragephoto_BUILD_YEAR "%Y" UTC)
configure_file(src/ragephoto.rc.in "${ragephoto_BINARY_DIR}/resources/ragephoto.rc" @ONLY)
list(APPEND RAGEPHOTO_SHARED_RESOURCES
"${ragephoto_BINARY_DIR}/resources/ragephoto.rc"
)
endif()
# RagePhoto Configures + Target + Installs
configure_file(src/ragephoto.pc.in "${ragephoto_BINARY_DIR}/pkgconfig/ragephoto.pc" @ONLY)
configure_file(src/libragephoto_global.h.in "${ragephoto_BINARY_DIR}/include/libragephoto_global.h" @ONLY)
list(APPEND RAGEPHOTO_HEADERS
"${ragephoto_BINARY_DIR}/include/libragephoto_global.h"
)
if (RAGEPHOTO_STATIC)
add_library(ragephoto STATIC ${RAGEPHOTO_HEADERS} ${RAGEPHOTO_SOURCES} ${RAGEPHOTO_STATIC_RESOURCES})
else()
add_library(ragephoto SHARED ${RAGEPHOTO_HEADERS} ${RAGEPHOTO_SOURCES} ${RAGEPHOTO_SHARED_RESOURCES})
set_target_properties(ragephoto PROPERTIES
PREFIX "lib"
)
endif()
target_compile_definitions(ragephoto PRIVATE
LIBRAGEPHOTO_LIBRARY
${LIBRAGEPHOTO_DEFINES}
)
target_include_directories(ragephoto PUBLIC
"${ragephoto_BINARY_DIR}/include"
"${ragephoto_SOURCE_DIR}/src"
)
install(TARGETS ragephoto
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
install(FILES ${RAGEPHOTO_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/RagePhoto")
if (UNIX)
install(FILES "${ragephoto_BINARY_DIR}/pkgconfig/ragephoto.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()
# RagePhoto WebAssembly Target
if (EMSCRIPTEN)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0")
add_executable(ragephoto-wasm ${RAGEPHOTO_HEADERS} ${RAGEPHOTO_SOURCES})
set_target_properties(ragephoto-wasm PROPERTIES
PREFIX "lib"
OUTPUT_NAME "ragephoto"
)
target_compile_definitions(ragephoto-wasm PRIVATE
LIBRAGEPHOTO_LIBRARY
${LIBRAGEPHOTO_DEFINES}
)
target_link_options(ragephoto-wasm PRIVATE
"SHELL:-O3"
"SHELL:--no-entry"
"SHELL:-s WASM=1"
"SHELL:-s ALLOW_MEMORY_GROWTH=1"
"SHELL:-s EXPORTED_FUNCTIONS=_free,_malloc"
"SHELL:-s EXPORTED_RUNTIME_METHODS=ccall,cwrap"
)
target_include_directories(ragephoto-wasm PUBLIC
${ragephoto_BINARY_DIR}/include
${ragephoto_SOURCE_DIR}/src
)
else()
message(WARNING "A useable WebAssembly build needs at least CMake 3.13.0 or newer")
endif()
endif()
# RagePhoto Documentation
option(RAGEPHOTO_DOC "Build libragephoto with documentation" OFF)
if (RAGEPHOTO_DOC)
add_subdirectory(doc)
endif()
# RagePhoto Examples
option(RAGEPHOTO_EXAMPLE_GTKVIEWER "Build libragephoto with GTK Photo Viewer" OFF)
if (RAGEPHOTO_EXAMPLE_GTKVIEWER)
add_subdirectory(examples/ragephoto-gtkviewer)
endif()
option(RAGEPHOTO_EXAMPLE_QTVIEWER "Build libragephoto with Qt Photo Viewer" OFF)
if (RAGEPHOTO_EXAMPLE_QTVIEWER)
add_subdirectory(examples/ragephoto-qtviewer)
endif()
# RagePhoto Extract Tool
option(RAGEPHOTO_EXTRACT "Build libragephoto with ragephoto-extract" ${RPTL_ON})
if (RAGEPHOTO_EXTRACT)
# RagePhoto-Extract Source files
if (RAGEPHOTO_C_API)
enable_language(C)
set(EXTRACT_SOURCES src/RagePhoto-Extract.c)
else()
set(EXTRACT_SOURCES src/RagePhoto-Extract.cpp)
endif()
# RagePhoto-Extract Win32 Shared Resources
if (WIN32)
string(TIMESTAMP ragephoto_BUILD_YEAR "%Y" UTC)
configure_file(src/ragephoto-extract.rc.in "${ragephoto_BINARY_DIR}/resources/ragephoto-extract.rc" @ONLY)
list(APPEND EXTRACT_RESOURCES
"${ragephoto_BINARY_DIR}/resources/ragephoto-extract.rc"
)
endif()
# RagePhoto-Extract Target + Installs
add_executable(ragephoto-extract ${RAGEPHOTO_HEADERS} ${EXTRACT_SOURCES} ${EXTRACT_RESOURCES})
set_target_properties(ragephoto-extract PROPERTIES
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
)
target_link_libraries(ragephoto-extract PRIVATE ragephoto)
install(TARGETS ragephoto-extract DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()