2023-02-24 21:24:33 +01:00
|
|
|
cmake_minimum_required(VERSION 3.12)
|
2019-07-17 11:25:29 +02:00
|
|
|
|
|
|
|
project(libspng C)
|
|
|
|
|
2022-08-18 11:32:39 +02:00
|
|
|
set(CMAKE_C_STANDARD 99)
|
|
|
|
|
2019-07-17 11:25:29 +02:00
|
|
|
set(SPNG_MAJOR 0)
|
2021-04-28 15:02:38 +02:00
|
|
|
set(SPNG_MINOR 7)
|
2023-05-08 16:45:20 +03:00
|
|
|
set(SPNG_REVISION 4)
|
2021-09-28 19:34:39 +02:00
|
|
|
set(SPNG_VERSION ${SPNG_MAJOR}.${SPNG_MINOR}.${SPNG_REVISION})
|
2019-07-17 11:25:29 +02:00
|
|
|
|
2019-07-22 10:33:52 +02:00
|
|
|
option(ENABLE_OPT "Enable architecture-specific optimizations" ON)
|
2019-07-17 11:25:29 +02:00
|
|
|
option(SPNG_SHARED "Build shared lib" ON)
|
|
|
|
option(SPNG_STATIC "Build static lib" ON)
|
2021-09-24 16:12:17 +02:00
|
|
|
option(BUILD_EXAMPLES "Build examples" ON)
|
2019-07-17 11:25:29 +02:00
|
|
|
|
|
|
|
include(GNUInstallDirs)
|
2023-02-24 21:24:33 +01:00
|
|
|
include(CMakePackageConfigHelpers)
|
2019-07-17 11:25:29 +02:00
|
|
|
|
2020-06-30 17:03:24 +02:00
|
|
|
if(NOT CMAKE_HOST_WIN32)
|
2023-02-24 21:24:33 +01:00
|
|
|
set(MATH_LIBRARY "m")
|
2020-06-30 17:03:24 +02:00
|
|
|
else()
|
2023-02-24 21:24:33 +01:00
|
|
|
set(MATH_LIBRARY "")
|
2020-06-30 17:03:24 +02:00
|
|
|
endif()
|
|
|
|
|
2019-07-22 10:33:52 +02:00
|
|
|
if(NOT ENABLE_OPT)
|
|
|
|
add_definitions( -DSPNG_DISABLE_OPT=1 )
|
2019-07-17 11:25:29 +02:00
|
|
|
endif()
|
|
|
|
|
2023-02-24 21:24:33 +01:00
|
|
|
set(spng_TARGETS "")
|
|
|
|
|
|
|
|
set(spng_SOURCES spng/spng.c)
|
|
|
|
|
2019-07-17 11:25:29 +02:00
|
|
|
if(SPNG_SHARED)
|
2020-08-14 13:10:38 +02:00
|
|
|
add_library(spng SHARED ${spng_SOURCES})
|
2023-02-24 21:24:33 +01:00
|
|
|
list(APPEND spng_TARGETS spng)
|
2020-07-02 19:16:07 +02:00
|
|
|
|
2021-09-24 16:12:17 +02:00
|
|
|
if(BUILD_EXAMPLES)
|
|
|
|
add_executable(example examples/example.c)
|
2023-02-24 21:24:33 +01:00
|
|
|
target_link_libraries(example PRIVATE spng)
|
2021-09-24 16:12:17 +02:00
|
|
|
endif()
|
2019-07-17 11:25:29 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(SPNG_STATIC)
|
2020-08-14 13:10:38 +02:00
|
|
|
add_library(spng_static STATIC ${spng_SOURCES})
|
2020-07-02 19:07:27 +02:00
|
|
|
target_compile_definitions(spng_static PUBLIC SPNG_STATIC)
|
2023-02-24 21:24:33 +01:00
|
|
|
list(APPEND spng_TARGETS spng_static)
|
2019-07-17 11:25:29 +02:00
|
|
|
endif()
|
|
|
|
|
2023-02-24 21:24:33 +01:00
|
|
|
find_package(ZLIB REQUIRED)
|
|
|
|
foreach(spng_TARGET ${spng_TARGETS})
|
|
|
|
target_include_directories(${spng_TARGET} PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/spng>
|
|
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
|
|
|
)
|
|
|
|
target_link_libraries(${spng_TARGET} PRIVATE ZLIB::ZLIB)
|
|
|
|
target_link_libraries(${spng_TARGET} PRIVATE ${MATH_LIBRARY})
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
set(project_config "${CMAKE_CURRENT_BINARY_DIR}/SPNGConfig.cmake")
|
|
|
|
set(project_version_config "${CMAKE_CURRENT_BINARY_DIR}/SPNGConfigVersion.cmake")
|
|
|
|
set(targets_export_name SPNGTargets)
|
|
|
|
set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/spng")
|
|
|
|
|
|
|
|
configure_package_config_file(cmake/Config.cmake.in ${project_config}
|
|
|
|
INSTALL_DESTINATION ${config_install_dir}
|
|
|
|
)
|
|
|
|
|
|
|
|
write_basic_package_version_file(${project_version_config}
|
|
|
|
VERSION ${SPNG_VERSION}
|
|
|
|
COMPATIBILITY SameMajorVersion
|
|
|
|
)
|
|
|
|
|
|
|
|
install(
|
|
|
|
TARGETS ${spng_TARGETS}
|
|
|
|
EXPORT ${targets_export_name}
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
|
|
)
|
|
|
|
|
|
|
|
install(FILES spng/spng.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
|
|
|
|
|
|
install(
|
|
|
|
FILES ${project_config} ${project_version_config}
|
|
|
|
DESTINATION ${config_install_dir}
|
|
|
|
)
|
|
|
|
|
|
|
|
install(
|
|
|
|
EXPORT ${targets_export_name}
|
|
|
|
NAMESPACE "spng::"
|
|
|
|
DESTINATION ${config_install_dir}
|
|
|
|
)
|
2019-07-17 11:25:29 +02:00
|
|
|
|
|
|
|
if(NOT CMAKE_HOST_WIN32 OR CYGWIN OR MINGW)
|
|
|
|
set(prefix ${CMAKE_INSTALL_PREFIX})
|
|
|
|
set(exec_prefix ${CMAKE_INSTALL_PREFIX})
|
|
|
|
set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
|
|
|
|
set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
|
2023-02-24 21:24:33 +01:00
|
|
|
set(LIBS "-lm")
|
2019-07-17 11:25:29 +02:00
|
|
|
|
2023-02-24 21:24:33 +01:00
|
|
|
foreach(libname ${spng_TARGETS})
|
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/libspng.pc.in ${CMAKE_CURRENT_BINARY_DIR}/cmake/lib${libname}.pc @ONLY)
|
2019-07-17 11:25:29 +02:00
|
|
|
|
2023-02-24 21:24:33 +01:00
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/lib${libname}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
|
|
|
endforeach()
|
2019-07-17 11:25:29 +02:00
|
|
|
endif()
|