Prev Next check_install.sh

@(@\newcommand{\R}[1]{ {\rm #1} } \newcommand{\B}[1]{ {\bf #1} } \newcommand{\W}[1]{ \; #1 \; }@)@
Example and Test Using the Installed Version of cppad_mixed

Syntax
build_type
Prefixes
cmake_libdir
example_file
PKG_CONFIG_PATH
LD_LIBRARY_PATH
Create Temporary
example_name
main
gsl_libs
ipopt_libs
suitesparse_libs
Compile and Link
Run Example

Syntax
bin/check_install.sh


build_type
Get the build_type used during the install:
 
cmd=`grep '^build_type=' bin/run_cmake.sh`
eval $cmd

Prefixes
Get the prefixes used during the install:
 
cmd=`grep '^cmake_install_prefix=' bin/run_cmake.sh`
eval $cmd
eigen_prefix="$cmake_install_prefix/eigen"
ipopt_prefix="$cmake_install_prefix"

cmake_libdir
Get the cmake_libdir used during the install:
 
cmd=`grep '^cmake_libdir=' bin/run_cmake.sh`
eval $cmd

example_file
This is the user example that we will compile using the installed version of cppad_mixed:
 
example_file='example/user/no_random.cpp'

PKG_CONFIG_PATH
Set the path used by $code pkg-config$$:
 
if [ "$PKG_CONFIG_PATH" == '' ]
then
export PKG_CONFIG_PATH="$ipopt_prefix/$cmake_libdir/pkgconfig"
else
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$ipopt_prefix/$cmake_libdir/pkgconfig"
fi

LD_LIBRARY_PATH
This setting is no longer required so test with it empty:
 
export LD_LIBRARY_PATH=''

Create Temporary
The following commands create a temporary directory, copy the example file into it, and make it the working directory:
 
mkdir -p build/tmp
cp $example_file build/tmp/example.cpp
cd build/tmp

example_name
The following command gets the example name, which is the example file with the .cpp at the end replaced by _xam:
 
example_name=`echo $example_file | sed -e 's|.*/||' -e 's|\.cpp|_xam|'`

main
The following command creates a main program (in the example.cpp file) that runs the example and reports the result of its return bool value:
 
cat << EOF >> example.cpp
int main(void)
{    if( ! $example_name() )
     {    std::cout << "$example_name: Error" << std::endl;
          std::exit(1);
     }
     std::cout << "$example_name: OK" << std::endl;
     exit(0);
}
EOF

gsl_libs
The following command determines the library link flags necessary to link ipopt on this system:
 
gsl_libs=`pkg-config --libs gsl`

ipopt_libs
The following command determines the library link flags necessary to link ipopt on this system:
 
ipopt_libs=`pkg-config --libs ipopt`

suitesparse_libs
The following command sets the library link flags necessary to link SuiteSparse on this system:
 
suitesparse_libs='-lcholmod -lamd -lcamd -lcolamd -lccolamd -lsuitesparseconfig'

Compile and Link
The command below compiles and links the example program. Note that the eigen include files have installed in a different directory and treated like system files because they otherwise generate lots of warnings.
 
if [ "$build_type" == 'debug' ]
then
     flags='-g -O0 -std=c++11 -Wall'
else
     flags='-O3 -DNDEBUG -std=c++11 -Wall'
fi
cat << EOF
g++ example.cpp \\
     $flags \\
     -I $cmake_install_prefix/include \\
     -isystem $eigen_prefix/include \\
     -L $cmake_install_prefix/$cmake_libdir -lcppad_mixed \\
     $gsl_libs \\
     $suitesparse_libs \\
     $ipopt_libs \\
     -o example
EOF
g++ example.cpp \
     $flags \
     -I $cmake_install_prefix/include \
     -isystem $eigen_prefix/include \
     -L $cmake_install_prefix/$cmake_libdir -lcppad_mixed \
    -Wl,-rpath=$cmake_install_prefix/$cmake_libdir \
     $gsl_libs \
     $suitesparse_libs \
     $ipopt_libs \
     -o example

Run Example
The following commands run the example:
 
if ! ./example
then
     echo 'check_install.sh: Error'
     exit 1
fi
echo 'check_install.sh: OK'
exit 0

Input File: bin/check_install.sh