Skip to content

Instantly share code, notes, and snippets.

@rubenwardy
Last active January 22, 2020 14:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rubenwardy/ca265e7405952b6031f5 to your computer and use it in GitHub Desktop.
Save rubenwardy/ca265e7405952b6031f5 to your computer and use it in GitHub Desktop.
Create CMakeLists
#!/usr/bin/python
# I recommend that you install it and run it:
# $ sudo cp init_cmake.py /usr/bin
# $ init_cmake
import os
print("Initialise CMAKE by rubenwardy")
project_name = raw_input("Project name: ")
res = """# Set up project
cmake_minimum_required(VERSION 2.6)
project(""" + project_name +""")
# Source files
set(PROJECT_SRC
"""
def doDir(dir):
ret = ""
for file in os.listdir(dir + "."):
if file.endswith(".cpp"):
ret = ret + "\t" + dir + file + "\n"
elif os.path.isdir(dir + file) and dir is not None and file is not None:
ret = ret + doDir(dir + file + "/")
return ret
res = res + doDir("") + """)
add_executable(${PROJECT_NAME} ${PROJECT_SRC})
file(MAKE_DIRECTORY "bin")
set_target_properties(${PROJECT_NAME}
PROPERTIES
OUTPUT_NAME bin/""" + project_name + """)
# Install DLLs
install (TARGETS ${PROJECT_NAME} DESTINATION bin)
"""
fo = open("CMakeLists.txt", "w")
fo.write(res)
fo.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment