From e3bc4980ca9b3f385a57408da4ddbe492670dc35 Mon Sep 17 00:00:00 2001 From: Robert Quill Date: Thu, 15 Aug 2024 08:59:00 +0100 Subject: [PATCH 1/3] Fix the build of the Python bindings. Signed-off-by: Robert Quill --- CMakeLists.txt | 3 +++ src/logger/CMakeLists.txt | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e777b85e..65b0d664 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,9 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# Set -fPIC so that ../lib/kp.cpython-310-x86_64-linux-gnu.so links correctly +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}") set(KOMPUTE_LIBRARIES kompute CACHE INTERNAL "") diff --git a/src/logger/CMakeLists.txt b/src/logger/CMakeLists.txt index 1f9b49ab..cb5abb9b 100644 --- a/src/logger/CMakeLists.txt +++ b/src/logger/CMakeLists.txt @@ -66,6 +66,10 @@ if(NOT KOMPUTE_OPT_LOG_LEVEL_DISABLED) else() target_link_libraries(kp_logger PUBLIC fmt::fmt) endif() + + if(KOMPUTE_OPT_BUILD_PYTHON) + target_link_libraries(kp_logger PUBLIC pybind11::pybind11) + endif() endif() From 1e8d2d0537b731491d9d71a22506cf6af3ed1342 Mon Sep 17 00:00:00 2001 From: Robert Quill Date: Thu, 15 Aug 2024 09:36:19 +0100 Subject: [PATCH 2/3] Don't link pybind11 into kp_logger Doing so is a partial fix for building with -DKOMPUTE_OPT_BUILD_TESTS=ON -DKOMPUTE_OPT_BUILD_PYTHON=ON but there are still undefined symbols at link time. Building either the tests or the Python bindings works correctly. Building both at the same time still does not work. Signed-off-by: Robert Quill --- src/logger/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/logger/CMakeLists.txt b/src/logger/CMakeLists.txt index cb5abb9b..1f9b49ab 100644 --- a/src/logger/CMakeLists.txt +++ b/src/logger/CMakeLists.txt @@ -66,10 +66,6 @@ if(NOT KOMPUTE_OPT_LOG_LEVEL_DISABLED) else() target_link_libraries(kp_logger PUBLIC fmt::fmt) endif() - - if(KOMPUTE_OPT_BUILD_PYTHON) - target_link_libraries(kp_logger PUBLIC pybind11::pybind11) - endif() endif() From 4bdfdb4a3f31379a91dfaaa8ee82a202b376a514 Mon Sep 17 00:00:00 2001 From: Robert Quill Date: Fri, 16 Aug 2024 12:20:22 +0100 Subject: [PATCH 3/3] Only build with -fPIC if KOMPUTE_OPT_BUILD_PYTHON=ON Position-independent code is only required when building a shared object. Signed-off-by: Robert Quill --- CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65b0d664..91082148 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,9 +18,6 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) -# Set -fPIC so that ../lib/kp.cpython-310-x86_64-linux-gnu.so links correctly -set(CMAKE_POSITION_INDEPENDENT_CODE ON) - set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}") set(KOMPUTE_LIBRARIES kompute CACHE INTERNAL "") @@ -127,6 +124,11 @@ include(cmake/vulkan_shader_compiler.cmake) include(cmake/check_vulkan_version.cmake) include(FetchContent) +# Set -fPIC so that ../lib/kp.cpython-310-x86_64-linux-gnu.so links correctly +if(KOMPUTE_OPT_BUILD_PYTHON) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() + # Vulkan Header # We don't import Vulkan library if Android build as it is built dynamically # Otherwise it is expected that the Vulkan SDK and dependencies are installed