Commit 15860274 authored by Dominik Charousset's avatar Dominik Charousset

Merge branch 'topic/build-tweaks' of https://github.com/mavam/libcppa into unstable

parents 9e36f2e3 594c4f2a
......@@ -12,3 +12,4 @@ libcppa.pc
bin/*
build/*
lib/*
Makefile
cmake_minimum_required(VERSION 2.4)
project(cppa CXX)
# Prohibit in-source builds.
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "In-source builds are not allowed. Please use "
"./configure to choose a build directory and "
"initialize the build configuration.")
endif ()
set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wextra -Wall -pedantic")
set(CMAKE_CXX_FLAGS "-std=c++11 -Wextra -Wall -pedantic")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os")
set(CMAKE_CXX_FLAGS_RELEASE "-O4")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
if (ENABLE_DEBUG)
set(CMAKE_BUILD_TYPE Debug)
add_definitions("-DCPPA_DEBUG")
endif ()
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
OUTPUT_VARIABLE GCC_VERSION)
if (NOT (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7))
message(FATAL_ERROR "${PROJECT_NAME} requires g++ 4.7 or greater.")
endif ()
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
else()
message(FATAL_ERROR "Your C++ compiler does not support C++11.")
endif ()
set(LIBCPPA_SRC
src/abstract_tuple.cpp
......@@ -116,12 +143,12 @@ install(TARGETS libcppa LIBRARY DESTINATION lib)
# install includes
install(DIRECTORY cppa/ DESTINATION include/cppa
FILES_MATCHING PATTERN "*.hpp")
# uninstall target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
......@@ -154,6 +181,7 @@ else ()
set (EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin CACHE PATH "Single directory for all executables")
endif ()
enable_testing()
add_subdirectory(unit_testing)
add_subdirectory(examples)
add_subdirectory(benchmarks)
......
#!/bin/sh
# Convenience wrapper for easily viewing/setting options that
# the project's CMake scripts will recognize.
# check for `cmake` command
type cmake > /dev/null 2>&1 || {
echo "\
This package requires CMake, please install it first, then you may
use this configure script to access CMake equivalent functionality.\
" >&2;
exit 1;
}
command="$0 $*"
sourcedir="$( cd "$( dirname "$0" )" && pwd )"
usage="\
Usage: $0 [OPTION]... [VAR=VALUE]...
Build Options:
--builddir=DIR place build files in directory [build]
--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:
--prefix=PREFIX installation directory [/usr/local]
Optional Features:
--enable-debug compile in debugging mode
--enable-perftools use Google perftools
Required Packages in Non-Standard Locations:
--with-boost=PATH path to Boost install root
Influential Environment Variables (only on first invocation
per build directory):
CXX C++ compiler command
CXXFLAGS C++ compiler flags
"
# Appends a CMake cache entry definition to the CMakeCacheEntries variable.
# $1 is the cache entry variable name
# $2 is the cache entry variable type
# $3 is the cache entry variable value
append_cache_entry ()
{
CMakeCacheEntries="$CMakeCacheEntries -D $1:$2=$3"
}
# Creates a build directory via CMake.
# $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=""
append_cache_entry CMAKE_INSTALL_PREFIX PATH /usr/local
append_cache_entry ENABLE_DEBUG BOOL false
# Parse arguments.
while [ $# -ne 0 ]; do
case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac
case "$1" in
--help|-h)
echo "${usage}" 1>&2
exit 1
;;
--builddir=*)
builddir=$optarg
;;
--generator=*)
CMakeGenerator="$optarg"
;;
--prefix=*)
append_cache_entry CMAKE_INSTALL_PREFIX PATH $optarg
;;
--enable-debug)
append_cache_entry ENABLE_DEBUG BOOL true
;;
--with-boost=*)
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."
exit 1
;;
esac
shift
done
if [ -n "$dualbuild" ]; then
# Use what we got in $PATH if --with-clang or --with-gcc is not specified.
if [ -z "$clang" ]; then
clang=clang++
fi
if [ -z "$gcc" ]; then
gcc=g++
fi
for i in gcc clang; do
compiler="$(eval echo \$$i)"
configure $compiler $i "" "" $CMakeGenerator
done
else
# Prefer Clang to GCC.
if [ -n "$clang" ]; then
compiler=$clang
elif [ -n "$gcc" ]; then
compiler=$gcc
fi
configure $compiler "" $bindir $libdir $CMakeGenerator
fi
echo "DIRS :=$workdirs\n" > $sourcedir/Makefile
read -d '' makefile <<"EOT"
all: configured
@for i in $(DIRS); do $(MAKE) -C $$i $@; done
configured:
@for i in $(DIRS); do \\
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
@for i in $(DIRS); do $(MAKE) -C $$i $@; done
install:
@for i in $(DIRS); do $(MAKE) -C $$i $@; done
uninstall: configured
@for i in $(DIRS); do $(MAKE) -C $$i $@; done
clean: configured
@for i in $(DIRS); do $(MAKE) -C $$i $@; done
distclean:
rm -rf $(DIRS) Makefile
.PHONY: all configured test install uninstall clean distclean
EOT
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"
......@@ -37,3 +37,5 @@ include_directories(. ${cppa_INCLUDE} ${Boost_INCLUDE_DIRS})
set(EXAMPLE_LIBS ${CMAKE_DL_LIBS} ${CPPA_LIBRARY} ${Boost_THREAD_LIBRARY})
target_link_libraries(unit_tests ${EXAMPLE_LIBS})
add_test(unit_tests ${EXECUTABLE_OUTPUT_PATH}/unit_tests)
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