CMakeLists.txt 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Include apt-pkg directly, as some files have #include <system.h>
  2. include_directories(${PROJECT_BINARY_DIR}/include/apt-pkg)
  3. add_definitions("-DAPT_PKG_EXPOSE_STRING_VIEW")
  4. # Set the version of the library
  5. execute_process(COMMAND awk -v ORS=. "/^\#define APT_PKG_M/ {print \$3}"
  6. COMMAND sed "s/\\.\$//"
  7. INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/contrib/macros.h
  8. OUTPUT_VARIABLE MAJOR OUTPUT_STRIP_TRAILING_WHITESPACE)
  9. execute_process(COMMAND grep "^#define APT_PKG_RELEASE"
  10. COMMAND cut -d " " -f 3
  11. INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/contrib/macros.h
  12. OUTPUT_VARIABLE MINOR OUTPUT_STRIP_TRAILING_WHITESPACE)
  13. message(STATUS "Building libapt-pkg ${MAJOR} (release ${MINOR})")
  14. set(APT_PKG_MAJOR ${MAJOR} PARENT_SCOPE) # exporting for methods/CMakeLists.txt
  15. # Definition of the C++ files used to build the library
  16. file(GLOB_RECURSE library "*.cc")
  17. file(GLOB_RECURSE headers "*.h")
  18. # Create a library using the C++ files
  19. add_library(apt-pkg SHARED ${library})
  20. add_dependencies(apt-pkg apt-pkg-versionscript)
  21. # Link the library and set the SONAME
  22. target_include_directories(apt-pkg
  23. PRIVATE ${ZLIB_INCLUDE_DIRS}
  24. ${BZIP2_INCLUDE_DIR}
  25. ${LZMA_INCLUDE_DIRS}
  26. ${LZ4_INCLUDE_DIRS}
  27. ${ICONV_DIRECTORIES}
  28. )
  29. target_link_libraries(apt-pkg
  30. PRIVATE -lutil ${CMAKE_DL_LIBS} ${RESOLV_LIBRARIES}
  31. ${CMAKE_THREAD_LIBS_INIT}
  32. ${ZLIB_LIBRARIES}
  33. ${BZIP2_LIBRARIES}
  34. ${LZMA_LIBRARIES}
  35. ${LZ4_LIBRARIES}
  36. ${ICONV_LIBRARIES}
  37. )
  38. set_target_properties(apt-pkg PROPERTIES VERSION ${MAJOR}.${MINOR})
  39. set_target_properties(apt-pkg PROPERTIES SOVERSION ${MAJOR})
  40. add_version_script(apt-pkg)
  41. # Install the library and the header files
  42. install(TARGETS apt-pkg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
  43. install(FILES ${headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/apt-pkg)
  44. flatify(${PROJECT_BINARY_DIR}/include/apt-pkg/ "${headers}")