Skip to content

Instantly share code, notes, and snippets.

@behrtam
Created November 3, 2013 10:46
Show Gist options
  • Save behrtam/7288914 to your computer and use it in GitHub Desktop.
Save behrtam/7288914 to your computer and use it in GitHub Desktop.
Instead of writing down the needed cpp-files manually, it just takes all the cpp-files of the current directory.
"""
This Auto-SConstruct takes alle *.cpp files of the current directory - the directory the SContruct is placed in.
The program name is based on the name of a file ending with '_main.cpp'.
Example: 'myprog_main.cpp' -> 'myprog'
If there is a file eding with '_test.cpp' a google testprogram is compiled with a similar naming process.
Example: 'mytest_main.cpp' -> 'mytest'
author: Tammo Behrends (2013)
"""
import os
include_files = ['.']
shared_libraries = ['m', 'gtest', 'gtest_main']
cpp_standard = ['-std=c++98', '-pedantic']
warnings = ['-Wall', '-Wextra', '-Werror']
std = Environment(
CXXFLAGS = cpp_standard + warnings,
CPPPATH = include_files,
LIBS = shared_libraries
)
cpp_files = [file_name for file_name in os.listdir(".") if file_name.endswith(".cpp")]
main_cpp = [file_name for file_name in cpp_files if file_name.endswith("_main.cpp")]
test_cpp = [file_name for file_name in cpp_files if file_name.endswith("_test.cpp")]
if main_cpp and len(main_cpp) == 1:
program_name = main_cpp[0].split('_')[0]
std.Program(program_name + '_test', cpp_files)
if test_cpp and len(test_cpp) == 1:
testprogram_name = test_cpp[0].split('_')[0]
std.Program(program_name, cpp_files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment