File indexing completed on 2024-04-21 08:29:07

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 manifest=$builddir/install_manifest.txt
0078 
0079 find_headers()
0080 {
0081     for f in $(grep -E "/include/.*/[[:alpha:]]+\.h$" "$manifest") ; do
0082         basename $f
0083     done
0084 }
0085 
0086 find_forwarding_headers()
0087 {
0088     for f in $(grep -E "/include/.*/[[:alpha:]]+$" "$manifest") ; do
0089         if grep -Eq "^#include \"[[:alpha:]]+\.h\"$" $f ; then
0090             basename $f
0091         fi
0092     done
0093 }
0094 
0095 for f in $(find_forwarding_headers; find_headers | sort); do
0096     fname=${f}_HeaderTest.cpp
0097     echo "#include <$f>" > $test_app_dir/$fname
0098     echo "    $fname" >> $test_app_dir/CMakeLists.txt
0099 done
0100 
0101 cat <<EOT >> "$test_app_dir/CMakeLists.txt"
0102 )
0103 
0104 target_link_libraries(HeadersTest
0105     PUBLIC
0106         $link_libs
0107 )
0108 
0109 feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
0110 EOT
0111 
0112 # Finally, build:
0113 cd "$test_app_builddir"
0114 
0115 CXXCOMPILER=`cmake -LA ../../.. | grep CMAKE_CXX_COMPILER || true`
0116 if [ -n "$CXXCOMPILER" ] ; then CXXCOMPILER=-D$CXXCOMPILER ; fi
0117 CCOMPILER=`cmake -LA ../../.. | grep CMAKE_C_COMPILER || true`
0118 if [ -n "$CCOMPILER" ] ; then CCOMPILER=-D$CCOMPILER ; fi
0119 
0120 echo cmake $CXXCOMPILER $CCOMPILER ../app
0121 cmake $CXXCOMPILER $CCOMPILER ../app
0122 make