CMakeLists.txt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/include/apt-pkg/)
  5. execute_process(COMMAND ${PROJECT_SOURCE_DIR}/triehash/triehash.pl
  6. --ignore-case
  7. --header ${PROJECT_BINARY_DIR}/include/apt-pkg/tagfile-keys.h
  8. --code ${CMAKE_CURRENT_BINARY_DIR}/tagfile-keys.cc
  9. --enum-class
  10. --enum-name pkgTagSection::Key
  11. --function-name pkgTagHash
  12. --include "<apt-pkg/tagfile.h>"
  13. ${CMAKE_CURRENT_SOURCE_DIR}/tagfile-keys.list)
  14. set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "tagfile-keys.list")
  15. # Set the version of the library
  16. execute_process(COMMAND awk -v ORS=. "/^\#define APT_PKG_M/ {print \$3}"
  17. COMMAND sed "s/\\.\$//"
  18. INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/contrib/macros.h
  19. OUTPUT_VARIABLE MAJOR OUTPUT_STRIP_TRAILING_WHITESPACE)
  20. execute_process(COMMAND grep "^#define APT_PKG_RELEASE"
  21. COMMAND cut -d " " -f 3
  22. INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/contrib/macros.h
  23. OUTPUT_VARIABLE MINOR OUTPUT_STRIP_TRAILING_WHITESPACE)
  24. message(STATUS "Building libapt-pkg ${MAJOR} (release ${MINOR})")
  25. set(APT_PKG_MAJOR ${MAJOR} PARENT_SCOPE) # exporting for methods/CMakeLists.txt
  26. # Definition of the C++ files used to build the library
  27. file(GLOB_RECURSE library "*.cc" "${CMAKE_CURRENT_BINARY_DIR}/tagfile-keys.cc")
  28. file(GLOB_RECURSE headers "*.h")
  29. # Create a library using the C++ files
  30. add_library(apt-pkg SHARED ${library})
  31. #add_dependencies(apt-pkg apt-pkg-versionscript)
  32. # Link the library and set the SONAME
  33. target_include_directories(apt-pkg
  34. PRIVATE ${ZLIB_INCLUDE_DIRS}
  35. ${BZIP2_INCLUDE_DIR}
  36. ${LZMA_INCLUDE_DIRS}
  37. ${LZ4_INCLUDE_DIRS}
  38. ${ICONV_INCLUDE_DIRS}
  39. )
  40. target_link_libraries(apt-pkg
  41. PRIVATE -lutil ${CMAKE_DL_LIBS} ${RESOLV_LIBRARIES}
  42. ${CMAKE_THREAD_LIBS_INIT}
  43. ${ZLIB_LIBRARIES}
  44. ${BZIP2_LIBRARIES}
  45. ${LZMA_LIBRARIES}
  46. ${LZ4_LIBRARIES}
  47. ${ICONV_LIBRARIES}
  48. )
  49. set_target_properties(apt-pkg PROPERTIES VERSION ${MAJOR}.${MINOR})
  50. set_target_properties(apt-pkg PROPERTIES SOVERSION ${MAJOR})
  51. add_version_script(apt-pkg)
  52. # Install the library and the header files
  53. install(TARGETS apt-pkg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
  54. install(FILES ${headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/apt-pkg)
  55. flatify(${PROJECT_BINARY_DIR}/include/apt-pkg/ "${headers}")
  56. if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
  57. target_link_libraries(apt-pkg PUBLIC noprofile)
  58. endif()