Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ cmake_minimum_required(VERSION 3.21)
project(Quidditch C CXX)

set(QUIDDITCH_TOOLCHAIN_FILE "" CACHE FILEPATH "Path to the quidditch toolchain's toolchain file")
set(OVERRIDE_VENV OFF CACHE BOOL "")
cmake_path(REMOVE_FILENAME QUIDDITCH_TOOLCHAIN_FILE OUTPUT_VARIABLE QUIDDITCH_TOOLCHAIN_ROOT)

if (NOT DEFINED ENV{VIRTUAL_ENV} AND NOT ${OVERRIDE_VENV})
message(FATAL_ERROR [[
Please use a virtual environment as this cmake script will call pip install.
Reconfigure with -DOVERRIDE_VENV=ON if this is a false positive or you don't
care.
]])
return()
endif ()
# TODO: allow influencing this from the commandline invocation during configuration
set(QUIDDITCH_VENV_DIR "${CMAKE_CURRENT_SOURCE_DIR}/venv")

find_package (Python3 COMPONENTS Interpreter)
execute_process (COMMAND "${Python3_EXECUTABLE}" -m venv "${QUIDDITCH_VENV_DIR}")

# based on: https://tinyurl.com/4rep5yd4
# update the environment with VIRTUAL_ENV variable (mimic the activate script)
set (ENV{VIRTUAL_ENV} "${QUIDDITCH_VENV_DIR}")
# change the context of the search
set (Python3_FIND_VIRTUALENV FIRST)
# unset Python3_EXECUTABLE because it is also an input variable (see documentation, Artifacts Specification section)
unset (Python3_EXECUTABLE)
# launch a new search
find_package (Python3 COMPONENTS Interpreter Development)

set(Python3_FIND_VIRTUALENV "FIRST")
find_package(Python3 REQUIRED)
execute_process(
COMMAND "${Python3_EXECUTABLE}" -m pip install -r ${CMAKE_CURRENT_LIST_DIR}/requirements.txt
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} COMMAND_ERROR_IS_FATAL ANY)
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ mkdir toolchain
docker run --rm ghcr.io/opencompl/quidditch/toolchain:main tar -cC /opt/quidditch-toolchain .\
| tar -xC ./toolchain

python -m venv venv
source ./venv/bin/activate

mkdir build && cd build
cmake .. -GNinja \
# Optional but highly recommended \
Expand Down
Loading