CMakeLists.txt 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. target_link_libraries(apt-pkg
  28. PRIVATE -lutil -ldl -lresolv
  29. ${CMAKE_THREAD_LIBS_INIT}
  30. ${ZLIB_LIBRARIES}
  31. ${BZIP2_LIBRARIES}
  32. ${LZMA_LIBRARIES}
  33. ${LZ4_LIBRARIES})
  34. set_target_properties(apt-pkg PROPERTIES VERSION ${MAJOR}.${MINOR})
  35. set_target_properties(apt-pkg PROPERTIES SOVERSION ${MAJOR})
  36. add_version_script(apt-pkg)
  37. # Install the library and the header files
  38. install(TARGETS apt-pkg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
  39. install(FILES ${headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/apt-pkg)
  40. flatify(${PROJECT_BINARY_DIR}/include/apt-pkg/ "${headers}")