I am trying to built application that will be possible to load Python as shared library. For some reasons I need for this only Python headers of specific version.
CMakeLists.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
PROJECT(MDTest)
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)
SET(CMAKE_CXX_STANDARD 11)
SET(CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_EXTENSIONS OFF)
FIND_PACKAGE(Python3 REQUIRED COMPONENTS Development)
ADD_EXECUTABLE(mdtest main.cpp)
TARGET_INCLUDE_DIRECTORIES(mdtest PRIVATE ${Python3_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(mdtest PRIVATE dl)
shell.nix
{ pkgs ? import <nixpkgs>{} }:
with import <nixpkgs>{};
let
in pkgs.mkShell {
buildInputs = with pkgs; [
ccls
clang-tools
cmake
gdb
gcc
fish
mono
python37Full
tcl
tk
];
inputsFrom = with pkgs; [
];
runScript = "fish";
}
Makefile:
BUILD_DIR := ./build
CONFIGURATION ?= Debug
OUTPUT_DIR := ./output
EXECUTABLE_DIR ?= $(BUILD_DIR)/$(CONFIGURATION)
.PHONY: all
all: configure build
.PHONY: configure
configure:
@echo '{{{Start configuring}}}'
@mkdir --parents $(BUILD_DIR) \
&& cmake ./CMakeLists.txt \
-B$(BUILD_DIR) \
-DCMAKE_BUILD_TYPE=$(CONFIGURATION)
@cp $(BUILD_DIR)/compile_commands.json ./
.PHONY: build
build:
@echo '{{{Start building all}}}'
@cmake \
--build ${BUILD_DIR} \
--config $(CONFIGURATION) \
--parallel \
-- --silent # build-tool options
.PHONY: clean
clean:
@rm --recursive --force $(BUILD_DIR)
@rm --force ./compile_commands.json
In shell.nix environment python --version returns 3.7.15. In user environment it returns 3.9.15
But during building without specifing of Python version in CMake it found Python 3.9.19.
I understand that this question is more about CMake, but I am waiting that shell.nix environment will contains only it’s own Python.
NixOS 22.05.4267.f42a45c015f used.