-
Notifications
You must be signed in to change notification settings - Fork 0
/
cgal_create_cmake_script
executable file
·175 lines (148 loc) · 4.88 KB
/
cgal_create_cmake_script
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
#!/bin/bash
# Copyright (c) 1999,2000,2002-2007
# Utrecht University (The Netherlands),
# ETH Zurich (Switzerland),
# INRIA Sophia-Antipolis (France),
# Max-Planck-Institute Saarbruecken (Germany),
# and Tel-Aviv University (Israel). All rights reserved.
#
# This file is part of CGAL (www.cgal.org); you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; version 3 of the License,
# or (at your option) any later version.
#
# Licensees holding a valid commercial license may use this file in
# accordance with the commercial license agreement provided with the software.
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# $URL: svn+ssh://[email protected]/svn/cgal/trunk/Scripts/scripts/cgal_create_makefile $
# $Id: cgal_create_makefile 36976 2007-03-09 22:53:24Z reichel $
#
# 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.
#
# Usage: cgal_create_cmake_script TYPE
#
# echo " TYPE can be any of "demo", "example" or "test".. any other value is ignored"
#VERSION=2.0
create_cmake_script()
{
# print makefile header
cat <<EOF
# Created by the script cgal_create_cmake_script
# This is the CMake script for compiling a CGAL application.
project( ${PROJECT}_${TYPE} )
EOF
cat <<'EOF'
cmake_minimum_required(VERSION 2.8.10)
set(CMAKE_CXX_STANDARD 14)
EOF
cat <<'EOF'
find_package(CGAL QUIET COMPONENTS Core )
if ( CGAL_FOUND )
include( ${CGAL_USE_FILE} )
include( CGAL_CreateSingleSourceCGALProgram )
EOF
if [ -d "${SOURCE_DIR}" ] ; then
echo " set(CGAL_CURRENT_SOURCE_DIR \"${SOURCE_DIR}\")"
echo
fi
if [ -d "${SOURCE_DIR}../../include" ] ; then
echo " include_directories (BEFORE \"${SOURCE_DIR}../../include\")"
echo
fi
if [ -d "${SOURCE_DIR}../include" ] ; then
echo " include_directories (BEFORE \"${SOURCE_DIR}../include\")"
echo
fi
if [ -d "${SOURCE_DIR}include" ] ; then
echo " include_directories (BEFORE \"${SOURCE_DIR}include\")"
echo
fi
for file in `ls "$SOURCE_DIR"*.cc "$SOURCE_DIR"*.cp "$SOURCE_DIR"*.cxx "$SOURCE_DIR"*.cpp "$SOURCE_DIR"*.CPP "$SOURCE_DIR"*.c++ "$SOURCE_DIR"*.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
echo " create_single_source_cgal_program( \"$file\" )"
echo "Adding a target ${BASE}..." >&3
fi
done
cat <<'EOF'
else()
message(STATUS "This program requires the CGAL library, and will not be compiled.")
endif()
EOF
echo
}
usage()
{
echo "Usage: cgal_create_cmake_script [--source_dir <source directory>]"
echo
echo " Create a CMakeLists.txt file in the current working directory."
echo
echo " TYPE must be any of example or test. The default is example."
echo
echo " If the option --source_dir is specified with a directory, the "
echo " CMakeLists.txt uses source files from that directory, otherwise "
echo " the source directory is supposed to be the current directory."
}
SOURCE_DIR=
while [ $1 ]; do
case "$1" in
-h|-help|--h|--help)
usage; exit
;;
example)
if [ -z "$TYPE" ]; then TYPE=$1; shift; else usage; exit 1; fi
;;
demo)
if [ -z "$TYPE" ]; then TYPE=$1; shift; else usage; exit 1; fi
;;
test)
if [ -z "$TYPE" ]; then TYPE=$1; shift; else usage; exit 1; fi
;;
--source_dir)
if [ -d "$2" ]; then
SOURCE_DIR=$2;
shift;
shift;
else
if [ -z "$2" ]; then
echo "Error: you must specify a directory after the --source_dir option!"
echo
else
echo "Error: \"$2\" is not a directory!"
echo
fi
usage; exit 1;
fi
;;
*)
echo "Unknown option: $1"
usage; exit 1
;;
esac
done
OUTPUTFILE=CMakeLists.txt
if [ -n "$SOURCE_DIR" ]; then
PROJECT=`basename $SOURCE_DIR`
SOURCE_DIR=$SOURCE_DIR/
else
PROJECT=`basename $PWD`
fi
if [ -f ${OUTPUTFILE} ] ; then
echo "moving $OUTPUTFILE to ${OUTPUTFILE}.bak ..."
mv -f $OUTPUTFILE ${OUTPUTFILE}.bak
fi
create_cmake_script 3>&1 > $OUTPUTFILE
echo "created $OUTPUTFILE in $PWD ..."