-
Notifications
You must be signed in to change notification settings - Fork 1
/
cgal_create_CMakeLists
executable file
·605 lines (479 loc) · 16.4 KB
/
cgal_create_CMakeLists
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
#!/bin/bash
# Copyright (c) 1999,2000,2002-2007,2009,2011,2012
# Utrecht University (The Netherlands),
# ETH Zurich (Switzerland),
# INRIA Sophia-Antipolis (France),
# Max-Planck-Institute for Informatics Saarbruecken (Germany),
# and Tel-Aviv University (Israel). All rights reserved.
#
# This file is part of CGAL (www.cgal.org)
#
# $URL$
# $Id$
# SPDX-License-Identifier: LGPL-3.0-or-later
#
# Author(s) : various
# This script creates a CGAL cmake script with entries for files with a common
# C++ file extension (as mentioned in the g++ man page) in the current directory.
# Some options can be given or specified in a file.
#LEDA
#GMP
#GMPXX
#MPFR
#MPFI
#RS
#BLAS
#LAPACK
#OPENNL
#QGLViewer (or implied by Qt4?)
#ESBTL
#NTL
#Core (implies GMP+GMPXX)
#Qt4 (implies QT4)
#ImageIO
#not (yet) supported
#F2C (comes with BLAS/LAPACK - something like that)
#IPE (ask Laurent)
#MKL (ask Andreas)
create_cmake_script_with_options()
{
qt4='n'
# parse options file
if [ -e "$OPTIONS_FILE" ]; then
OLDIFS="$IFS"
IFS=$'\n'
for LINE in `cat $OPTIONS_FILE`; do
# CGAL components
if [ -z "$CGAL_COMPONENTS_GIVEN" ]; then # read file only if not given!
next_cgal_component=`echo $LINE | grep -v "#" | grep CGAL_COMPONENT`
if [ ! -z "$next_cgal_component" ]; then
next_cgal_component=${next_cgal_component/CGAL_COMPONENT /}
if [ -z "$CGAL_COMPONENTS" ]; then
CGAL_COMPONENTS=$next_cgal_component
else
CGAL_COMPONENTS=$CGAL_COMPONENTS":"$next_cgal_component
fi
fi
fi
# Boost components
if [ -z "$BOOST_COMPONENTS_GIVEN" ]; then # read file only if not given!
next_boost_component=`echo $LINE | grep -v "#" | grep BOOST_COMPONENT`
if [ ! -z "$next_boost_component" ]; then
next_boost_component=${next_boost_component/BOOST_COMPONENT /}
if [ -z "$BOOST_COMPONENTS" ]; then
BOOST_COMPONENTS=$next_boost_component
else
BOOST_COMPONENTS=$BOOST_COMPONENTS":"$next_boost_component
fi
fi
fi
done
IFS="$OLDIFS"
fi
# print makefile header
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
cat << 'EOF'
# Created by the script cgal_create_CMakeLists
# This is the CMake script for compiling a set of CGAL applications.
cmake_minimum_required(VERSION 3.1...3.15)
EOF
#---------------------------------------------------------------------------
if [ "$SINGLE_SOURCE" = "n" ]; then
echo "project( ${PROJECT} )"
else
echo "project( ${SOURCE} )"
fi
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
cat << 'EOF'
# CGAL and its components
EOF
if [ -n "$ENABLE_CTEST" ]; then
echo "enable_testing()"
fi
#---------------------------------------------------------------------------
# echo "CGAL_COMPONENTS: $CGAL_COMPONENTS"
if [ ! -z "$CGAL_COMPONENTS" ]; then
# ensure capitalization
# CGAL: Core, Qt4, PDB, ImageIO
CGAL_COMPONENTS=${CGAL_COMPONENTS//[c|C][o|O][r|R][e|E]/Core}
CGAL_COMPONENTS=${CGAL_COMPONENTS//[q|Q][t|T]4/Qt4}
CGAL_COMPONENTS=${CGAL_COMPONENTS//[i|I][m|M][a|A][g|G][e|E][i|I][o|O]/ImageIO}
# external libs
CGAL_COMPONENTS=${CGAL_COMPONENTS//[g|G][m|M][p|P]/GMP}
CGAL_COMPONENTS=${CGAL_COMPONENTS//[g|G][m|M][p|P][x|X][x|X]/GMPXX}
CGAL_COMPONENTS=${CGAL_COMPONENTS//[m|M][p|P][f|F][r|R]/MPFR}
CGAL_COMPONENTS=${CGAL_COMPONENTS//[l|L][e|E][d|D][a|A]/LEDA}
CGAL_COMPONENTS=${CGAL_COMPONENTS//[m|M][p|P][f|F][i|I]/MPFI}
CGAL_COMPONENTS=${CGAL_COMPONENTS//[r|R][s|S]/RS}
CGAL_COMPONENTS=${CGAL_COMPONENTS//[o|O][p|P][e|E][n|N][n|N][l|L]/OpenNL}
CGAL_COMPONENTS=${CGAL_COMPONENTS//[b|B][l|L][a|A][s|S]/BLAS}
CGAL_COMPONENTS=${CGAL_COMPONENTS//[l|L][a|A][p|P][a|A][c|C][k|K]/LAPACK}
CGAL_COMPONENTS=${CGAL_COMPONENTS//[q|Q][g|G][l|L][v|V][i|I][e|E][w|W][e|E][r|R]/QGLViewer}
CGAL_COMPONENTS=${CGAL_COMPONENTS//[z|Z][l|L][i|I][b|B]/zlib}
CGAL_COMPONENTS=${CGAL_COMPONENTS//[e|E][s|S][b|B][t|T][l|L]/ESBTL}
CGAL_COMPONENTS=${CGAL_COMPONENTS//[n|N][t|T][l|L]/NTL}
CGAL_COMPONENTS=${CGAL_COMPONENTS//[o|O][p|P][e|E][n|N][g|G][l|L]/OpenGL}
#F2C?
#IPE?
#MKL?
OLDIFS="$IFS"
IFS=':'
for cgal_component in $CGAL_COMPONENTS; do
COMPONENT=`echo $cgal_component | tr '[:upper:]' '[:lower:]'`
# for qtmoc
if [ "$COMPONENT" = "qt4" ]; then
qt4='y'
fi
done
IFS=$OLDIFS
fi
echo "find_package( CGAL QUIET COMPONENTS ${CGAL_COMPONENTS//:/ } )"
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
cat << 'EOF'
if ( NOT CGAL_FOUND )
message(STATUS "This project requires the CGAL library, and will not be compiled.")
return()
endif()
EOF
#---------------------------------------------------------------------------
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
cat << 'EOF'
# Boost and its components
EOF
#---------------------------------------------------------------------------
if [ ! -z "$BOOST_COMPONENTS" ]; then
echo "find_package( Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS//:/ } )"
else
echo "find_package( Boost REQUIRED )"
fi # additional Boost components
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
cat << 'EOF'
if ( NOT Boost_FOUND )
message(STATUS "This project requires the Boost library, and will not be compiled.")
return()
endif()
EOF
#---------------------------------------------------------------------------
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
cat << 'EOF'
# include for local directory
EOF
#---------------------------------------------------------------------------
if [ -d include ] ; then
echo 'include_directories( BEFORE include )'
fi
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
cat << 'EOF'
# include for local package
EOF
#---------------------------------------------------------------------------
# includes for local package
if [ -d ../include ] ; then
echo 'include_directories( BEFORE ../include )'
fi
if [ ! -z "$PACKAGES" ]; then
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
cat << 'EOF'
# include of additional packages
EOF
#-------------------------------------------------------------------------
fi
# Qt4
if [ "$qt4" = "y" ]; then
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
cat << 'EOF'
# Qt4
set( QT_USE_QTXML true )
set( QT_USE_QTMAIN true )
set( QT_USE_QTSCRIPT true )
set( QT_USE_QTOPENGL true )
find_package(Qt4)
if ( NOT QT_FOUND )
message(STATUS "This project requires the Qt4 library, and will not be compiled.")
return()
endif()
EOF
#-------------------------------------------------------------------------
fi #qt4
if [ ! -z "$BOOST_COMPONENTS" ]; then
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
cat << 'EOF'
# Boost linking
EOF
#-------------------------------------------------------------------------
OLDIFS="$IFS"
IFS=':'
for boost_component in $BOOST_COMPONENTS; do
BOOST_COMPONENT=`echo $boost_component | tr '[:lower:]' '[:upper:]'`
echo "add_definitions( \"-DCGAL_USE_BOOST_${BOOST_COMPONENT}\" )"
echo "list(APPEND CGAL_3RD_PARTY_LIBRARIES \${Boost_${BOOST_COMPONENT}_LIBRARY} )"
done
IFS=$OLDIFS
fi # additional Boost components
# All Files or Single Source
if [ "$SINGLE_SOURCE" = "n" ]; then #=======================================
###############
# ALL SOURCES #
###############
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
cat << 'EOF'
# Creating entries for all C++ files with "main" routine
# ##########################################################
EOF
#-------------------------------------------------------------------------
# add a new line
echo
# Qt4
if [ "$qt4" = "y" ]; then
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
cat << 'EOF'
if ( CGAL_Qt4_FOUND AND QT_FOUND )
include( ${QT_USE_FILE} )
include_directories( ${QT_INCLUDE_DIR} )
endif()
EOF
#-----------------------------------------------------------------------
fi # qt4
for file in `ls *.cc *.cp *.cxx *.cpp *.CPP *.c++ *.C 2> /dev/null | sort` ; do
# Create an executable for each cpp that contains a function "main()"
BASE=`basename $file .cc`
BASE=`basename $BASE .cp`
BASE=`basename $BASE .cxx`
BASE=`basename $BASE .cpp`
BASE=`basename $BASE .CPP`
BASE=`basename $BASE .c++`
BASE=`basename $BASE .C`
egrep '\bmain[ \t]*\(' $file >/dev/null 2>&1
if [ $? -eq 0 ]; then
if [ "$qt4" = "y" ]; then
echo "create_single_source_cgal_program_qt4( \"$file\" )"
else
echo "create_single_source_cgal_program( \"$file\" )"
fi
if [ -n "$ENABLE_CTEST" ]; then
if [ -f "$BASE.cin" ] ; then
CIN=" < $BASE.cin"
else
CIN=
fi
cat <<EOF
add_test( "$BASE" \${CMAKE_CTEST_COMMAND}
--build-and-test "\${CMAKE_CURRENT_SOURCE_DIR}"
"\${CMAKE_CURRENT_BINARY_DIR}"
--build-generator "\${CMAKE_GENERATOR}"
--build-makeprogram "\${CMAKE_MAKE_PROGRAM}"
--build-target $BASE
--build-no-clean
--build-run-dir "\${CMAKE_CURRENT_SOURCE_DIR}"
--test-command sh -c "\${CMAKE_CURRENT_BINARY_DIR}/$BASE$CIN" )
EOF
fi
fi
#add a new line
echo
done
else #======================================================================
#################
# SINGLE_SOURCE #
#################
target_name=$SOURCE
echo
echo
echo "# Creating entries for target: $target_name"
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
cat << 'EOF'
# ############################
EOF
#-------------------------------------------------------------------------
for file in `ls *.cc *.cp *.cxx *.cpp *.CPP *.c++ *.C 2> /dev/null | sort` ; do
all="$all $file"
done
# Qt4
if [ "$qt4" = "y" ]; then
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
cat << 'EOF'
if ( CGAL_Qt4_FOUND AND QT_FOUND )
include( ${QT_USE_FILE} )
include_directories( ${QT_INCLUDE_DIR} )
EOF
#-----------------------------------------------------------------------
echo " # UI files (Qt Designer files)"
for file in `ls *.ui 2> /dev/null | sort`; do
echo " qt4_wrap_ui( DT_UI_FILES $file )"
done
echo
echo " # qrc files (resources files, that contain icons, at least)"
for file in `ls *.qrc 2> /dev/null | sort`; do
echo " qt4_add_resources ( DT_RESOURCE_FILES ./$file )"
done
echo
MOC_FILES=""
echo " # use the Qt MOC preprocessor on classes that derives from QObject"
for file in `ls include/*.h 2> /dev/null | sort`; do
BASE=`basename $file .h`
egrep 'Q_OBJECT' $file >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo " qt4_generate_moc( include/${BASE}.h ${BASE}.moc )"
MOC_FILES="${BASE}.moc $MOC_FILES"
fi
done
for file in `ls *.h 2> /dev/null | sort`; do
BASE=`basename $file .h`
egrep 'Q_OBJECT' $file >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo " qt4_generate_moc( ${BASE}.h ${BASE}.moc )"
MOC_FILES="${BASE}.moc $MOC_FILES"
fi
done
for file in `ls *.cc *.cp *.cxx *.cpp *.CPP *.c++ *.C 2> /dev/null | sort` ; do
BASE=`basename $file .cc`
BASE=`basename $BASE .cp`
BASE=`basename $BASE .cxx`
BASE=`basename $BASE .cpp`
BASE=`basename $BASE .CPP`
BASE=`basename $BASE .c++`
BASE=`basename $BASE .C`
egrep 'Q_OBJECT' $file >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo " qt4_generate_moc( ${BASE}.cpp ${BASE}.moc )"
MOC_FILES="${BASE}.moc $MOC_FILES"
fi
done
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
cat << 'EOF'
endif()
EOF
#-----------------------------------------------------------------------
all="${all} ${MOC_FILES} \${DT_UI_FILES} \${DT_RESOURCE_FILES}"
fi # qt4
# no 'cat' here, as variable substitution required
echo
echo "add_executable( ${target_name} ${all} )"
echo
echo "add_to_cached_list( CGAL_EXECUTABLE_TARGETS ${target_name} )"
echo
echo "# Link the executable to CGAL and third-party libraries"
LIBS=""
for comp in ${CGAL_COMPONENTS}; do
LIBS=$LIBS" CGAL::CGAL_${comp}"
done
echo "target_link_libraries(${target_name} PRIVATE CGAL::CGAL${LIBS} )"
fi # single source or all files #===========================================
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
cat << 'EOF'
EOF
#---------------------------------------------------------------------------
echo
}
usage()
{
echo "Usage: `basename $0` [-s source] [-c cgal-component1:cgal-component2:...] [-b boost-component1:boost-component2:...] [-p] [-o options_file='`pwd`/cgal_cmake_options:$HOME/.cgal_cmake_options_rc'] [-v] [-h]" >&2
echo >&2
echo " -s source If this parameter is given the script will create one single executable for 'source' with all source files; otherwise it creates one executable for each main'ed source." >&2
echo " cgal_componentX - must be a valid cgal component, examples are 'Core','ImageIO','Qt4' ('benchmark', 'symbolic')." >&2
echo " boost_componentX - must be a valid boost component, like 'filesystem', 'program_options'." >&2
echo " -o options_file - file with PACKAGE, DIRECTORY, CGAL_COMPONENT, and BOOST_COMPONENT directives" >&2
echo " -v the version" >&2
echo " -h this info screen" >&2
echo >&2
}
SINGLE_SOURCE='n'
SOURCE=""
CGAL_COMPONENTS_GIVEN=""
CGAL_COMPONENTS=""
BOOST_COMPONENTS_GIVEN=""
BOOST_COMPONENTS=""
OPTIONS_FILE=`pwd`"/cgal_cmake_options"
if [ ! -e "$OPTIONS_FILE" ]; then
OPTIONS_FILE="${HOME}/.cgal_cmake_options_rc"
fi
# parse command line arguments
while getopts s:c:b:o:phvt OPT; do
case "$OPT" in
s) SINGLE_SOURCE='y'
SOURCE=$OPTARG
if [ "${SOURCE:(-3)}" = ".cc" ]; then
echo "Error: Source must not end with '.cc'!" >&2
echo
usage
exit 2
fi
if [ "${SOURCE:(-3)}" = ".cp" ]; then
echo "Error: Source must not end with '.cp'!" >&2
echo
usage
exit 2
fi
if [ "${SOURCE:(-4)}" = ".cxx" ]; then
echo "Error: Source must not end with '.cxx'!" >&2
echo
usage
exit 2
fi
if [ "${SOURCE:(-4)}" = ".cpp" ]; then
echo "Error: Source must not end with '.cpp'!" >&2
echo
usage
exit 2
fi
if [ "${SOURCE:(-4)}" = ".CPP" ]; then
echo "Error: Source must not end with '.CPP'!" >&2
echo
usage
exit 2
fi
if [ "${SOURCE:(-4)}" = ".c++" ]; then
echo "Error: Source must not end with '.c++'!" >&2
echo
usage
exit 2
fi
if [ "${SOURCE:(-2)}" = ".C" ]; then
echo "Error: Source must not end with '.C'!" >&2
echo
usage
exit 2
fi
;;
c) CGAL_COMPONENTS_GIVEN='y'
CGAL_COMPONENTS=$OPTARG
;;
b) BOOST_COMPONENTS_GIVEN='y'
BOOST_COMPONENTS=$OPTARG
;;
o) OPTIONS_FILE=$OPTARG
if [ ! -e "$OPTIONS_FILE" ]; then
echo "Options-file '$OPTIONS_FILE' does not exist." >&2
exit 1
fi
;;
t) ENABLE_CTEST='y'
;;
h) usage
exit 0
;;
v) echo "`basename $0` version 0.1"
exit 0
;;
\?) # getopts issues an error message
usage
exit 1
;;
esac
done
shift `expr $OPTIND - 1`
#echo "FILE: $OPTIONS_FILE"
#echo "BOOST_COMPONENTS: $BOOST_COMPONENTS"
echo "CGAL_COMPONENTS: $CGAL_COMPONENTS"
#echo "SINGLE_SOURCE: $SINGLE_SOURCE"
#echo "SOURCE: $SOURCE"
OUTPUTFILE=CMakeLists.txt
PROJECT=`basename $PWD`
if [ -f ${OUTPUTFILE} ] ; then
echo "moving $OUTPUTFILE to ${OUTPUTFILE}.bak ..."
echo
mv -f $OUTPUTFILE ${OUTPUTFILE}.bak
fi
create_cmake_script_with_options | tee $OUTPUTFILE
echo
echo "created $OUTPUTFILE in $PWD ..."