From 323a49a917724dd396d8b17ef5abbef5cfb9a9e4 Mon Sep 17 00:00:00 2001 From: Mooneer Salem Date: Fri, 27 Sep 2024 08:00:44 -0700 Subject: [PATCH] Use FindPython to find the correct Python in a non-distro specific manner. --- CMakeLists.txt | 19 ++++++++----------- src/CMakeLists.txt | 6 +++--- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2df4e4d..78cd11f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,17 +31,14 @@ endif("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") # Set default flags (from opus-ng build) set(CMAKE_C_FLAGS "-O2 -fvisibility=hidden -fstack-protector-strong -W -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes") -# Python tells us the CFLAGS we need for Embedding Python in a C lib -# The default PYTHON_CONFIG works on Ubuntu 22 but will likely need to be changed for other distros -if(NOT PYTHON_CONFIG) - set(PYTHON_CONFIG python3.10-config) -endif() -execute_process(COMMAND ${PYTHON_CONFIG} --cflags OUTPUT_VARIABLE PYTHON_C_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE) -execute_process(COMMAND ${PYTHON_CONFIG} --ldflags --embed OUTPUT_VARIABLE PYTHON_LD_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE) -string(STRIP ${PYTHON_C_FLAGS} PYTHON_C_FLAGS) -string(STRIP ${PYTHON_LD_LIBS} PYTHON_LD_LIBS) -message(PYTHON_C_FLAGS="${PYTHON_C_FLAGS}") -message(PYTHON_LD_LIBS="${PYTHON_LD_LIBS}") +# Python tells us the CFLAGS we need for Embedding Python in a C lib. +# We also need to make sure we select the libraries in any activated venv first, +# in case the user is using that for e.g. NumPy/PyTorch. +set(Python3_FIND_STRATEGY LOCATION) +set(Python_FIND_REGISTRY LAST) +set(CMAKE_FIND_FRAMEWORK LAST) +find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED) + add_subdirectory(src) # Ctests ---------------------------------------------------------------------- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ceba6df..5e6180f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,8 +4,8 @@ add_executable(lpcnet_demo lpcnet_demo.c) target_link_libraries(lpcnet_demo opus m) add_executable(radae_tx radae_tx.c rade_api.c) -set_source_files_properties(rade_api.c PROPERTIES COMPILE_FLAGS "${PYTHON_C_FLAGS}") -target_link_libraries(radae_tx ${PYTHON_LD_LIBS}) +#set_source_files_properties(rade_api.c PROPERTIES COMPILE_FLAGS "${PYTHON_C_FLAGS}") +target_link_libraries(radae_tx Python3::Python Python3::NumPy) add_executable(radae_rx radae_rx.c rade_api.c) -target_link_libraries(radae_rx ${PYTHON_LD_LIBS}) +target_link_libraries(radae_rx Python3::Python Python3::NumPy)