|
| 1 | +cmake_minimum_required(VERSION 3.4) |
| 2 | +project(libopk LANGUAGES C VERSION 1.0) |
| 3 | + |
| 4 | +include(GNUInstallDirs) |
| 5 | + |
| 6 | +set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig" |
| 7 | + CACHE PATH "Installation directory for pkgconfig (.pc) files") |
| 8 | + |
| 9 | +if (CMAKE_COMPILER_IS_GNUCC) |
| 10 | + add_compile_options(-fvisibility=hidden -Wall -Wextra) |
| 11 | +endif () |
| 12 | + |
| 13 | +find_package(PkgConfig REQUIRED) |
| 14 | +pkg_check_modules(INI QUIET libini) |
| 15 | +if (NOT INI_FOUND) |
| 16 | + message(FATAL_ERROR "Missing dependency: libini") |
| 17 | +endif() |
| 18 | + |
| 19 | +link_directories(${INI_LIBRARY_DIRS}) |
| 20 | +include_directories(${INI_INCLUDE_DIRS}) |
| 21 | + |
| 22 | +pkg_check_modules(ZLIB QUIET zlib) |
| 23 | +if (ZLIB_FOUND) |
| 24 | + add_compile_definitions(USE_GZIP) |
| 25 | + link_directories(${ZLIB_LIBRARY_DIRS}) |
| 26 | + include_directories(${ZLIB_INCLUDE_DIRS}) |
| 27 | +endif (ZLIB_FOUND) |
| 28 | + |
| 29 | +add_library(opk SHARED libopk.c unsqfs.c opk.h unsqfs.h) |
| 30 | +add_executable(opkinfo opkinfo.c) |
| 31 | +add_executable(opkrun opkrun.c) |
| 32 | + |
| 33 | +set_target_properties(opk opkinfo opkrun PROPERTIES |
| 34 | + C_STANDARD 11 |
| 35 | + C_STANDARD_REQUIRED ON |
| 36 | + C_EXTENSIONS OFF |
| 37 | +) |
| 38 | + |
| 39 | +set_target_properties(opk PROPERTIES |
| 40 | + VERSION ${PROJECT_VERSION} |
| 41 | + SOVERSION ${PROJECT_VERSION_MAJOR} |
| 42 | + PUBLIC_HEADER opk.h |
| 43 | +) |
| 44 | + |
| 45 | +target_link_libraries(opk LINK_PRIVATE ${INI_LIBRARIES} ${ZLIB_LIBRARIES}) |
| 46 | +target_link_libraries(opkinfo opk) |
| 47 | +target_link_libraries(opkrun opk) |
| 48 | + |
| 49 | +configure_file(libopk.pc.cmakein libopk.pc @ONLY) |
| 50 | +install(FILES ${CMAKE_BINARY_DIR}/libopk.pc DESTINATION "${INSTALL_PKGCONFIG_DIR}") |
| 51 | + |
| 52 | +set(SETUP_PY ${CMAKE_SOURCE_DIR}/bindings/python/setup.py) |
| 53 | +configure_file(${SETUP_PY}.cmakein ${SETUP_PY} @ONLY) |
| 54 | + |
| 55 | +install(TARGETS opk opkinfo opkrun |
| 56 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 57 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 58 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 59 | + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 60 | +) |
0 commit comments