Skip to content

Commit

Permalink
build: fix invoking scan_enums.py
Browse files Browse the repository at this point in the history
The "scan_enums.py" script requires a Python v2 interpreter to be
available. The "CMakeLists.txt" simply searched for a Python
interpreter, which failed on modern Debian systems.

Instead of simply searching for "python", the CMake script was adjusted
to specifically search for a Python 2 interpreter, and then to
explicitly invoke that to run the "scan_enums.py" scripts.

Furthermore, a dependency was created to ensure that the script runs
before the "core-libs" package is compiled, and thus to ensure that any
compilations use the newly-generated versions of the files.

An improvement would be to remove "enum_tables.h" and "enum_tables.cpp"
from the repository, generate the files into the "build" directory, and
compile and link against those, although that would mean every developer
would need to have Python installed. This is currently optional as long
as no new enums are added which need to be accessed by Lua.
  • Loading branch information
mwerle committed Oct 6, 2024
1 parent 1213d00 commit 5bcbfd6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,15 @@ if (NATURALDOCS)
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
endif()

find_program(PYTHON NAMES python)
if (PYTHON)
find_package(Python2 COMPONENTS Interpreter)
if (Python2_Interpreter_FOUND)
add_custom_target(enums
COMMAND scripts/scan_enums.py -o src/enum_table.cpp --pattern='*.h' -r src
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
COMMAND "${Python2_EXECUTABLE}" scripts/scan_enums.py -o src/enum_table.cpp --pattern='*.h' -r src
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
add_dependencies(pioneer-core enums)
else()
message(WARNING, "Python 2 not found; enums will not be scanned.")
endif()

target_link_libraries(pioneer-lib PUBLIC lz4 fmt::fmt)
Expand Down

0 comments on commit 5bcbfd6

Please sign in to comment.