Skip to content

Instantly share code, notes, and snippets.

@Kojirion
Created March 25, 2016 00:08
Show Gist options
  • Save Kojirion/5fda45c0204be472b783 to your computer and use it in GitHub Desktop.
Save Kojirion/5fda45c0204be472b783 to your computer and use it in GitHub Desktop.
Automatically generate CMakeLists.txt for a SFML project
from os import listdir
f = open("CMakeLists.txt", "w")
f.write(
"""project(Foo)
cmake_minimum_required(VERSION 2.8)
list(APPEND CMAKE_MODULE_PATH \"${CMAKE_CURRENT_LIST_DIR}/cmake\")
find_package(SFML 2 REQUIRED graphics window system)
include_directories(${SFML_INCLUDE_DIR})\n\n""")
headers = []
sources = []
for w in listdir():
if w[-2:]=='.h':
headers.append(w)
elif w[-4:]=='.cpp':
sources.append(w)
f.write("set(HDRS\n")
for header in headers:
f.write("\t"+header+"\n")
f.write(")\n\n")
f.write("set(SRCS\n")
for source in sources:
f.write("\t"+source+"\n")
f.write(")\n\n")
f.write("""add_executable(${PROJECT_NAME} ${HDRS} ${SRCS})
target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES})
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX})
FILE(GLOB images "*.png")
install(FILES ${images} DESTINATION ${CMAKE_INSTALL_PREFIX})
FILE(GLOB fonts "*.ttf")
install(FILES ${fonts} DESTINATION ${CMAKE_INSTALL_PREFIX})""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment