Skip to content

Instantly share code, notes, and snippets.

@bmegli
Forked from Meltwin/change_cpp.py
Last active April 29, 2025 13:26
Show Gist options
  • Select an option

  • Save bmegli/c93e78483231297746a8086349b16414 to your computer and use it in GitHub Desktop.

Select an option

Save bmegli/c93e78483231297746a8086349b16414 to your computer and use it in GitHub Desktop.

Revisions

  1. bmegli revised this gist Apr 29, 2025. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions change_cpp.py
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,7 @@
    print()

    REPLACE_FILTER = {
    "-std=c++0x":"-std=c++17",
    "-std=c++11":"-std=c++17",
    "-std=c++14":"-std=c++17",
    "COMPILER_SUPPORTS_CXX11": "COMPILER_SUPPORTS_CXX17",
  2. bmegli revised this gist Apr 24, 2025. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions change_cpp.py
    Original file line number Diff line number Diff line change
    @@ -35,12 +35,13 @@ def fix_cmakelist(cmakelist_path: str) -> None:
    print(f"{Fore.GREEN}Fixed !" if changed else f"{Fore.BLUE}Nothing to change")

    def walk_dir(dir: str, depth = 0) -> None:
    if depth >=2:
    if depth >=5:
    return
    for d in os.listdir(dir):
    cmakelist_path = f"{dir}/{d}/CMakeLists.txt"
    if not os.path.isfile(cmakelist_path):
    walk_dir(f"{dir}/{d}", depth+1)
    if os.path.isdir(f"{dir}/{d}") :
    walk_dir(f"{dir}/{d}", depth+1)
    else :
    fix_cmakelist(cmakelist_path)

  3. bmegli revised this gist Apr 22, 2025. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions change_cpp.py
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,7 @@

    REPLACE_FILTER = {
    "-std=c++11":"-std=c++17",
    "-std=c++14":"-std=c++17",
    "COMPILER_SUPPORTS_CXX11": "COMPILER_SUPPORTS_CXX17",
    "CMAKE_CXX_STANDARD 11": "CMAKE_CXX_STANDARD 17",
    "CMAKE_CXX_STANDARD 14": "CMAKE_CXX_STANDARD 17"
  4. @Meltwin Meltwin created this gist May 4, 2023.
    48 changes: 48 additions & 0 deletions change_cpp.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    import os
    from colorama import Fore, Style

    WANTED_WIDTH = 100
    DISPLAY_WIDTH = min(WANTED_WIDTH, os.get_terminal_size().columns - 2)
    print("┏" + "".center(DISPLAY_WIDTH, "━") + "┓")
    print(f"┃{Fore.RED}" + "CMakeLists to C++17 Utils".center(DISPLAY_WIDTH, " ") + f"{Style.RESET_ALL}┃")
    print(f"┃{Style.BRIGHT+ Fore.BLACK}" + "Meltwin - 2023".center(DISPLAY_WIDTH, " ") + f"{Style.RESET_ALL}┃")
    print("┗" + "".center(DISPLAY_WIDTH, "━") + "┛")
    print()

    REPLACE_FILTER = {
    "-std=c++11":"-std=c++17",
    "COMPILER_SUPPORTS_CXX11": "COMPILER_SUPPORTS_CXX17",
    "CMAKE_CXX_STANDARD 11": "CMAKE_CXX_STANDARD 17",
    "CMAKE_CXX_STANDARD 14": "CMAKE_CXX_STANDARD 17"
    }

    def fix_cmakelist(cmakelist_path: str) -> None:
    print(f"{Fore.YELLOW}{Fore.RESET}Found {Fore.RED}{cmakelist_path}{Fore.RESET}", end=" ")
    with open(cmakelist_path, "r") as handle:
    data = handle.read()

    # Replacing
    changed = False
    for key, value in REPLACE_FILTER.items():
    if data.find(key) != -1:
    data = data.replace(key, value)
    changed = True

    if changed:
    with open(cmakelist_path, "w") as handle:
    handle.write(data)
    print(f"{Fore.GREEN}Fixed !" if changed else f"{Fore.BLUE}Nothing to change")

    def walk_dir(dir: str, depth = 0) -> None:
    if depth >=2:
    return
    for d in os.listdir(dir):
    cmakelist_path = f"{dir}/{d}/CMakeLists.txt"
    if not os.path.isfile(cmakelist_path):
    walk_dir(f"{dir}/{d}", depth+1)
    else :
    fix_cmakelist(cmakelist_path)

    if __name__ == "__main__":
    # Get all the CMakeLists.txt
    walk_dir("./src")