I'm going to use the Pybind11's cmake-example, since we want to use CMake with CLion.
First, download the repo
$ git clone --recursive https://github.com/pybind/cmake_example.git && cd cmake_example
From now on, I'm going to assume $ROOT is the path for this cmak_example repository.
Next, import the directory with CLion
CLion --> Open --> select $ROOT folder
Add symbols and turn off optimization for debugging by adding the following line to CMakeLists.txt file
cmake_minimum_required(VERSION 2.8.12)
project(cmake_example)
set(CMAKE_CXX_FLAGS "-g -O0")
add_subdirectory(pybind11)
pybind11_add_module(cmake_example src/main.cpp)
Edit Run/Debug configurations for cmake_exmaple as follows:
target: cmake_example
executable: /your/python3/binary
program arguments: tests/test.py
working directory: $ROOT
environment variables: PYTHONPATH=$ROOT/cmake-build
Now, debug with this configuration. You'll probably get version assert error. Let's just comment out that line in tests/test.py.
import cmake_example as m
#assert m.__version__ == '0.0.1'
assert m.add(1, 2) == 3
assert m.subtract(1, 2) == -1
Now, re-run debug with break point at line 4 of src/main.cpp.
CLion should break there!