Page 1 of 1

Understanding CMakeLists of GZDoom

Posted: Mon Sep 07, 2020 9:51 am
by RederickDeathwill
I'm trying to embed a Python interpreter in the GZDoom existing code base and I'm having trouble understanding the CMakeLists.txt. Here's my shell script to compile the source code:

Code: Select all

#!/bin/sh
a='' && [ "$(uname -m)" = x86_64 ] && a=64
c="$(lscpu -p | grep -v '#' | sort -u -t , -k 2,4 | wc -l)" ; [ "$c" -eq 0 ] && c=1
cd ./build &&
rm -f output_sdl/liboutput_sdl.so &&
if [ -d ../fmodapi44464linux ]; then
f="-DFMOD_LIBRARY=../fmodapi44464linux/api/lib/libfmodex${a}-4.44.64.so \
-DFMOD_INCLUDE_DIR=../fmodapi44464linux/api/inc"; else
f='-UFMOD_LIBRARY -UFMOD_INCLUDE_DIR'; fi &&
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/home/ericson/Workspace/ZMusic/build_install ..
cmake .. -DCMAKE_BUILD_TYPE=Release $f &&
make -j$c
The problem is, in order to embed the python interpreter, I need to user the "target_link_libraries" function on gzdoom, but I can't find the "add_executable" part of the CMakesList. There is an "add_custom_target" though, but that's not what I need to link to.

Where is gzdoom? (The final build) on the CMakesList?

Thanks for the help :)

Re: Understanding CMakeLists of GZDoom

Posted: Mon Sep 07, 2020 9:59 am
by _mental_

Re: Understanding CMakeLists of GZDoom

Posted: Mon Sep 07, 2020 10:31 am
by RederickDeathwill
Thank you! I've managed to make it work. It compiled, and a Hello World worked from Python. I've added this to the "D_DoomMain_Internal" function (It worked upon initialization):

Code: Select all

py::scoped_interpreter guard{}; // start the interpreter and keep it alive
py::print("Hello, World! GZDoom now runs Python :)"); // use the Python API

Re: Understanding CMakeLists of GZDoom

Posted: Mon Sep 07, 2020 12:31 pm
by m8f
Crazy stuff!

I have so many questions! Is it an experiment, or there is some serious plan?
Does it run from C++ side only, or from script side too, somehow?

Re: Understanding CMakeLists of GZDoom

Posted: Mon Sep 07, 2020 2:14 pm
by RederickDeathwill
m8f wrote:Crazy stuff!

I have so many questions! Is it an experiment, or there is some serious plan?
Does it run from C++ side only, or from script side too, somehow?
Well, it is an experiment, I have this dream of scripting Doom with Python for many years, but never had the technical skills to do it. I've had a lot of experience with Python in my job now (Apart from side projects on github) and I'm experimenting with the idea somewhat more seriously now, studying pybind11. I'm somewhat acquainted with Kate Fox's PyDoom, and in my opinion what she was trying to do was not the "ideal" (If there's such a thing) way of doing it. GZDoom is modern, pretty advanced and the product of many many years of community work, there's no reason to try to implement an entirely new source port only in Python. Pybind11 is a pretty fancy and modern solution to embedding Python to an existing C++ codebase, and yeah, that's exactly what I'm trying to do, I want to mess with the internal functions from Python externally without needing to recompile the code, and I'll probably do a lot of things wrong, but anyway, there's no reason not to do it :p

I've pushed a few hours ago this "Hello World" of mine (It's on d_main.cpp), you can clone my fork and test it if you want. I'll post my progress from time to time.