Home | History | Annotate | Download | only in cmake
      1 #!/bin/sh -e
      2 
      3 # Copyright 2015-2018 by
      4 # David Turner, Robert Wilhelm, and Werner Lemberg.
      5 #
      6 # This file is part of the FreeType project, and may only be used, modified,
      7 # and distributed under the terms of the FreeType project license,
      8 # LICENSE.TXT.  By continuing to use, modify, or distribute this file you
      9 # indicate that you have read the license and understand and accept it
     10 # fully.
     11 
     12 # This script tests the CMake build. Simply run
     13 #
     14 #     builds/cmake/testbuild.sh
     15 #
     16 # or
     17 #
     18 #     BUILD_SHARED_LIBS=1 builds/cmake/testbuild.sh
     19 #
     20 # The script:
     21 #
     22 # - builds the main CMakeLists.txt
     23 # - builds and runs a small test app in a separate build tree so
     24 #   the config-module is tested, too
     25 #
     26 # Options (environment variables):
     27 #
     28 # - The variable BUILD_SHARED_LIBS will be forwarded to the CMake project
     29 #   that builds the library.
     30 #
     31 
     32 
     33 # prepare temporary dir
     34 
     35 cd `dirname $0`/../..
     36 ftdir=`pwd`
     37 tmpdir=/tmp/freetype-cmake-testbuild
     38 rm -rf $tmpdir
     39 mkdir -p $tmpdir
     40 
     41 
     42 # build and install freetype
     43 
     44 if test -n "$BUILD_SHARED_LIBS"; then
     45   bsl=-DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS
     46 else
     47   bsl=-UBUILD_SHARED_LIBS
     48 fi
     49 
     50 build_opts="-DWITH_ZLIB=0 \
     51             -DWITH_BZip2=0 \
     52             -DWITH_PNG=0 \
     53             -DWITH_HarfBuzz=0 \
     54             $bsl \
     55             -DCMAKE_INSTALL_PREFIX=$tmpdir/out"
     56 
     57 (set -x; cmake -H$ftdir \
     58                -B$tmpdir/ftb \
     59                -DCMAKE_BUILD_TYPE=Debug \
     60                $build_opts)
     61 (set -x; cmake --build $tmpdir/ftb \
     62                --config Debug \
     63                --target install)
     64 
     65 (set -x; cmake $tmpdir/ftb \
     66                -DCMAKE_BUILD_TYPE=Release)
     67 (set -x; cmake --build $tmpdir/ftb \
     68                --config Release \
     69                --target install \
     70                --clean-first)
     71 
     72 
     73 # create test project CMakeLists.txt
     74 
     75 cat >$tmpdir/CMakeLists.txt << END
     76 cmake_minimum_required(VERSION 2.6)
     77 project(freetype-cmake-testbuild)
     78 
     79 find_package(Freetype REQUIRED CONFIG)
     80 
     81 add_executable(freetype-cmake-test main.c)
     82 target_link_libraries(freetype-cmake-test freetype)
     83 
     84 enable_testing()
     85 add_test(freetype-cmake-test freetype-cmake-test)
     86 END
     87 
     88 
     89 # create test project main.c
     90 
     91 cat >$tmpdir/main.c << END
     92 #include <stdio.h>
     93 #include <stdlib.h>
     94 
     95 #include <ft2build.h>
     96 #include FT_FREETYPE_H
     97 
     98 
     99 FT_Library library;
    100 
    101 
    102 int main(int argc,
    103          char*argv[])
    104 {
    105   FT_Error error;
    106   FT_Int major = 0;
    107   FT_Int minor = 0;
    108   FT_Int patch = 0;
    109 
    110   error = FT_Init_FreeType(&library);
    111   if (error)
    112     return EXIT_FAILURE;
    113 
    114   FT_Library_Version(library, &major, &minor, &patch);
    115   if (major != FREETYPE_MAJOR
    116       || minor != FREETYPE_MINOR
    117       || patch != FREETYPE_PATCH)
    118     return EXIT_FAILURE;
    119 
    120   printf("FT_Library_Version: %d.%d.%d\n", major, minor, patch);
    121 
    122   error = FT_Done_FreeType(library);
    123   if (error)
    124     return EXIT_FAILURE;
    125 
    126   return EXIT_SUCCESS;
    127 }
    128 END
    129 
    130 
    131 # build and test
    132 
    133 mkdir -p $tmpdir/tb
    134 cd $tmpdir/tb
    135 
    136 LD_LIBRARY_PATH=$tmpdir/out/lib:$LD_LIBRARY_PATH
    137 DYLD_LIBRARY_PATH=$tmpdir/out/lib:$DYLD_LIBRARY_PATH
    138 export LD_LIBRARY_PATH
    139 export DYLD_LIBRARY_PATH
    140 
    141 (set -x; cmake $tmpdir \
    142                -DCMAKE_BUILD_TYPE=Debug \
    143                -DCMAKE_PREFIX_PATH=$tmpdir/out)
    144 (set -x; cmake --build . \
    145                --config Debug)
    146 (set -x; ctest -V -C Debug)
    147 
    148 (set -x; cmake . \
    149                -DCMAKE_BUILD_TYPE=Release)
    150 (set -x; cmake --build . \
    151                --config Release \
    152                --clean-first)
    153 (set -x; ctest -V -C Release)
    154 
    155 rm -rf $tmpdir
    156 
    157 # EOF
    158