File indexing completed on 2024-04-21 04:40:58

0001 #!/bin/sh
0002 #
0003 # Generates a full project for a HeadersTest app.
0004 # This is a compile-time test checking if all the installed headers can be included individually.
0005 #
0006 # Example for KDb:
0007 # % ./headers_test.sh ~/kde/build/kdb ~/kde/src/kdb KDb kdb .
0008 #
0009 # It is assumed that this script is executed from the current build subdirectory.
0010 # Source dir goes to the app/ subdirectory, build dir goes to the app-build subdirectory.
0011 # Nothing is cached, both dirs are fully recreated on each run.
0012 
0013 set -e
0014 builddir="$1"
0015 current_builddir="`pwd`"
0016 shift
0017 srcdir="$1"
0018 
0019 if [ ! -d "$builddir" -o ! -d "$srcdir" -o $# -lt 4 ] ; then
0020     echo "Usage: $me <project_binary_dir> <project_source_dir> <libraries_to_link> <project_name_prefix> <subdirs_to_find>..."
0021     exit 1
0022 fi
0023 
0024 test_app_dir="$current_builddir/app"
0025 rm -rf "$test_app_dir"
0026 mkdir -p "$test_app_dir"
0027 
0028 test_app_builddir="$current_builddir/app-build"
0029 rm -rf "$test_app_builddir"
0030 mkdir -p "$test_app_builddir"
0031 
0032 me=headers_test.sh
0033 current_srcdir="`dirname \"$0\"`"
0034 
0035 shift
0036 link_libs="$1"
0037 shift
0038 prefix="$1"
0039 shift
0040 
0041 cd "$srcdir"
0042 
0043 cat <<EOT > "$test_app_dir/CMakeLists.txt"
0044 # Generated by $current_srcdir/$me
0045 # prefix: $prefix
0046 # link_libs: $link_libs
0047 # subdirs: $@
0048 #
0049 # WARNING! All changes made in this file will be lost!
0050 #
0051 # Test if all the installed headers can be included individually.
0052 # This is a compile-time test.
0053 
0054 cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
0055 find_package(ECM 1.8.0 REQUIRED NO_MODULE)
0056 set(CMAKE_MODULE_PATH "$current_srcdir" "$srcdir/cmake/modules" \${ECM_MODULE_PATH})
0057 
0058 project(HeadersTest)
0059 include(HeadersTestInclude NO_POLICY_SCOPE)
0060 
0061 add_executable(
0062     HeadersTest
0063     HeadersTest.cpp
0064 EOT
0065 
0066 cat <<EOT > "$test_app_dir/HeadersTest.cpp"
0067 // Generated by $me
0068 // WARNING! All changes made in this file will be lost!
0069 
0070 // Nothing to do here
0071 int main(int, char**)
0072 {
0073     return 0;
0074 }
0075 EOT
0076 
0077 # files to include using <name>, forward headers + some *.h headers
0078 find_files()
0079 {
0080     for subdir in "$@" ; do
0081         find "$builddir/src/$subdir" -maxdepth 1 -type f -printf "%f\n"
0082     done
0083 }
0084 
0085 for f in `find_files $@ | grep -v "\.h\$" | grep -vE "(\\.|Makefile)" | sort`; do
0086     fname=${f}_HeaderTest.cpp
0087     echo "#include <$f>" > $test_app_dir/$fname
0088     echo "    $fname" >> $test_app_dir/CMakeLists.txt
0089 done
0090 
0091 # files to include using <name>, these are .h files
0092 for f in `find_files $@ | grep "\.h\$" | grep -vE "^ui_.*\.h" | sort`; do
0093     fname=${f}_HeaderTest.cpp
0094     echo "#include <$f>" > $test_app_dir/$fname
0095     echo "    $fname" >> $test_app_dir/CMakeLists.txt
0096 done
0097 
0098 cat <<EOT >> "$test_app_dir/CMakeLists.txt"
0099 )
0100 
0101 target_link_libraries(HeadersTest
0102     PUBLIC
0103         $link_libs
0104 )
0105 
0106 feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
0107 EOT
0108 
0109 # Finally, build:
0110 cd "$test_app_builddir"
0111 cmake ../app
0112 make