-
Notifications
You must be signed in to change notification settings - Fork 11
/
configure.py
executable file
·980 lines (891 loc) · 31.8 KB
/
configure.py
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
#!/usr/bin/python3
# coding=utf-8
# Copyright Matus Chochlik.
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt
#
import os
import sys
import json
import stat
import string
import getopt
import shutil
import subprocess
from tools import args
from tools import paths
# initial values for the configuration options
# returns a normalized path to the project root directory
def get_root_dir():
import sys
return os.path.normpath(os.path.dirname(sys.argv[0]))
# returns the path to the default build directory
def get_default_build_dir():
try:
try:
if os.environ['BUILD_DIR']:
return os.path.join(os.environ['BUILD_DIR'], 'oglplu2')
if os.environ['BINARY_DIR']:
return os.path.join(os.environ['BINARY_DIR'], 'oglplu2')
except: pass
with open(os.path.join(get_root_dir(), "BINARY_DIR"), "rt") as bdf:
return bdf.read()
except: return os.path.join(get_root_dir(), "_build");
def get_argument_parser():
import argparse
def BoolArgValue(arg):
if(arg in ("True", "true", "Yes", "yes", "Y", "On", "1")):
return True
elif(arg in ("False", "false", "No", "no", "N", "Off", "0")):
return False
else:
msg = "'%s' is not a valid boolean value" % str(arg)
raise argparse.ArgumentTypeError(msg)
def JobCountValue(arg):
msg_fmt = "'%s' is not a valid process count value"
try:
if int(arg) <= 0:
msg = msg_fmt % str(arg)
raise argparse.ArgumentTypeError(msg)
else:
return int(arg)
except:
msg = msg_fmt % str(arg)
raise argparse.ArgumentTypeError(msg)
def OpenGLVersionValue(arg):
import re
match = re.match("^([3-9]).([0-9])$", arg)
if match:
return match.group(1)+"_"+match.group(2)
else:
msg = "'%s' is not a supported OpenGL version" % str(arg)
raise argparse.ArgumentTypeError(msg)
CMakeGeneratorValue = str
version_file = os.path.join(os.path.dirname(sys.argv[0]), "VERSION")
try: version = open(version_file, "r").read().strip()
except: version = str("<unknown>")
argparser = argparse.ArgumentParser(
prog="configure",
description="""
Configuration script for the OGLplus library (version %(version)s)
""" % { "version" : version },
epilog="""
Copyright (c) Matúš Chochlík.
Permission is granted to copy, distribute and/or modify this document
under the terms of the Boost Software License, Version 1.0.
(See a copy at http://www.boost.org/LICENSE_1_0.txt)
"""
)
argparser.add_argument(
"--generate-bash-complete",
action="store_true",
help="""
Generates bash completion script for this configure script and quits.
For internal use only.
"""
)
argparser.add_argument(
"--generate-manual",
action="store_true",
help="""
Generates a man-compatible manual.
For internal use only.
"""
)
argparser.add_argument(
"--config-type",
dest="config_types",
choices=["Debug", "Release"],
action="append",
default=list(),
help="""
Determines the build configuration (default = %(default)s).
"""
)
argparser.add_argument(
"--debug",
dest="config_types",
action="append_const",
const="Debug",
default=list(),
help="""
Configures for the 'Debug' build type.
"""
)
argparser.add_argument(
"--release",
dest="config_types",
action="append_const",
const="Release",
default=list(),
help="""
Configures for the 'Release' build type.
"""
)
argparser.add_argument(
"--prefix",
dest="install_prefix",
type=os.path.abspath,
action="store",
help="""
Specifies the installation prefix. The path must be absolute or
relative to the current working directory from which %(prog)s is
invoked.
"""
)
argparser.add_argument(
"--build-dir",
type=os.path.abspath,
default=get_default_build_dir(),
action="store",
help="""
Specifies the work directory for cmake, where the cached files,
generated makefiles and the intermediate build files will be
placed. The specified path must be either absolute or
relative to the current working directory from which %(prog)s
is invoked (default = '%(default)s').
"""
)
argparser.add_argument(
"--include-dir", "-I",
dest="include_dirs",
type=os.path.abspath,
action="append",
default=list(),
help="""
Specifies additional directory to search when looking for external
headers like GL/glew.h or GL3/gl3.h. The specified path
must be absolute or relative to the current working directory
from which %(prog)s is invoked. This option may be specified
multiple times to add multiple directories to the search list.
"""
)
argparser.add_argument(
"--library-dir", "-L",
dest="library_dirs",
type=os.path.abspath,
action="append",
default=list(),
help="""
Specifies additional directory to search when looking for compiled
libraries like GL, GLEW, glut, png, etc. The specified
path must be absolute or relative to the current working directory
from which configure is invoked. This option may be specified
multiple times to add multiple directories to the search list.
"""
)
argparser.add_argument(
"--search-dir", "-S",
dest="search_dirs",
type=os.path.abspath,
action="append",
default=list(),
help="""
Specifies additional directory with include and lib subdirectories
that should be searched when looking for C++ headers or compiled
libraries. Specifying --search-dir PATH is equivalent to specifying
--include-dir PATH/include --library-dir PATH/lib. The provided
path must be absolute or relative to the current working directory
from which configure is invoked. This option may be specified
multiple times to add multiple directories to the search list.
"""
)
argparser.add_argument(
"--use-cxxflags",
default=False,
action="store_true",
help="""
Uses the directories specified by the -I options
in CXXFLAGS (if available) and adds them
to the values specified by --include-dir.
"""
)
argparser.add_argument(
"--use-ldflags",
default=False,
action="store_true",
help="""
Uses the directories specified by the -L options
in LDFLAGS (if available) and adds them
to the values specified by --library-dir.
"""
)
argparser.add_argument(
"--low-profile",
dest="low_profile",
type=BoolArgValue,
choices=[True, False],
action="store",
default=None,
help="""
Enables or disables the low profile mode (see the documentation
for the EAGINE_LOW_PROFILE compile-time switch).
If this option is used, then the specified value is written to
the oglplus/config/site.hpp file, otherwise it is set to the default
value in oglplus/config.hpp and may be overriden in sources by
defining this preprocessor symbol or by using the appropriate
compiler command-line switch or build environment setting.
"""
)
argparser.add_argument(
"--info-only",
dest="info_only",
action="store_true",
default=False,
help="""
With this option configure only generates a python script containing
information about the available configurations on the current machine.
"""
)
argparser.add_argument(
"--with-clang-tidy",
dest="with_clang_tidy",
action="store_true",
default=False,
help="""
Configure with clang-tidy checks.
"""
)
argparser_build_examples_group = argparser.add_mutually_exclusive_group()
argparser_build_examples_group.add_argument(
"--build-examples",
dest="build_examples",
type=BoolArgValue,
choices=[True, False],
action="store",
default=True,
help="""
Determines whether the examples should be built (default = %(default)s).
"""
)
argparser_build_examples_group.add_argument(
"--no-examples",
dest="build_examples",
action="store_false",
help="""
Do not build the examples and the textures.
Equivalent to --build-examples=False.
"""
)
argparser_build_docs_group = argparser.add_mutually_exclusive_group()
argparser_build_docs_group.add_argument(
"--build-docs",
dest="build_docs",
type=BoolArgValue,
choices=[True, False],
action="store",
default=True,
help="""
Determines whether the documentation should be built (default = %(default)s).
"""
)
argparser_build_docs_group.add_argument(
"--no-docs",
dest="build_docs",
action="store_false",
help="""
Do not build the documentation.
Equivalent to --build-docs=False.
"""
)
argparser_make_screenshots_group = argparser.add_mutually_exclusive_group()
argparser_make_screenshots_group.add_argument(
"--make-screenshots",
dest="make_screenshots",
type=BoolArgValue,
choices=[True, False],
action="store",
default=False,
help="""
Determines whether screenshots from OGLplus examples should be
made when building the documentation (default = %(default)s).
"""
)
argparser_make_screenshots_group.add_argument(
"--screenshots",
dest="make_screenshots",
action="store_true",
help="""
Equivalent to --make-screenshots=True.
"""
)
argparser.add_argument(
"--max-gl-version",
dest="max_gl_version",
type=OpenGLVersionValue,
action="store",
default=None,
help="""
Sets the maximum OpenGL version to be used. The cmake OpenGL
version detection is only rudimentary and not 100%% reliable
and may return a higher OpenGL version than actually available.
This option can be used to limit the maximal version number.
"""
)
argparser.add_argument(
"--strict-gl-version-detection",
dest="strict_gl_version_detection",
type=BoolArgValue,
action="store",
default=None,
help="""
Enables (or disables) strict GL version and extension detection.
In relaxed (non-strict) mode the only thing that is detected is
whether specific GL symbols are defined like GL_VERSION_x_y or
GL_EXT_extension_name. In strict mode a GL context is initialized
and the GL version and extension list is queried and processed.
"""
)
argparser.add_argument(
"--gl-tests-compile-only",
dest="gl_tests_compile_only",
action="store_true",
default=False,
help="""
Only compilation failures are taken into account when
detecting GL version or extensions. Execution failures
are ignored.
"""
)
path2idus = str.maketrans("/.","__")
path2idmi = str.maketrans("/.","--")
gl_api_libs = {
"glcorearb.h" : "GL/glcorearb.h header",
"GL3/gl3.h" : "GL3/gl3.h header",
"GLES3/gl32.h" : "GLES3/gl32.h header",
"GLES3/gl31.h" : "GLES3/gl31.h header",
"GLES3/gl3.h" : "GLES3/gl3.h header",
"GLEW" : "GLEW library",
"GL3W" : "GL3W library"
}
argparser_gl_api_lib_group = argparser.add_mutually_exclusive_group()
argparser_gl_api_lib_group.add_argument(
"--use-gl-api-lib",
dest="gl_api_lib",
type=str,
choices=[lib.upper().translate(path2idus) for lib in gl_api_libs.keys()],
action="store",
default=None,
help="""
Forces the use of a specific header or library which
defines the GL symbols (types, functions, defines, etc.).
If this option is used then the header must be installed somewhere
in the system include directories or in directories specified
with --include-dir and the corresponding binary libraries
must be installed in system library directories or in directories
specified with the --library-dir option.
"""
)
for gl_api_lib, gl_api_lib_name in gl_api_libs.items():
lib_lc = gl_api_lib.lower().translate(path2idmi)
lib_uc = gl_api_lib.upper().translate(path2idus)
argparser_gl_api_lib_group.add_argument(
"--use-%(lib_lc)s" % { "lib_lc" : lib_lc },
dest="gl_api_lib",
action="store_const",
const=lib_uc,
help="""
Forces the use of the %(lib_name)s to define the GL symbols
used in OGLplus examples.
Equivalent to --use-gl-api-lib=%(lib_uc)s.
""" % {
"lib" : gl_api_lib,
"lib_name" : gl_api_lib_name,
"lib_uc" : lib_uc
}
)
# TODO
#gl_init_libs = ["GLUT", "GLFW3", "GLFW", "QT5GL", "wxGL", "SDL", "glX", "EGL"]
gl_init_libs = ["GLUT", "GLFW3", "GLFW", "SDL", "glX"]
argparser_gl_init_lib_group = argparser.add_mutually_exclusive_group()
argparser_gl_init_lib_group.add_argument(
"--use-gl-init-lib",
dest="gl_init_lib",
type=str,
choices=[lib.upper() for lib in gl_init_libs],
action="store",
default=None,
help="""
Forces the use of a specific window library which
initializes the default GL context. This option allows
to force a specific example 'harness'.
"""
)
for gl_init_lib in gl_init_libs:
argparser_gl_init_lib_group.add_argument(
"--use-%(lib_lc)s" % { "lib_lc" : gl_init_lib.lower() },
dest="gl_init_lib",
action="store_const",
const=gl_init_lib.upper(),
help="""
Forces the use of the %(lib)s library to create
the window and initialize the GL context in
OGLplus examples.
Equivalent to --use-gl-init-lib=%(lib_uc)s.
""" % {
"lib" : gl_init_lib,
"lib_uc" : gl_init_lib.upper()
}
)
argparser.add_argument(
"--clean",
default=False,
action="store_true",
help="""
Remove any previous cached and intermediate files and run the
configuration process from scratch.
Specifying this option causes the build directory to be deleted
and recreated.
"""
)
argparser.add_argument(
"--quiet",
default=False,
action="store_true",
help="""
Do not print regular messages, errors are still printed to
stderr. Also any cmake output is still printed.
"""
)
argparser.add_argument(
"--quick",
default=False,
action="store_true",
help="""
Skips some optional steps in the configuration process.
"""
)
argparser.add_argument(
"--jobs",
type=JobCountValue,
default=None,
action="store",
help="""
Specifies the number of parallel build jobs to be used,
if applicable for the used build tool.
"""
)
argparser.add_argument(
"--build",
default=False,
action="store_true",
help="""
If possible, after running cmake also invoke the build tool
and build the project. This is currently supported only
for certain build tools.
"""
)
argparser.add_argument(
"--install",
default=False,
action="store_true",
help="""
If possible, after running cmake also build and install
the project. This is currently supported only
for certain build tools.
"""
)
argparser.add_argument(
"--update-me",
default=False,
action="store_true",
help="""
After successful installation calls the update-me script, that
copies OGLplus user configuration files and scripts into the user's
home directory.
"""
)
argparser.add_argument(
"--no-tests",
default=False,
action="store_true",
help="""
Disable configuring of the testsuite.
"""
)
argparser.add_argument(
"--no-enum-tests",
default=False,
action="store_true",
help="""
Don't include enumerations tests in the testsuite.
"""
)
argparser.add_argument(
"--generator",
type=CMakeGeneratorValue,
default=None,
action="store",
help="""
Specify the cmake generator to be used.
"""
)
argparser.add_argument(
"--debug-config",
dest="debug_config",
default=False,
action="store_true",
help="""
Enable debugging of the cmake build system.
"""
)
argparser.add_argument(
"--debug-gl-ver-error",
dest="debug_gl_ver_error",
default=False,
action="store_true",
help="""
Enable debugging of problems with GL version detetion.
"""
)
argparser.add_argument(
"--debug-gl-feat-error",
dest="debug_gl_feat_error",
type=str,
default="",
action="store",
help="""
Enable debugging of problems with GL extension detetion.
"""
)
argparser.add_argument(
"--debug-lib-error",
dest="debug_lib_error",
default=False,
action="store_true",
help="""
Enable debugging of problems with building the library.
"""
)
argparser.add_argument(
"--cmake",
dest="cmake_options",
nargs=argparse.REMAINDER,
default=list(),
help="""Everything following this option will be passed to cmake verbatim."""
)
return argparser
# applies LD_LIBRARY_PATH to library search directories
def search_ld_library_path():
ld_library_path_dirs = list()
try:
ld_library_path = os.environ.get("LD_LIBRARY_PATH")
if ld_library_path:
for ld_library_dir in ld_library_path.split(':'):
if os.path.isdir(ld_library_dir):
ld_library_path_dirs.append(ld_library_dir)
except: pass
return ld_library_path_dirs
# applies CXXFLAGS to the options for cmake if possible
def search_cxxflags():
cxxflags_include_dirs = list()
try:
import shlex
cxxflags = os.environ.get("CXXFLAGS")
if cxxflags is not None:
flagiter = iter(shlex.split(cxxflags))
for flag in flagiter:
if flag == "-I":
cxxflags_include_dirs.append(flagiter.next())
elif flag.startswith("-I"):
cxxflags_include_dirs.append(flag[2:])
except: pass
return cxxflags_include_dirs
# applies LDFLAGS to the options for cmake if possible
def search_ldflags():
ldflags_library_dirs = list()
try:
import shlex
ldflags = os.environ.get("LDFLAGS")
if ldflags is not None:
flagiter = iter(shlex.split(ldflags))
for flag in flagiter:
if flag == "-L":
ldflags_library_dirs.append(flagiter.next())
elif flag.startswith("-L"):
ldflags_library_dirs.append(flag[2:])
except: pass
return ldflags_library_dirs
# get some useful information from cmake
def cmake_system_info(options):
info_path = os.path.join(options.build_dir, "system-info.txt")
command = ["cmake", "--system-information", info_path]
try:
proc = subprocess.Popen(
command,
stdin=None,
stdout=subprocess.PIPE,
stderr=None
)
except OSError as os_error:
print("Failed to execute '%(cmd)s': %(error)s" % {
"cmd": command,
"error": os_error
})
sys.exit(2)
result = dict()
try:
import shlex
for line in open(info_path).readlines():
try:
words = shlex.split(line)
if(words[0] in (
"CMAKE_BUILD_TOOL",
"CMAKE_INSTALL_PREFIX"
)): result[words[0]] = words[1]
except ValueError:
pass
except IndexError:
pass
except: pass
return result
# the main function
def main(argv):
# parse and process the command-line arguments
argparser = get_argument_parser()
options = argparser.parse_args()
cmake_env = os.environ.copy()
if sys.platform == 'win32':
env_list_sep = str(";")
else: env_list_sep = str(":")
# if we just wanted to generate the bash completion script
if options.generate_bash_complete:
args.print_bash_complete_script(argparser)
return 0
# if we just wanted to generate the bash completion script
if options.generate_manual:
args.print_manual(argparser)
return 0
# if we are in quiet mode we may also go to quick mode
if options.quiet: options.quick = True
# if we also want to install the project enable building
if options.install: options.build= True
# if we also want to build the project disable quick mode
if options.build: options.quick = False
# get the info from cmake if we are not in a hurry
if not options.quick:
cmake_info = cmake_system_info(options)
else: cmake_info = list()
# the search prefix
for search_dir in options.search_dirs:
subdir = os.path.join(search_dir, "include")
if os.path.exists(subdir):
options.include_dirs.append(subdir)
subdir = os.path.join(search_dir, "lib")
if os.path.exists(subdir):
options.library_dirs.append(subdir)
subdir = os.path.join(subdir, "pkgconfig")
pkg_config_path = cmake_env.get("PKG_CONFIG_PATH", None)
if pkg_config_path:
pc_paths = pkg_config_path.split(env_list_sep)
pc_paths.append(subdir)
pkg_config_path = env_list_sep.join(pc_paths)
else: pkg_config_path = subdir
cmake_env["PKG_CONFIG_PATH"] = pkg_config_path
# search the LD_LIBRARY_PATH
options.library_dirs += search_ld_library_path()
# search the CXX and LD FLAGS if requested
if(options.use_cxxflags): options.include_dirs += search_cxxflags()
if(options.use_ldflags): options.library_dirs += search_ldflags()
# additional options for cmake
cmake_options = list()
# add configuration options
if(len(options.config_types) == 1):
cmake_options.append("-DCMAKE_BUILD_TYPE="+options.config_types[0])
elif(len(options.config_types) > 1):
cmake_options.append(
"-DCMAKE_CONFIGURATION_TYPES="+";".join(options.config_types)
)
# add the installation prefix if provided
if(options.install_prefix):
cmake_options.append(
"-DCMAKE_INSTALL_PREFIX="+
options.install_prefix
)
# set the low profile mode switch
if(options.low_profile is not None):
cmake_options.append("-DCONFIG_SET_LOW_PROFILE=On")
if(options.low_profile):
cmake_options.append("-DLOW_PROFILE=On")
else:
cmake_options.append("-DLOW_PROFILE=Off")
# if we just want fo query the system configuration info
if(options.info_only):
cmake_options.append("-DCONFIG_INFO_ONLY=On")
# disable building the examples
if(not options.build_examples):
cmake_options.append("-DNO_EXAMPLES=On")
# enable clang-tidy checks
if options.with_clang_tidy:
cmake_options.append("-DWITH_CLANG_TIDY=On")
# limit the GL version
if(options.max_gl_version):
cmake_options.append("-DCONFIG_MAX_GL_VERSION=%s"%options.max_gl_version)
# enable/disable strict version detection
if(options.strict_gl_version_detection is not None):
value = int(options.strict_gl_version_detection)
cmake_options.append("-DCONFIG_STRICT_GL_VERSION_CHECK=%d"%value)
if(options.gl_tests_compile_only):
cmake_options.append("-DCOMPILE_ONLY_GL_TESTS=On")
# force the GL header to be used
if(options.gl_api_lib):
cmake_options.append("-DFORCE_GL_API_LIB=%s"%options.gl_api_lib)
# force the GL initialization library to be used
if(options.gl_init_lib):
cmake_options.append("-DFORCE_GL_INIT_LIB=%s"%options.gl_init_lib)
# add paths for header lookop
if(options.include_dirs):
cmake_options.append("-DHEADER_SEARCH_PATHS="+";".join(options.include_dirs))
# add paths for library lookup
if(options.library_dirs):
cmake_options.append("-DLIBRARY_SEARCH_PATHS="+";".join(options.library_dirs))
# remove the build dir if it was requested
if(options.clean and os.path.exists(options.build_dir)):
try: shutil.rmtree(options.build_dir)
except OSError as os_error:
print("Warning failed to remove build directory")
# configure the test suite
if(options.no_tests):
cmake_options.append("-DNO_TESTS=On")
if(options.no_enum_tests):
cmake_options.append("-DNO_ENUM_TESTS=On")
# set the generator if specified
if(options.generator):
cmake_options += ['-G', options.generator]
# put cmake in debug mode if specified
if(options.debug_gl_ver_error):
cmake_options += ["-DDEBUG_GL_VER_ERROR=1"]
if(options.debug_gl_feat_error):
cmake_options += ["-DDEBUG_GL_FEAT_ERROR=%s"%options.debug_gl_feat_error]
if(options.debug_lib_error):
cmake_options += ["-DDEBUG_LIB_ERROR=1"]
if(options.debug_config):
cmake_options += ["-DDEBUG_CONFIG=1"]
cmake_options += ["--debug-output", "--debug-trycompile"]
# get the work directory path
workdir = os.path.abspath(os.path.dirname(sys.argv[0]))
# create the build directory if necessary
if(not os.path.isdir(options.build_dir)):
os.makedirs(options.build_dir)
# compose the command line for calling cmake
cmake_cmd_line = ["cmake"] + cmake_options + options.cmake_options + [workdir]
# call cmake
try:
ret = subprocess.call(
cmake_cmd_line,
cwd=options.build_dir,
env=cmake_env
)
if ret < 0:
print("# Configuration killed by signal %d" % -ret)
sys.exit(-ret)
elif ret > 0:
print("# Configuration failed with code %d" % ret)
sys.exit(ret)
# handle errors
except OSError as os_error:
print( "# Configuration failed")
print("# Failed to execute '%(cmd)s': %(error)s" % {
"cmd": str(" ").join(cmake_cmd_line),
"error": str(os_error)
})
sys.exit(3)
# use the specified number of jobs
if options.jobs is not None:
job_count = options.jobs
else:
# else try to get the processor count (use below)
try:
import multiprocessing
job_count = multiprocessing.cpu_count()+1
except: job_count = None
# print some info if not supressed
if not options.quiet and not options.info_only:
print("# Configuration completed successfully.")
cmake_build_tool = cmake_info.get("CMAKE_BUILD_TOOL")
if(cmake_build_tool):
cmake_build_tool = paths.shorten_command(cmake_build_tool)
path_to_build_dir = paths.shortest_path_from_to(os.getcwd(), options.build_dir)
if(not options.build):
if(cmake_build_tool == "make"):
print("# To build OGLplus do the following:")
print(str())
print("cd "+ path_to_build_dir)
if job_count:
print("%(tool)s -j %(jobs)d" % {
"tool": cmake_build_tool,
"jobs": job_count
})
else: print(cmake_build_tool)
print(cmake_build_tool + " install")
# if the user requested build after config is done
if options.build:
build_cmd_line = [
"cmake",
"--build",
options.build_dir
]
if options.install:
build_cmd_line += ["--target", "install"]
if job_count:
build_cmd_line += ["--", "-j", str(job_count)]
if build_cmd_line:
try:
subprocess.call(
build_cmd_line,
cwd=options.build_dir,
env=cmake_env
)
if options.update_me:
if not options.install_prefix:
options.install_prefix =\
cmake_info.get("CMAKE_INSTALL_PREFIX")
update_me_cmd_line = [
os.path.join(
options.install_prefix,
"share",
"oglplus",
"user",
"update-me"
)
]
subprocess.call(update_me_cmd_line)
except OSError as os_error:
print( "# Build failed")
print("# Failed to execute '%(cmd)s': %(error)s" % {
"cmd": str(" ").join(build_cmd_line),
"error": str(os_error)
})
sys.exit(4)
else: print("# --build is not supported with the current build tool")
# print the configuration info if requested
if options.info_only:
try:
info_json_path=os.path.join(options.build_dir, 'config', 'info.json')
oglplus_config_info=json.load(open(info_json_path))
key_descs = {
"gl_init_libs": "Possible values for --gl-init-lib",
"gl_api_libs": "Possible values for --gl-api-lib",
}
for key, value in oglplus_config_info.items():
try: desc=key_descs[key]
except: desc=key
if type(value) == list:
value = "\n\t".join(value)
print("%(desc)s:\n\t%(value)s" % {"desc": desc, "value": value})
except: pass
# print additional info if not supressed
elif not options.quiet:
if not options.install_prefix:
options.install_prefix = cmake_info.get("CMAKE_INSTALL_PREFIX")
if(options.install_prefix):
if not os.access(options.install_prefix, os.W_OK):
print(str())
print("# NOTE: installing to '%(prefix)s' "\
"may require administrative privilegues" % {
"prefix": options.install_prefix
}
)
# run the main function
if __name__ == "__main__": main(sys.argv[1:])