\(\newcommand{\B}[1]{ {\bf #1} }\) \(\newcommand{\R}[1]{ {\rm #1} }\) \(\newcommand{\W}[1]{ \; #1 \; }\)
check_install.sh¶
View page sourceExample and Test Using the Installed Version of cppad_mixed¶
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
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
eigen_cflags¶
The following command determines the flags necessary
to compile with eigen on this system:
eigen_cflags=$(pkg-config --cflags eigen3)
CHOLMOD_cflags¶
The following command determines the flags necessary
to compile with eigen on this system:
CHOLMOD_cflags=$(pkg-config --cflags CHOLMOD)
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`
CHOLMOD_libs¶
The following command sets the library link flags necessary
to link cholmod on this system:
CHOLMOD_libs=`pkg-config --libs CHOLMOD`
Compile and Link¶
The command below compiles and links the example program.
#
# optimize_flags
if [ "$build_type" == 'debug' ]
then
optimize_flags='-g -O0 -std=c++11 -Wall'
else
optimize_flags='-O3 -DNDEBUG -std=c++11 -Wall'
fi
#
# path2libdir
path2libdir="$cmake_install_prefix/$cmake_libdir"
#
# homebrew_flags
if [ -e /opt/homebrew ]
then
homebrew_flags='-Wno-bitwise-instead-of-logical'
homebrew_flags+=' -I /opt/homebrew/include'
homebrew_flags+=" -L /opt/homebrew/lib -Wl,-rpath,/opt/homebrew/lib"
else
homebrew_flags=""
fi
#
cat << EOF
g++ example.cpp \\
$optimize_flags \\
-I $cmake_install_prefix/include \\
-L $path2libdir -Wl,-rpath,$path2libdir -lcppad_mixed \\
$homebrew_flags \\
$eigen_cflags \\
$CHOLMOD_cflags \\
$gsl_libs \\
$CHOLMOD_libs \\
$ipopt_libs \\
-o example
EOF
g++ example.cpp \
$optimize_flags \
-I $cmake_install_prefix/include \
-L $path2libdir -Wl,-rpath,$path2libdir -lcppad_mixed \
$eigen_cflags \
$CHOLMOD_cflags \
$homebrew_flags \
$gsl_libs \
$CHOLMOD_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