cmake_builder.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. # - BUILD_TYPE=Release/Debug
  9. # - LIB_TYPE=static/shared
  10. #
  11. # Optional environmental variables
  12. # - DESTDIR <- used for setting the install prefix
  13. # - BUILD_TOOL=["Unix Makefile"|"Ninja"]
  14. # - BUILDNAME <- how to identify this build on the dashboard
  15. # - DO_MemCheck <- if set, try to use valgrind
  16. # - DO_Coverage <- if set, try to do dashboard coverage testing
  17. #
  18. env_set=1
  19. if ${BUILD_TYPE+false}; then
  20. echo "BUILD_TYPE not set in environment."
  21. env_set=0
  22. fi
  23. if ${LIB_TYPE+false}; then
  24. echo "LIB_TYPE not set in environment."
  25. env_set=0
  26. fi
  27. if ${CXX+false}; then
  28. echo "CXX not set in environment."
  29. env_set=0
  30. fi
  31. if [ ${env_set} -eq 0 ]; then
  32. echo "USAGE: CXX=$(which clang++) BUILD_TYPE=[Release|Debug] LIB_TYPE=[static|shared] $0"
  33. echo ""
  34. echo "Examples:"
  35. echo " CXX=$(which clang++) BUILD_TYPE=Release LIB_TYPE=shared DESTDIR=/tmp/cmake_json_cpp $0"
  36. echo " CXX=$(which clang++) BUILD_TYPE=Debug LIB_TYPE=shared DESTDIR=/tmp/cmake_json_cpp $0"
  37. echo " CXX=$(which clang++) BUILD_TYPE=Release LIB_TYPE=static DESTDIR=/tmp/cmake_json_cpp $0"
  38. echo " CXX=$(which clang++) BUILD_TYPE=Debug LIB_TYPE=static DESTDIR=/tmp/cmake_json_cpp $0"
  39. echo " CXX=$(which g++) BUILD_TYPE=Release LIB_TYPE=shared DESTDIR=/tmp/cmake_json_cpp $0"
  40. echo " CXX=$(which g++) BUILD_TYPE=Debug LIB_TYPE=shared DESTDIR=/tmp/cmake_json_cpp $0"
  41. echo " CXX=$(which g++) BUILD_TYPE=Release LIB_TYPE=static DESTDIR=/tmp/cmake_json_cpp $0"
  42. echo " CXX=$(which g++) BUILD_TYPE=Debug LIB_TYPE=static DESTDIR=/tmp/cmake_json_cpp $0"
  43. exit -1
  44. fi
  45. if ${DESTDIR+false}; then
  46. DESTDIR="/usr/local"
  47. fi
  48. # -e: fail on error
  49. # -v: show commands
  50. # -x: show expanded commands
  51. set -vex
  52. env | sort
  53. which cmake
  54. cmake --version
  55. echo ${CXX}
  56. ${CXX} --version
  57. _COMPILER_NAME=`basename ${CXX}`
  58. if [ "${BUILD_TYPE}" == "shared" ]; then
  59. _CMAKE_BUILD_SHARED_LIBS=ON
  60. else
  61. _CMAKE_BUILD_SHARED_LIBS=OFF
  62. fi
  63. CTEST_TESTING_OPTION="-D ExperimentalTest"
  64. # - DO_MemCheck <- if set, try to use valgrind
  65. if ! ${DO_MemCheck+false}; then
  66. valgrind --version
  67. CTEST_TESTING_OPTION="-D ExperimentalMemCheck"
  68. else
  69. # - DO_Coverage <- if set, try to do dashboard coverage testing
  70. if ! ${DO_Coverage+false}; then
  71. export CXXFLAGS="-fprofile-arcs -ftest-coverage"
  72. export LDFLAGS="-fprofile-arcs -ftest-coverage"
  73. CTEST_TESTING_OPTION="-D ExperimentalTest -D ExperimentalCoverage"
  74. #gcov --version
  75. fi
  76. fi
  77. # Ninja = Generates build.ninja files.
  78. if ${BUILD_TOOL+false}; then
  79. BUILD_TOOL="Ninja"
  80. export _BUILD_EXE=ninja
  81. which ninja
  82. ninja --version
  83. else
  84. # Unix Makefiles = Generates standard UNIX makefiles.
  85. export _BUILD_EXE=make
  86. fi
  87. _BUILD_DIR_NAME="build-cmake_${BUILD_TYPE}_${LIB_TYPE}_${_COMPILER_NAME}_${_BUILD_EXE}"
  88. mkdir -p ${_BUILD_DIR_NAME}
  89. cd "${_BUILD_DIR_NAME}"
  90. if ${BUILDNAME+false}; then
  91. _HOSTNAME=`hostname -s`
  92. BUILDNAME="${_HOSTNAME}_${BUILD_TYPE}_${LIB_TYPE}_${_COMPILER_NAME}_${_BUILD_EXE}"
  93. fi
  94. cmake \
  95. -G "${BUILD_TOOL}" \
  96. -DBUILDNAME:STRING="${BUILDNAME}" \
  97. -DCMAKE_CXX_COMPILER:PATH=${CXX} \
  98. -DCMAKE_BUILD_TYPE:STRING=${BUILD_TYPE} \
  99. -DBUILD_SHARED_LIBS:BOOL=${_CMAKE_BUILD_SHARED_LIBS} \
  100. -DCMAKE_INSTALL_PREFIX:PATH=${DESTDIR} \
  101. ../
  102. ctest -C ${BUILD_TYPE} -D ExperimentalStart -D ExperimentalConfigure -D ExperimentalBuild ${CTEST_TESTING_OPTION} -D ExperimentalSubmit
  103. # Final step is to verify that installation succeeds
  104. cmake --build . --config ${BUILD_TYPE} --target install
  105. if [ "${DESTDIR}" != "/usr/local" ]; then
  106. ${_BUILD_EXE} install
  107. fi
  108. cd -
  109. if ${CLEANUP+false}; then
  110. echo "Skipping cleanup: build directory will persist."
  111. else
  112. rm -r "${_BUILD_DIR_NAME}"
  113. fi