| 1 |
cmake_minimum_required (VERSION 3.1) |
| 2 |
project(zzipsdl VERSION "0.13.72" LANGUAGES C) |
| 3 |
|
| 4 |
if(NOT CMAKE_BUILD_TYPE) |
| 5 |
set(CMAKE_BUILD_TYPE Release) |
| 6 |
endif(NOT CMAKE_BUILD_TYPE) |
| 7 |
|
| 8 |
include ( GNUInstallDirs ) |
| 9 |
include ( FindPkgConfig ) |
| 10 |
|
| 11 |
# options ######################################################## |
| 12 |
option(BUILD_SHARED_LIBS "Build a shared library" ON) |
| 13 |
option(BUILD_STATIC_LIBS "Build the static library" OFF) |
| 14 |
option(BUILD_TESTS "Build test programs" OFF) |
| 15 |
option(MSVC_STATIC_RUNTIME "Build with static runtime libs (/MT)" ON) |
| 16 |
|
| 17 |
if(UNIX) |
| 18 |
option(ZZIP_LIBTOOL "Ensure binary compatibility with libtool" ON) |
| 19 |
option(ZZIP_PKGCONFIG "Generate pkg-config files for linking" ON) |
| 20 |
else() |
| 21 |
option(ZZIP_LIBTOOL "Ensure binary compatibility with libtool" OFF) |
| 22 |
option(ZZIP_PKGCONFIG "Generate pkg-config files for linking" OFF) |
| 23 |
endif() |
| 24 |
|
| 25 |
|
| 26 |
# Zlib library needed |
| 27 |
find_package ( ZLIB REQUIRED ) |
| 28 |
# pkg_search_module ( ZZIP zzip ) |
| 29 |
pkg_search_module ( SDL sdl2) |
| 30 |
|
| 31 |
# targets ######################################################## |
| 32 |
set(ZZIPSDL_SRCS |
| 33 |
SDL_rwops_zzip.c) |
| 34 |
|
| 35 |
set(ZZIPSDL_HDRS |
| 36 |
SDL_rwops_zzip.h) |
| 37 |
|
| 38 |
set(ZZCATSDL_SRCS |
| 39 |
${ZZIPSDL_SRCS} |
| 40 |
SDL_rwops_zzcat.c) |
| 41 |
|
| 42 |
if(SDL_FOUND) |
| 43 |
add_executable(zzcatsdl ${ZZCATSDL_SRCS} ) |
| 44 |
target_link_libraries(zzcatsdl libzzip "${SDL_LIBRARIES}" ZLIB::ZLIB) |
| 45 |
target_include_directories(zzcatsdl PRIVATE "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" "${SDL_INCLUDE_DIRS}") |
| 46 |
endif() |
| 47 |
|
| 48 |
# install ######################################################## |
| 49 |
if(SDL_FOUND) |
| 50 |
set(zzipsdldir "${CMAKE_INSTALL_INCLUDEDIR}/SDL_rwops_zzip") |
| 51 |
install(FILES ${ZZIPSDL_SRCS} ${ZZIPSDL_HDRS} |
| 52 |
DESTINATION ${zzipsdldir}) |
| 53 |
endif() |
| 54 |
|
| 55 |
# pkgconfig ###################################################### |
| 56 |
|
| 57 |
if(SDL_FOUND) |
| 58 |
if(ZZIP_PKGCONFIG) |
| 59 |
join_paths(libdir "\${prefix}" "${CMAKE_INSTALL_LIBDIR}") |
| 60 |
join_paths(includedir "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") |
| 61 |
join_paths(pc_zzipsdldir "\${prefix}" "${zzipsdldir}") |
| 62 |
add_custom_command(OUTPUT SDL_rwops_zzip.pc |
| 63 |
COMMAND ${BASH} -c "echo 'prefix=${CMAKE_INSTALL_PREFIX}' > SDL_rwops_zzip.pc" |
| 64 |
COMMAND ${BASH} -c "echo 'zzipsdldir=${pc_zzipsdldir}' >> SDL_rwops_zzip.pc" |
| 65 |
COMMAND ${BASH} -c "echo '' >> SDL_rwops_zzip.pc" |
| 66 |
COMMAND ${BASH} -c "echo 'Name: SDL_rwops_zzip' >> SDL_rwops_zzip.pc" |
| 67 |
COMMAND ${BASH} -c "echo 'Version: ${PROJECT_VERSION}' >> SDL_rwops_zzip.pc" |
| 68 |
COMMAND ${BASH} -c "echo 'Description: SDL_rwops for ZZipLib' >> SDL_rwops_zzip.pc" |
| 69 |
COMMAND ${BASH} -c "echo 'Requires: sdl, zziplib' >> SDL_rwops_zzip.pc" |
| 70 |
COMMAND ${BASH} -c "echo 'Cflags: -I\${zzipsdldir}' >> SDL_rwops_zzip.pc" |
| 71 |
VERBATIM) |
| 72 |
add_custom_target(pkgconfig-sdl ALL DEPENDS SDL_rwops_zzip.pc) |
| 73 |
|
| 74 |
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/SDL_rwops_zzip.pc |
| 75 |
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" ) |
| 76 |
endif(ZZIP_PKGCONFIG) |
| 77 |
endif(SDL_FOUND) |
| 78 |
|
| 79 |
# messages ################################################## |
| 80 |
|
| 81 |
message(STATUS "installing SDL_rwops_zzip example headers: ${SDL_FOUND}") |
| 82 |
message(STATUS "installing SDL_rwops_zzip pkgconfig files: ${ZZIP_PKGCONFIG}") |
| 83 |
|