1#!/bin/sh
2
3# This file for Linux users,
4# launches CMake and creates configuration for
5# Release and Debug modes.
6
7
8echo
9echo ============= Checking for CMake ============
10echo
11
12if (cmake --version); then
13    echo "Found CMake"
14    echo
15else
16    echo "Error: CMake not found, please install it (see http://www.cmake.org/)"
17    exit 1
18fi
19
20# Parse command line arguments
21
22cmake_options=
23build_name_suffix=
24while [ -n "$1" ]; do
25    case "$1" in
26        --debug)
27            cmake_options="$cmake_options --trace"
28            shift
29            ;;
30        --with-*=*)
31            cmake_option=`echo "$1" | sed 's/--with-\([^=]*\)=\(.*\)$/-DVORPALINE_WITH_\U\1\E:STRING="\2"/'`
32            cmake_options="$cmake_options $cmake_option"
33            shift
34            ;;
35
36        --with-*)
37            cmake_option=`echo "$1" | sed 's/--with-\(.*\)$/-DVORPALINE_WITH_\U\1:BOOL=TRUE/'`
38            cmake_options="$cmake_options $cmake_option"
39            shift
40            ;;
41
42        --help-platforms)
43            echo "Supported platforms:"
44            for i in `find cmake/platforms/* -type d`
45            do
46                if [ $i != "xxxcmake/platforms" ]
47                then
48                    echo "*" `basename $i`
49                fi
50            done
51            exit
52            ;;
53        --build_name_suffix=*)
54            build_name_suffix=`echo "$1" | sed 's/--build_name_suffix=\(.*\)$/\1/'`
55            shift
56            ;;
57
58        --help)
59            cat <<END
60NAME
61    configure.sh
62
63SYNOPSIS
64    Prepares the build environment for Geogram/Vorpaline.
65    
66    - For Unix builds, the script creates 2 build trees for Debug and Release
67    build in a 'build' sub directory under the project root.
68
69    - For Windows builds, the script creates a single build tree that supports
70    all cmake build types (Debug, Release, RelWithDebInfo, MinSizeRel)
71    build in a 'build' sub directory under the project root.
72
73USAGE
74    configure.sh [options] build-platform
75
76OPTIONS
77
78    --help
79        Prints this page.
80
81    --with-gcov
82        Builds the project for coverage analysis with gcov    
83
84    --with-gprof
85        Builds the project for performance analysis with gprof
86
87    --with-asan
88        Builds the project with Google's AddressSanitizer (dynamic builds only)
89        See: http://code.google.com/p/address-sanitizer/
90
91    --with-tsan
92        Builds the project with Google's ThreadSanitizer (dynamic builds only)
93        See: https://code.google.com/p/thread-sanitizer/
94
95    --with-ddt=ddt-root-dir
96        Builds the project for memory analysis with Allinea's DDT installed in
97        the specified directory: ddt-root-dir
98
99    --build_name_suffix=suffix-dir
100        Add a suffix to define the build directory
101
102PLATFORM
103    Build platforms supported by Geogram/Vorpaline: use configure.sh --help-platforms
104END
105            exit
106            ;;
107
108        -*)
109            echo "Error: unrecognized option: $1"
110            return 1
111            ;;
112        *)
113            break;
114            ;;
115    esac
116done
117
118# Check the current OS
119
120os="$1"
121if [ -z "$os" ]; then
122    os=`uname -a`
123    case "$os" in
124        Linux*x86_64*)
125            os=Linux64-gcc-dynamic
126            ;;
127        Linux*amd64*)
128            os=Linux64-gcc-dynamic
129            ;;
130        Linux*i586*|Linux*i686*)
131            os=Linux32-gcc-dynamic
132            ;;
133        Darwin*)
134            os=Darwin-clang-dynamic
135            ;;
136        Linux*aarch64*Android)
137            os=Android-aarch64-gcc-dynamic
138            ;;
139        *)
140            echo "Error: OS not supported: $os"
141            exit 1
142            ;;
143    esac
144fi
145
146#  Import plaform specific environment
147
148if [ ! -f cmake/platforms/$os/setvars.sh ]
149then
150    echo $os: no such platform
151    exit 1
152fi
153
154. cmake/platforms/$os/setvars.sh || exit 1
155
156# Generate the Makefiles
157
158for config in Release Debug; do
159   platform=$os-$config
160   echo
161   echo ============= Creating makefiles for $platform ============
162   echo
163
164   build_dir=build/$platform$build_name_suffix
165   mkdir -p $build_dir
166   (cd $build_dir; cmake -DCMAKE_BUILD_TYPE:STRING=$config -DVORPALINE_PLATFORM:STRING=$os $cmake_options ../../)
167done
168
169echo
170echo ============== Geogram build configured ==================
171echo
172
173cat << EOF
174To build geogram:
175  - go to build/$os-Release$build_name_suffix or build/$os-Debug$build_name_suffix
176  - run 'make' or 'cmake --build .'
177
178Note: local configuration can be specified in CMakeOptions.txt
179(see CMakeOptions.txt.sample for an example)
180You'll need to re-run configure.sh if you create or modify CMakeOptions.txt
181
182EOF
183