forked from guillaumechereau/goxel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
124 lines (101 loc) · 3.69 KB
/
SConstruct
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Goxel 3D voxels editor
#
# copyright (c) 2018 Guillaume Chereau <guillaume@noctua-software.com>
#
# Goxel is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# Goxel is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# goxel. If not, see <http://www.gnu.org/licenses/>.
import glob
import os
import sys
target_os = str(Platform())
debug = int(ARGUMENTS.get('debug', 1))
profile = int(ARGUMENTS.get('profile', 0))
werror = int(ARGUMENTS.get("werror", 1))
clang = int(ARGUMENTS.get("clang", 0))
sound = False
if os.environ.get('CC') == 'clang': clang = 1
if profile: debug = 0
env = Environment(ENV = os.environ)
conf = env.Configure()
if clang:
env.Replace(CC='clang', CXX='clang++')
# Asan & Ubsan (need to come first).
if debug and target_os == 'posix':
env.Append(CCFLAGS=['-fsanitize=address', '-fsanitize=undefined'],
LINKFLAGS=['-fsanitize=address', '-fsanitize=undefined'],
LIBS=['asan', 'ubsan'])
# Global compilation flags.
# CCFLAGS : C and C++
# CFLAGS : only C
# CXXFLAGS : only C++
env.Append(
CFLAGS=['-std=gnu99', '-Wall',
'-Wno-unknow-pragma', '-Wno-unknown-warning-option'],
CXXFLAGS=['-std=gnu++17', '-Wall', '-Wno-narrowing']
)
if werror:
env.Append(CCFLAGS='-Werror')
if debug:
env.Append(CCFLAGS=['-O0'])
else:
env.Append(CCFLAGS=['-O3', '-DNDEBUG'])
if env['CC'] == 'gcc': env.Append(CCFLAGS='-Ofast')
if profile or debug:
env.Append(CCFLAGS='-g')
env.Append(CPPPATH=['src'])
env.Append(CCFLAGS='-include config.h')
# Get all the c and c++ files in src, recursively.
sources = []
for root, dirnames, filenames in os.walk('src'):
for filename in filenames:
if filename.endswith('.c') or filename.endswith('.cpp'):
sources.append(os.path.join(root, filename))
# Check for libpng.
if conf.CheckLibWithHeader('libpng', 'png.h', 'c'):
env.Append(CCFLAGS='-DHAVE_LIBPNG=1')
# Linux compilation support.
if target_os == 'posix':
env.Append(LIBS=['GL', 'm', 'z'])
# Note: add '--static' to link with all the libs needed by glfw3.
env.ParseConfig('pkg-config --libs glfw3')
env.ParseConfig('pkg-config --cflags --libs gtk+-3.0')
# Windows compilation support.
if target_os == 'msys':
env.Append(CXXFLAGS=['-Wno-attributes', '-Wno-unused-variable',
'-Wno-unused-function',
'-DFREE_WINDOWS'])
env.Append(LIBS=['glfw3', 'opengl32', 'Imm32', 'gdi32', 'Comdlg32',
'z', 'tre', 'intl', 'iconv'],
LINKFLAGS='--static')
sources += glob.glob('ext_src/glew/glew.c')
env.Append(CPPPATH=['ext_src/glew'])
env.Append(CCFLAGS='-DGLEW_STATIC')
# OSX Compilation support.
if target_os == 'darwin':
sources += glob.glob('src/*.m')
env.Append(FRAMEWORKS=['OpenGL', 'Cocoa'])
env.Append(LIBS=['m', 'z', 'glfw3', 'objc'])
# Add external libs.
env.Append(CPPPATH=['ext_src/uthash'])
env.Append(CPPPATH=['ext_src/stb'])
env.Append(CPPPATH=['ext_src/noc'])
if sound:
env.Append(LIBS='openal')
env.Append(CCFLAGS='-DSOUND=1')
# Append external environment flags
env.Append(
CFLAGS=os.environ.get("CFLAGS", "").split(),
CXXFLAGS=os.environ.get("CXXFLAGS", "").split(),
LINKFLAGS=os.environ.get("LDFLAGS", "").split()
)
env.Program(target='goxel', source=sources)