• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env sh
2# This script can be used on the command line directly to configure several
3# different build environments.
4# This is called by `.travis.yml` via Travis CI.
5# Travis supplies $TRAVIS_OS_NAME.
6#  http://docs.travis-ci.com/user/multi-os/
7# Our .travis.yml also defines:
8
9#   - BUILD_TYPE=Release/Debug
10#   - LIB_TYPE=static/shared
11#
12# Optional environmental variables
13#   - DESTDIR <- used for setting the install prefix
14#   - BUILD_TOOL=["Unix Makefile"|"Ninja"]
15#   - BUILDNAME <- how to identify this build on the dashboard
16#   - DO_MemCheck <- if set, try to use valgrind
17#   - DO_Coverage <- if set, try to do dashboard coverage testing
18#
19
20env_set=1
21if ${BUILD_TYPE+false}; then
22  echo "BUILD_TYPE not set in environment."
23  env_set=0
24fi
25if ${LIB_TYPE+false}; then
26  echo "LIB_TYPE not set in environment."
27  env_set=0
28fi
29if ${CXX+false}; then
30  echo "CXX not set in environment."
31  env_set=0
32fi
33
34
35if [ ${env_set} -eq 0 ]; then
36  echo "USAGE:  CXX=$(which clang++)  BUILD_TYPE=[Release|Debug] LIB_TYPE=[static|shared] $0"
37  echo ""
38  echo "Examples:"
39  echo "           CXX=$(which clang++) BUILD_TYPE=Release LIB_TYPE=shared DESTDIR=/tmp/cmake_json_cpp $0"
40  echo "           CXX=$(which clang++) BUILD_TYPE=Debug   LIB_TYPE=shared DESTDIR=/tmp/cmake_json_cpp $0"
41  echo "           CXX=$(which clang++) BUILD_TYPE=Release LIB_TYPE=static DESTDIR=/tmp/cmake_json_cpp $0"
42  echo "           CXX=$(which clang++) BUILD_TYPE=Debug   LIB_TYPE=static DESTDIR=/tmp/cmake_json_cpp $0"
43
44  echo "           CXX=$(which g++)     BUILD_TYPE=Release LIB_TYPE=shared DESTDIR=/tmp/cmake_json_cpp $0"
45  echo "           CXX=$(which g++)     BUILD_TYPE=Debug   LIB_TYPE=shared DESTDIR=/tmp/cmake_json_cpp $0"
46  echo "           CXX=$(which g++)     BUILD_TYPE=Release LIB_TYPE=static DESTDIR=/tmp/cmake_json_cpp $0"
47  echo "           CXX=$(which g++)     BUILD_TYPE=Debug   LIB_TYPE=static DESTDIR=/tmp/cmake_json_cpp $0"
48
49  exit -1
50fi
51
52if ${DESTDIR+false}; then
53  DESTDIR="/usr/local"
54fi
55
56# -e: fail on error
57# -v: show commands
58# -x: show expanded commands
59set -vex
60
61env | sort
62
63which cmake
64cmake --version
65
66echo ${CXX}
67${CXX} --version
68_COMPILER_NAME=`basename ${CXX}`
69if [ "${BUILD_TYPE}" = "shared" ]; then
70  _CMAKE_BUILD_SHARED_LIBS=ON
71else
72  _CMAKE_BUILD_SHARED_LIBS=OFF
73fi
74
75CTEST_TESTING_OPTION="-D ExperimentalTest"
76#   - DO_MemCheck <- if set, try to use valgrind
77if ! ${DO_MemCheck+false}; then
78   valgrind --version
79   CTEST_TESTING_OPTION="-D ExperimentalMemCheck"
80else
81#   - DO_Coverage <- if set, try to do dashboard coverage testing
82  if ! ${DO_Coverage+false}; then
83     export CXXFLAGS="-fprofile-arcs -ftest-coverage"
84     export LDFLAGS="-fprofile-arcs -ftest-coverage"
85     CTEST_TESTING_OPTION="-D ExperimentalTest -D ExperimentalCoverage"
86     #gcov --version
87  fi
88fi
89
90#  Ninja                        = Generates build.ninja files.
91if ${BUILD_TOOL+false}; then
92  BUILD_TOOL="Ninja"
93  export _BUILD_EXE=ninja
94  which ninja
95  ninja --version
96else
97#  Unix Makefiles               = Generates standard UNIX makefiles.
98  export _BUILD_EXE=make
99fi
100
101# Language standard
102# Set default to ON
103if [ "${LANGUAGE_STANDARD}" = "98" ]; then
104  _BUILD_WITH_CXX_11=OFF
105else
106  _BUILD_WITH_CXX_11=ON
107fi
108
109_BUILD_DIR_NAME="build-cmake_${BUILD_TYPE}_${LIB_TYPE}_${_COMPILER_NAME}_${_BUILD_EXE}"
110mkdir -p ${_BUILD_DIR_NAME}
111cd "${_BUILD_DIR_NAME}"
112  if ${BUILDNAME+false}; then
113     _HOSTNAME=`hostname -s`
114     BUILDNAME="${_HOSTNAME}_${BUILD_TYPE}_${LIB_TYPE}_${_COMPILER_NAME}_${_BUILD_EXE}"
115  fi
116  cmake \
117    -G "${BUILD_TOOL}" \
118    -DBUILDNAME:STRING="${BUILDNAME}" \
119    -DCMAKE_CXX_COMPILER:PATH=${CXX} \
120    -DCMAKE_BUILD_TYPE:STRING=${BUILD_TYPE} \
121    -DBUILD_SHARED_LIBS:BOOL=${_CMAKE_BUILD_SHARED_LIBS} \
122    -DCMAKE_INSTALL_PREFIX:PATH=${DESTDIR} \
123    -DBUILD_WITH_CXX_11=${_BUILD_WITH_CXX_11} \
124    ../
125
126  ctest -C ${BUILD_TYPE} -D ExperimentalStart -D ExperimentalConfigure -D ExperimentalBuild ${CTEST_TESTING_OPTION} -D ExperimentalSubmit
127  # Final step is to verify that installation succeeds
128  cmake --build . --config ${BUILD_TYPE} --target install
129
130  if [ "${DESTDIR}" != "/usr/local" ]; then
131     ${_BUILD_EXE} install
132  fi
133cd -
134
135if ${CLEANUP+false}; then
136  echo "Skipping cleanup: build directory will persist."
137else
138  rm -r "${_BUILD_DIR_NAME}"
139fi
140