Commit 594c4f2a authored by Matthias Vallentin's avatar Matthias Vallentin

Update ./configure to support dual builds.

The new configure script now supports the functionality previously provided by
mk_dual_build.sh. To enable a dual-build, provide --dual-build on the command
line. Moreover, the script also supports other new options to control the build
process:

    --with-clang=/path/to/clang++
    --with-gcc=/path/to/g++
    --bin-dir=/path/to/executables
    --lib-dir=/path/to/libraries
parent 3a1ef36e
#!/bin/sh #!/bin/sh
# Convenience wrapper for easily viewing/setting options that # Convenience wrapper for easily viewing/setting options that
# the project's CMake scripts will recognize # the project's CMake scripts will recognize.
command="$0 $*"
# check for `cmake` command # check for `cmake` command
type cmake > /dev/null 2>&1 || { type cmake > /dev/null 2>&1 || {
...@@ -13,12 +11,19 @@ use this configure script to access CMake equivalent functionality.\ ...@@ -13,12 +11,19 @@ use this configure script to access CMake equivalent functionality.\
exit 1; exit 1;
} }
command="$0 $*"
sourcedir="$( cd "$( dirname "$0" )" && pwd )"
usage="\ usage="\
Usage: $0 [OPTION]... [VAR=VALUE]... Usage: $0 [OPTION]... [VAR=VALUE]...
Build Options: Build Options:
--builddir=DIR place build files in directory [build] --builddir=DIR place build files in directory [build]
--generator=GENERATOR CMake generator to use (see cmake --help) --generator=GENERATOR CMake generator to use (see cmake --help)
--with-clang=FILE path to clang++ executable
--with-gcc=FILE path to g++ executable
--bin-dir=DIR executable directory [build/bin]
--lib-dir=DIR library directory [build/lib]
--dual-build build both with gcc and clang
Installation Directories: Installation Directories:
--prefix=PREFIX installation directory [/usr/local] --prefix=PREFIX installation directory [/usr/local]
...@@ -37,24 +42,91 @@ Usage: $0 [OPTION]... [VAR=VALUE]... ...@@ -37,24 +42,91 @@ Usage: $0 [OPTION]... [VAR=VALUE]...
" "
sourcedir="$( cd "$( dirname "$0" )" && pwd )" # Appends a CMake cache entry definition to the CMakeCacheEntries variable.
# Function to append a CMake cache entry definition to the
# CMakeCacheEntries variable
# $1 is the cache entry variable name # $1 is the cache entry variable name
# $2 is the cache entry variable type # $2 is the cache entry variable type
# $3 is the cache entry variable value # $3 is the cache entry variable value
append_cache_entry () { append_cache_entry ()
{
CMakeCacheEntries="$CMakeCacheEntries -D $1:$2=$3" CMakeCacheEntries="$CMakeCacheEntries -D $1:$2=$3"
} }
# Set defaults # Creates a build directory via CMake.
builddir=build # $1 is the path to a compiler executable.
# $2 is the suffix of the build directory.
# $3 is the executable output path.
# $4 is the library output path.
# $5 is the CMake generator.
configure ()
{
CMakeCacheEntries=""
echo "-------------------------------------------------"
if [ -n "$1" ]; then
append_cache_entry CMAKE_CXX_COMPILER FILEPATH $1
echo "compiler: $1"
else
echo "compiler: system default"
fi
if [ -n "$2" ]; then
workdir="$builddir-$2"
else
workdir=$builddir
fi
workdirs="$workdirs $workdir"
echo "build directory: $workdir"
if [ -n "$3" ]; then
append_cache_entry EXECUTABLE_OUTPUT_PATH PATH $3
echo "executable output directory: $3"
else
append_cache_entry EXECUTABLE_OUTPUT_PATH PATH "$workdir/bin"
echo "executable output directory: $workdir/bin"
fi
if [ -n "$4" ]; then
append_cache_entry LIBRARY_OUTPUT_PATH PATH $4
echo "library output directory: $4"
else
append_cache_entry LIBRARY_OUTPUT_PATH PATH "$workdir/lib"
echo "library output directory: $workdir/lib"
fi
echo "-------------------------------------------------"
if [ -d $workdir ]; then
# If a build directory exists, check if it has a CMake cache.
if [ -f $workdir/CMakeCache.txt ]; then
# If the CMake cache exists, delete it so that this configuration
# is not tainted by a previous one.
rm -f $workdir/CMakeCache.txt
fi
else
mkdir -p $workdir
fi
cd $workdir
if [ -n "$5" ]; then
cmake -G "$5" $CMakeCacheEntries $sourcedir
else
cmake $CMakeCacheEntries $sourcedir
fi
echo "# This is the command used to configure this build" > config.status
echo $command >> config.status
chmod u+x config.status
}
# Set defaults.
builddir="$sourcedir/build"
CMakeCacheEntries="" CMakeCacheEntries=""
append_cache_entry CMAKE_INSTALL_PREFIX PATH /usr/local append_cache_entry CMAKE_INSTALL_PREFIX PATH /usr/local
append_cache_entry ENABLE_DEBUG BOOL false append_cache_entry ENABLE_DEBUG BOOL false
# parse arguments # Parse arguments.
while [ $# -ne 0 ]; do while [ $# -ne 0 ]; do
case "$1" in case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
...@@ -81,6 +153,21 @@ while [ $# -ne 0 ]; do ...@@ -81,6 +153,21 @@ while [ $# -ne 0 ]; do
--with-boost=*) --with-boost=*)
append_cache_entry BOOST_ROOT PATH $optarg append_cache_entry BOOST_ROOT PATH $optarg
;; ;;
--with-clang=*)
clang=$optarg
;;
--with-gcc=*)
gcc=$optarg
;;
--bin-dir=*)
bindir=$optarg
;;
--lib-dir=*)
libdir=$optarg
;;
--dual-build)
dualbuild=1
;;
*) *)
echo "Invalid option '$1'. Try $0 --help to see available options." echo "Invalid option '$1'. Try $0 --help to see available options."
exit 1 exit 1
...@@ -89,61 +176,59 @@ while [ $# -ne 0 ]; do ...@@ -89,61 +176,59 @@ while [ $# -ne 0 ]; do
shift shift
done done
if [ -d $builddir ]; then if [ -n "$dualbuild" ]; then
# If build directory exists, check if it has a CMake cache # Use what we got in $PATH if --with-clang or --with-gcc is not specified.
if [ -f $builddir/CMakeCache.txt ]; then if [ -z "$clang" ]; then
# If the CMake cache exists, delete it so that this configuration clang=clang++
# is not tainted by a previous one fi
rm -f $builddir/CMakeCache.txt if [ -z "$gcc" ]; then
gcc=g++
fi fi
else
# Create build directory
mkdir -p $builddir
fi
echo "Build Directory : $builddir"
echo "Source Directory: $sourcedir"
cd $builddir
if [ -n "$CMakeGenerator" ]; then for i in gcc clang; do
cmake -G "$CMakeGenerator" $CMakeCacheEntries $sourcedir compiler="$(eval echo \$$i)"
configure $compiler $i "" "" $CMakeGenerator
done
else else
cmake $CMakeCacheEntries $sourcedir # Prefer Clang to GCC.
fi if [ -n "$clang" ]; then
compiler=$clang
echo "# This is the command used to configure this build" > config.status elif [ -n "$gcc" ]; then
echo $command >> config.status compiler=$gcc
chmod u+x config.status fi
echo "BUILD=$builddir\n" > $sourcedir/Makefile configure $compiler "" $bindir $libdir $CMakeGenerator
fi
echo "DIRS :=$workdirs\n" > $sourcedir/Makefile
read -d '' makefile <<"EOT" read -d '' makefile <<"EOT"
all: configured all: configured
@$(MAKE) -C $(BUILD) $@ @for i in $(DIRS); do $(MAKE) -C $$i $@; done
configured: configured:
@test -d $(BUILD) || ( echo "Error: No build/ directory found. Did you run configure?" && exit 1 ) @for i in $(DIRS); do \\
@test -e $(BUILD)/Makefile || ( echo "Error: No build/Makefile found. Did you run configure?" && exit 1 ) test -d $$i || \\
( echo "Error: No build directory found. Did you run configure?" && exit 1 ); \\
test -e $$i/Makefile || \\
( echo "Error: No Makefile in build directory found. Did you run configure?" && exit 1 ); \\
done
test: configured test: configured
@$(MAKE) -C $(BUILD) $@ @for i in $(DIRS); do $(MAKE) -C $$i $@; done
install: install:
@$(MAKE) -C $(BUILD) $@ @for i in $(DIRS); do $(MAKE) -C $$i $@; done
uninstall: configured uninstall: configured
@$(MAKE) -C $(BUILD) $@ @for i in $(DIRS); do $(MAKE) -C $$i $@; done
clean: configured clean: configured
@$(MAKE) -C $(BUILD) $@ @for i in $(DIRS); do $(MAKE) -C $$i $@; done
distclean: distclean:
rm -rf $(BUILD) rm -rf $(DIRS) Makefile
doc:
@$(MAKE) -C $(BUILD) $@
.PHONY : all configured test install uninstall clean distclean doc .PHONY: all configured test install uninstall clean distclean
EOT EOT
echo "$makefile" >> $sourcedir/Makefile echo "$makefile" >> $sourcedir/Makefile
#!/bin/bash
if test "$#" != "2" ; then
echo "usage: $0 [path_to_clang++] [path_to_g++]"
exit
fi
echo "using clang: $1"
echo "using gcc: $2"
rm -rf clang_build
rm -r gcc_build
topDir=$PWD
mkdir clang_build
cd clang_build
cmake .. -DCMAKE_CXX_COMPILER="$1" -DCMAKE_CXX_FLAGS="-stdlib=libc++ -DCPPA_DEBUG -pedantic -Wall -Wextra -Werror" -DEXECUTABLE_OUTPUT_PATH="$topDir/clang_bin/" -DLIBRARY_OUTPUT_PATH="$topDir/clang_lib"
cd ..
mkdir gcc_build
cd gcc_build
cmake .. -DCMAKE_CXX_COMPILER="$2" -DCMAKE_CXX_FLAGS="-DCPPA_DEBUG -pedantic -Wall -Wextra -Werror" -DEXECUTABLE_OUTPUT_PATH="$topDir/gcc_bin/" -DLIBRARY_OUTPUT_PATH="$topDir/gcc_lib"
cd ..
exec > Makefile
printf "all:\n"
printf "\tmake -C gcc_build\n"
printf "\tmake -C clang_build\n"
printf "\n"
printf "clean:\n"
printf "\tmake clean -C gcc_build\n"
printf "\tmake clean -C clang_build\n"
printf "\n"
printf "test:\n"
printf "\texport DYLD_LIBRARY_PATH=$topDir/gcc_lib\n"
printf "\t./gcc_bin/unit_tests\n"
printf "\texport DYLD_LIBRARY_PATH=$topDir/clang_lib\n"
printf "\t./clang_bin/unit_tests\n"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment