Created
September 27, 2019 12:56
-
-
Save MartyLake/05c16f69f37e250b67d6aaaf05c50348 to your computer and use it in GitHub Desktop.
Generate compile_commands.json from a cmakelists.txt file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" a big WIP, as I discovered that VS2019 supports the export """ | |
import os | |
import subprocess | |
import shutil | |
import contextlib | |
import tempfile | |
SRC_DIR=(os.path.dirname(os.path.realpath(__file__))) | |
@contextlib.contextmanager | |
def make_temp_directory(): | |
temp_dir = tempfile.mkdtemp(suffix="generate_compile_commands_json") | |
try: | |
yield temp_dir | |
finally: | |
os.chdir(last_cwd) | |
with make_temp_directory() as TMP_DIR: | |
cmd = "cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -G Ninja \"{}\"".format(SRC_DIR) | |
process = subprocess.check_call(cmd, stdout=None, stderr=subprocess.STDOUT, cwd=TMP_DIR) | |
shutil.copyfile( | |
"{}/{}".format(TMP_DIR, "compile_commands.json"), | |
"{}/{}".format(SRC_DIR, "compile_commands.json"), | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment