1 # Include apt-pkg directly, as some files have #include <system.h>
2 include_directories(${PROJECT_BINARY_DIR}/include/apt-pkg)
4 add_definitions("-DAPT_PKG_EXPOSE_STRING_VIEW")
6 file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/include/apt-pkg/)
7 execute_process(COMMAND ${PROJECT_SOURCE_DIR}/triehash/triehash.pl
9 --header ${PROJECT_BINARY_DIR}/include/apt-pkg/tagfile-keys.h
10 --code ${CMAKE_CURRENT_BINARY_DIR}/tagfile-keys.cc
12 --enum-name pkgTagSection::Key
13 --function-name pkgTagHash
14 --include "<apt-pkg/tagfile.h>"
15 ${CMAKE_CURRENT_SOURCE_DIR}/tagfile-keys.list)
16 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "tagfile-keys.list")
19 # Set the version of the library
20 execute_process(COMMAND awk -v ORS=. "/^\#define APT_PKG_M/ {print \$3}"
21 COMMAND sed "s/\\.\$//"
22 INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/contrib/macros.h
23 OUTPUT_VARIABLE MAJOR OUTPUT_STRIP_TRAILING_WHITESPACE)
24 execute_process(COMMAND grep "^#define APT_PKG_RELEASE"
25 COMMAND cut -d " " -f 3
26 INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/contrib/macros.h
27 OUTPUT_VARIABLE MINOR OUTPUT_STRIP_TRAILING_WHITESPACE)
29 message(STATUS "Building libapt-pkg ${MAJOR} (release ${MINOR})")
30 set(APT_PKG_MAJOR ${MAJOR} PARENT_SCOPE) # exporting for methods/CMakeLists.txt
32 # Definition of the C++ files used to build the library
33 file(GLOB_RECURSE library "*.cc" "${CMAKE_CURRENT_BINARY_DIR}/tagfile-keys.cc")
34 file(GLOB_RECURSE headers "*.h")
36 # Create a library using the C++ files
37 add_library(apt-pkg SHARED ${library})
38 add_dependencies(apt-pkg apt-pkg-versionscript)
39 # Link the library and set the SONAME
40 target_include_directories(apt-pkg
41 PRIVATE ${ZLIB_INCLUDE_DIRS}
48 target_link_libraries(apt-pkg
49 PRIVATE -lutil ${CMAKE_DL_LIBS} ${RESOLV_LIBRARIES}
50 ${CMAKE_THREAD_LIBS_INIT}
57 set_target_properties(apt-pkg PROPERTIES VERSION ${MAJOR}.${MINOR})
58 set_target_properties(apt-pkg PROPERTIES SOVERSION ${MAJOR})
59 add_version_script(apt-pkg)
61 # Install the library and the header files
62 install(TARGETS apt-pkg LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
63 install(FILES ${headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/apt-pkg)
64 flatify(${PROJECT_BINARY_DIR}/include/apt-pkg/ "${headers}")
66 if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
67 target_link_libraries(apt-pkg PUBLIC noprofile)