Skip to content

Instantly share code, notes, and snippets.

@chpf
Last active May 14, 2022 13:07
Show Gist options
  • Save chpf/76fed282d1d931592f5ce6456cfeb3e6 to your computer and use it in GitHub Desktop.
Save chpf/76fed282d1d931592f5ce6456cfeb3e6 to your computer and use it in GitHub Desktop.
Generate a raylib cmake project
#!/usr/bin/env python
from msilib.schema import Error
import subprocess
try:
subprocess.check_output(['git', '--version'], text=True)
subprocess.check_output(['cmake', '--version'], text=True)
except:
print("install git and cmake pls")
try:
subprocess.check_output(['git', 'init'], text=True)
subprocess.check_output(
['git', 'submodule', 'add', 'https://github.com/raysan5/raylib'], text=True)
except subprocess.CalledProcessError:
print("Git already cloned the files, if this is not the case delete everything in this folder except the generator script")
import os
try:
os.makedirs("src")
os.makedirs("out")
except OSError:
print ("Creation of the directories failed")
import shutil
try:
shutil.copyfile(os.path.join('raylib', 'examples', 'core', 'core_basic_window.c'), os.path.join('src', 'main.c'))
except shutil.ExecError:
print("failed to copy example file")
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("name", help="The project Name")
args = parser.parse_args()
project_name = args.name
cmake_content = f"""
cmake_minimum_required(VERSION 3.21)
set(CMAKE_SUPPRESS_REGENERATION)
project({project_name})
set(CMAKE_C_STANDARD 23)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "$(PROJECT_SOURCE_DIR)/out")
set(SOURCE_FILES
src/main.c
)
add_subdirectory(raylib)
add_executable({project_name} ${{SOURCE_FILES}})
target_link_libraries({project_name} PRIVATE raylib)
"""
with open('CMakeLists.txt', 'a') as cmake_file:
cmake_file.write(cmake_content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment