1- cmake_minimum_required (VERSION 3.10 )
1+ cmake_minimum_required (VERSION 3.15 )
22
33project (createrepo-agent C)
44
@@ -35,6 +35,7 @@ target_link_libraries(createrepo-cache PUBLIC
3535target_compile_definitions (createrepo-cache PRIVATE
3636 -DG_LOG_DOMAIN="CREATEREPO_CACHE" )
3737set_target_properties (createrepo-cache PROPERTIES
38+ POSITION_INDEPENDENT_CODE ON
3839 SOVERSION ${CRA_VERSION_MAJOR}
3940 VERSION ${CRA_VERSION} )
4041
@@ -60,6 +61,8 @@ target_link_libraries(createrepo-agent-lib PUBLIC
6061 glib-2.0)
6162target_compile_definitions (createrepo-agent-lib PRIVATE
6263 -DG_LOG_DOMAIN="CREATEREPO_AGENT" )
64+ set_target_properties (createrepo-agent-lib PROPERTIES
65+ POSITION_INDEPENDENT_CODE ON )
6366
6467# Executable
6568add_executable (${PROJECT_NAME}
@@ -75,6 +78,73 @@ install(TARGETS ${PROJECT_NAME}
7578 RUNTIME DESTINATION bin
7679 COMPONENT bin)
7780
81+ # Python bindings
82+ cmake_policy (SET CMP0094 NEW)
83+ set (Python_FIND_UNVERSIONED_NAMES FIRST
84+ CACHE STRING "Defines how the generic names will be searched for Python" )
85+ if (CMAKE_VERSION VERSION_LESS "3.18" )
86+ set (Python_COMPONENTS Interpreter Development)
87+ else ()
88+ set (Python_COMPONENTS Interpreter Development.Module)
89+ endif ()
90+ find_package (Python 3 QUIET COMPONENTS ${Python_COMPONENTS} )
91+ option (WITH_PYTHON "Build Python bindings" ${Python_FOUND} )
92+ if (WITH_PYTHON)
93+ # Find Python again, this time REQUIRED
94+ find_package (Python 3 REQUIRED COMPONENTS ${Python_COMPONENTS} )
95+
96+ python_add_library(createrepo_agent MODULE
97+ src/python/client.c
98+ src/python/init.c
99+ src/python/server.c)
100+ target_link_libraries (createrepo_agent PRIVATE
101+ createrepo-agent-lib)
102+
103+ if (SKBUILD)
104+ set (PYTHON_INSTALL_DIR ${SKBUILD_PLATLIB_DIR} )
105+ else ()
106+ # Determine package installation location
107+ string (JOIN "; " PYTHON_INSTALL_DIR_CMD
108+ "from os.path import sep"
109+ "from sys import stdout"
110+ "from sysconfig import get_path"
111+ "stdout.write(get_path('platlib', vars={'base': '', 'platbase': ''}).lstrip(sep))"
112+ )
113+ execute_process (COMMAND ${Python_EXECUTABLE} -c "${PYTHON_INSTALL_DIR_CMD} "
114+ OUTPUT_VARIABLE PYTHON_INSTALL_DIR)
115+
116+ set (DISTINFO_NAME "createrepo_agent-${CRA_VERSION} .dist-info" )
117+ set (DISTINFO_DIR "${CMAKE_CURRENT_BINARY_DIR} /${DISTINFO_NAME} " )
118+ file (GENERATE
119+ OUTPUT "${DISTINFO_DIR} /INSTALLER"
120+ CONTENT "cmake\n " )
121+ file (GENERATE
122+ OUTPUT "${DISTINFO_DIR} /METADATA"
123+ CONTENT "Metadata-Version: 1.1\n Name: createrepo-agent\n Version: ${CRA_VERSION} \n " )
124+ string (JOIN "\n " RECORD_CONTENT
125+ "$<TARGET_FILE_NAME:createrepo_agent>,,"
126+ "${DISTINFO_NAME} /INSTALLER,,"
127+ "${DISTINFO_NAME} /METADATA,,"
128+ "${DISTINFO_NAME} /RECORD,,"
129+ "${DISTINFO_NAME} /top_level.txt,,"
130+ )
131+ file (GENERATE
132+ OUTPUT "${DISTINFO_DIR} /RECORD"
133+ CONTENT "${RECORD_CONTENT} \n " )
134+ file (GENERATE
135+ OUTPUT "${DISTINFO_DIR} /top_level.txt"
136+ CONTENT "createrepo_agent\n " )
137+ install (DIRECTORY ${DISTINFO_DIR}
138+ DESTINATION ${PYTHON_INSTALL_DIR}
139+ COMPONENT python)
140+ endif ()
141+
142+ install (TARGETS createrepo_agent
143+ RUNTIME DESTINATION ${PYTHON_INSTALL_DIR}
144+ LIBRARY DESTINATION ${PYTHON_INSTALL_DIR}
145+ COMPONENT python)
146+ endif ()
147+
78148add_subdirectory (doc )
79149
80150set (MEMORYCHECK_SUPPRESSIONS_FILE "${CMAKE_CURRENT_SOURCE_DIR} /test/valgrind.supp"
0 commit comments