1#!/bin/sh 2# 3# Generates a full project for a HeadersTest app. 4# This is a compile-time test checking if all the installed headers can be included individually. 5# 6# Example for KDb: 7# % ./headers_test.sh ~/kde/build/kdb ~/kde/src/kdb KDb kdb . 8# 9# It is assumed that this script is executed from the current build subdirectory. 10# Source dir goes to the app/ subdirectory, build dir goes to the app-build subdirectory. 11# Nothing is cached, both dirs are fully recreated on each run. 12 13set -e 14builddir="$1" 15current_builddir="`pwd`" 16shift 17srcdir="$1" 18 19if [ ! -d "$builddir" -o ! -d "$srcdir" -o $# -lt 4 ] ; then 20 echo "Usage: $me <project_binary_dir> <project_source_dir> <libraries_to_link> <project_name_prefix> <subdirs_to_find>..." 21 exit 1 22fi 23 24test_app_dir="$current_builddir/app" 25rm -rf "$test_app_dir" 26mkdir -p "$test_app_dir" 27 28test_app_builddir="$current_builddir/app-build" 29rm -rf "$test_app_builddir" 30mkdir -p "$test_app_builddir" 31 32me=headers_test.sh 33current_srcdir="`dirname \"$0\"`" 34 35shift 36link_libs="$1" 37shift 38prefix="$1" 39shift 40 41cd "$srcdir" 42 43cat <<EOT > "$test_app_dir/CMakeLists.txt" 44# Generated by $current_srcdir/$me 45# prefix: $prefix 46# link_libs: $link_libs 47# subdirs: $@ 48# 49# WARNING! All changes made in this file will be lost! 50# 51# Test if all the installed headers can be included individually. 52# This is a compile-time test. 53 54cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) 55find_package(ECM 1.8.0 REQUIRED NO_MODULE) 56set(CMAKE_MODULE_PATH "$current_srcdir" "$srcdir/cmake/modules" \${ECM_MODULE_PATH} \${ECM_KDE_MODULE_DIR}) 57 58project(HeadersTest) 59include(HeadersTestInclude NO_POLICY_SCOPE) 60 61add_executable( 62 HeadersTest 63 HeadersTest.cpp 64EOT 65 66cat <<EOT > "$test_app_dir/HeadersTest.cpp" 67// Generated by $me 68// WARNING! All changes made in this file will be lost! 69 70// Nothing to do here 71int main(int, char**) 72{ 73 return 0; 74} 75EOT 76 77# files to include using <name>, forward headers + some *.h headers 78find_files() 79{ 80 for subdir in "$@" ; do 81 find "$builddir/src/$subdir" -maxdepth 1 -type f -printf "%f\n" 82 done 83} 84 85for f in `find_files $@ | grep -v "\.h\$" | grep -vE "(\\.|Makefile)" | sort`; do 86 fname=${f}_HeaderTest.cpp 87 echo "#include <$f>" > $test_app_dir/$fname 88 echo " $fname" >> $test_app_dir/CMakeLists.txt 89done 90 91# files to include using <name>, these are .h files 92for f in `find_files $@ | grep "\.h\$" | grep -vE "^ui_.*\.h" | sort`; do 93 fname=${f}_HeaderTest.cpp 94 echo "#include <$f>" > $test_app_dir/$fname 95 echo " $fname" >> $test_app_dir/CMakeLists.txt 96done 97 98cat <<EOT >> "$test_app_dir/CMakeLists.txt" 99) 100 101target_link_libraries(HeadersTest 102 PUBLIC 103 $link_libs 104) 105 106feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) 107EOT 108 109# Finally, build: 110cd "$test_app_builddir" 111cmake ../app 112make 113