Skip to content

Commit bb7b228

Browse files
build: Use Python venv by default
1 parent 1093479 commit bb7b228

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

build-support/custom-modules/ns3-check-dependencies.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ function(check_deps missing_deps)
4040
)
4141
if(NOT (${return_code} EQUAL 0))
4242
list(APPEND local_missing_deps ${package})
43+
else()
44+
# To make sure CMake import files can be found from venv site packages, we
45+
# manually add them to CMAKE_PREFIX_PATH
46+
execute_process(
47+
COMMAND
48+
${Python3_EXECUTABLE} -c
49+
"import os; import ${package}; print(os.path.abspath(os.path.dirname(${package}.__file__)))"
50+
OUTPUT_VARIABLE venv_site_packages_path
51+
)
52+
# Remove newlines (\n, \r, \r\n)
53+
string(REGEX REPLACE "[\r\n]+$" "" venv_site_packages_path
54+
"${venv_site_packages_path}"
55+
)
56+
if(EXISTS ${venv_site_packages_path})
57+
if(NOT (DEFINED CMAKE_PREFIX_PATH))
58+
set(CMAKE_PREFIX_PATH "" PARENT_SCOPE)
59+
endif()
60+
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};${venv_site_packages_path}"
61+
PARENT_SCOPE
62+
)
63+
endif()
4364
endif()
4465
endforeach()
4566

build-support/macros-and-definitions.cmake

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -628,16 +628,11 @@ macro(process_options)
628628
set(Python3_FOUND FALSE)
629629
set(Python3_INCLUDE_DIRS)
630630
set(Python3_Interpreter_FOUND FALSE)
631+
set(Python3_FIND_VIRTUALENV FIRST)
631632
if(${NS3_PYTHON_BINDINGS})
632633
find_package(Python3 COMPONENTS Interpreter Development)
633634
else()
634-
# If Python was not set yet, use the version found by check_deps
635-
check_deps(python3_deps EXECUTABLES python3)
636-
if(python3_deps)
637-
message(FATAL_ERROR "Python3 was not found")
638-
else()
639-
set(Python3_EXECUTABLE ${PYTHON3})
640-
endif()
635+
find_package(Python3 COMPONENTS Interpreter)
641636
endif()
642637

643638
# Check if both Python interpreter and development libraries were found

0 commit comments

Comments
 (0)