Commit 430bedea authored by Dominik Charousset's avatar Dominik Charousset

Add CMake scaffold

parent bd147156
This diff is collapsed.
# Try to find CAF headers and libraries.
#
# Use this module as follows:
#
# find_package(CAF [COMPONENTS <core|io|opencl|...>*] [REQUIRED])
#
# Variables used by this module (they can change the default behaviour and need
# to be set before calling find_package):
#
# CAF_ROOT_DIR Set this variable either to an installation prefix or to wa
# CAF build directory where to look for the CAF libraries.
#
# Variables defined by this module:
#
# CAF_FOUND System has CAF headers and library
# CAF_LIBRARIES List of library files for all components
# CAF_INCLUDE_DIRS List of include paths for all components
# CAF_LIBRARY_$C Library file for component $C
# CAF_INCLUDE_DIR_$C Include path for component $C
if(CAF_FIND_COMPONENTS STREQUAL "")
message(FATAL_ERROR "FindCAF requires at least one COMPONENT.")
endif()
# iterate over user-defined components
foreach (comp ${CAF_FIND_COMPONENTS})
# we use uppercase letters only for variable names
string(TOUPPER "${comp}" UPPERCOMP)
if ("${comp}" STREQUAL "core")
set(HDRNAME "caf/all.hpp")
elseif ("${comp}" STREQUAL "test")
set(HDRNAME "caf/test/unit_test.hpp")
else ()
set(HDRNAME "caf/${comp}/all.hpp")
endif ()
if (CAF_ROOT_DIR)
set(header_hints
"${CAF_ROOT_DIR}/include"
"${CAF_ROOT_DIR}/libcaf_${comp}"
"${CAF_ROOT_DIR}/../libcaf_${comp}"
"${CAF_ROOT_DIR}/../../libcaf_${comp}")
endif ()
find_path(CAF_INCLUDE_DIR_${UPPERCOMP}
NAMES
${HDRNAME}
HINTS
${header_hints}
/usr/include
/usr/local/include
/opt/local/include
/sw/include
${CMAKE_INSTALL_PREFIX}/include)
mark_as_advanced(CAF_INCLUDE_DIR_${UPPERCOMP})
if (NOT "${CAF_INCLUDE_DIR_${UPPERCOMP}}"
STREQUAL "CAF_INCLUDE_DIR_${UPPERCOMP}-NOTFOUND")
# mark as found (set back to false when missing library or build header)
set(CAF_${comp}_FOUND true)
# check for CMake-generated build header for the core component
if ("${comp}" STREQUAL "core")
find_path(caf_build_header_path
NAMES
caf/detail/build_config.hpp
HINTS
${header_hints}
/usr/include
/usr/local/include
/opt/local/include
/sw/include
${CMAKE_INSTALL_PREFIX}/include)
if ("${caf_build_header_path}" STREQUAL "caf_build_header_path-NOTFOUND")
message(WARNING "Found all.hpp for CAF core, but not build_config.hpp")
set(CAF_${comp}_FOUND false)
else()
list(APPEND CAF_INCLUDE_DIRS "${caf_build_header_path}")
endif()
endif()
list(APPEND CAF_INCLUDE_DIRS "${CAF_INCLUDE_DIR_${UPPERCOMP}}")
# look for (.dll|.so|.dylib) file, again giving hints for non-installed CAFs
# skip probe_event as it is header only
if (NOT ${comp} STREQUAL "probe_event" AND NOT ${comp} STREQUAL "test")
if (CAF_ROOT_DIR)
set(library_hints "${CAF_ROOT_DIR}/lib")
endif ()
find_library(CAF_LIBRARY_${UPPERCOMP}
NAMES
"caf_${comp}"
"caf_${comp}_static"
HINTS
${library_hints}
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
${CMAKE_INSTALL_PREFIX}/lib)
mark_as_advanced(CAF_LIBRARY_${UPPERCOMP})
if ("${CAF_LIBRARY_${UPPERCOMP}}"
STREQUAL "CAF_LIBRARY_${UPPERCOMP}-NOTFOUND")
set(CAF_${comp}_FOUND false)
else ()
set(CAF_LIBRARIES ${CAF_LIBRARIES} ${CAF_LIBRARY_${UPPERCOMP}})
endif ()
endif ()
endif ()
endforeach ()
if (DEFINED CAF_INCLUDE_DIRS)
list(REMOVE_DUPLICATES CAF_INCLUDE_DIRS)
endif()
# let CMake check whether all requested components have been found
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CAF
FOUND_VAR CAF_FOUND
REQUIRED_VARS CAF_LIBRARIES CAF_INCLUDE_DIRS
HANDLE_COMPONENTS)
# final step to tell CMake we're done
mark_as_advanced(CAF_ROOT_DIR
CAF_LIBRARIES
CAF_INCLUDE_DIRS)
if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest:
\"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"")
endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
list(REVERSE files)
foreach (file ${files})
message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
if (EXISTS "$ENV{DESTDIR}${file}")
execute_process(
COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}"
OUTPUT_VARIABLE rm_out
RESULT_VARIABLE rm_retval
)
if(NOT ${rm_retval} EQUAL 0)
message(FATAL_ERROR "Problem when removing
\"$ENV{DESTDIR}${file}\"")
endif (NOT ${rm_retval} EQUAL 0)
else (EXISTS "$ENV{DESTDIR}${file}")
message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.")
endif (EXISTS "$ENV{DESTDIR}${file}")
endforeach(file)
#include <iostream>
using namespace std;
int main() {
# ifdef __clang__
cout << __clang_major__
<< "."
<< __clang_minor__;
# elif defined(__GNUC__)
cout << __GNUC__
<< "."
<< __GNUC_MINOR__;
# else
cout << "0.0";
# endif
return 0;
}
#include "caf/test/unit_test_impl.hpp"
#!/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 $*"
dirname_0=`dirname $0`
sourcedir=`cd $dirname_0 && pwd`
usage="\
Usage: $0 [OPTION]... [VAR=VALUE]...
Build Options:
--generator=GENERATOR set CMake generator (see cmake --help)
--build-type=TYPE set CMake build type [RelWithDebInfo]:
- Debug: debugging flags enabled
- MinSizeRel: minimal output size
- Release: optimizations on, debugging off
- RelWithDebInfo: release flags plus debugging
--extra-flags=STRING additional compiler flags
--build-dir=DIR place build files in directory [build]
--bin-dir=DIR executable directory [build/bin]
--lib-dir=DIR library directory [build/lib]
--build-static build as static and shared library
--build-static-only build as static library only
--static-runtime build with static C++ runtime
--more-warnings enables most warnings
--no-compiler-check disable compiler version check
--no-auto-libc++ do not automatically enable libc++ for Clang
Required packages in non-standard locations:
--with-caf=PATH path to CAF install root or build directory
Installation Directories:
--prefix=PREFIX installation directory [/usr/local]
Debugging:
--enable-asan build with address sanitizer
Convenience options:
--dev-mode sets --build-type=debug and --enable-asan
Influential Environment Variables (only on first invocation):
CXX C++ compiler command
CXXFLAGS C++ compiler flags (overrides defaults)
LDFLAGS Additional linker flags
CMAKE_GENERATOR Selects a custom generator
Python Build Options:
--with-python-config=FILE Use python-conf binary to determine includes and libs
iOS Build Options (should be used with XCode generator):
--sysroot=DIR set system root for Clang
- iphoneos: for iOS device
- iphonesimulator: for iOS simulator
--ios-min-ver=VERSION set the ios deployment target version
"
# 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 ()
{
case "$3" in
*\ * )
# string contains whitespace
CMakeCacheEntries="$CMakeCacheEntries -D \"$1:$2=$3\""
;;
*)
# string contains whitespace
CMakeCacheEntries="$CMakeCacheEntries -D $1:$2=$3"
;;
esac
}
# -- set defaults --------------------------------------------------------------
builddir="$sourcedir/build"
CMakeCacheEntries=""
append_cache_entry CMAKE_INSTALL_PREFIX PATH /usr/local
# -- parse custom environment variables ----------------------------------------
if [ -n "$CMAKE_GENERATOR" ]; then
CMakeGenerator="$CMAKE_GENERATOR"
fi
# -- 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
;;
--generator=*)
CMakeGenerator="$optarg"
;;
--prefix=*)
append_cache_entry CMAKE_INSTALL_PREFIX PATH "$optarg"
;;
--enable-asan)
append_cache_entry CAF_ENABLE_ADDRESS_SANITIZER BOOL yes
;;
--more-warnings)
append_cache_entry CAF_MORE_WARNINGS BOOL yes
;;
--no-compiler-check)
append_cache_entry CAF_NO_COMPILER_CHECK BOOL yes
;;
--no-auto-libc++)
append_cache_entry CAF_NO_AUTO_LIBCPP BOOL yes
;;
--with-caf=*)
append_cache_entry CAF_ROOT_DIR PATH "$optarg"
;;
--sysroot=*)
append_cache_entry CAF_OSX_SYSROOT PATH "$optarg"
;;
--ios-min-ver=*)
append_cache_entry CMAKE_OSX_ARCHITECTURES STRING "\$(ARCHS_STANDARD_32_64_BIT)"
append_cache_entry CAF_IOS_DEPLOYMENT_TARGET STRING "$optarg"
;;
--build-type=*)
append_cache_entry CMAKE_BUILD_TYPE STRING "$optarg"
;;
--extra-flags=*)
append_cache_entry EXTRA_FLAGS STRING "$optarg"
;;
--build-dir=*)
builddir="$optarg"
;;
--bin-dir=*)
append_cache_entry EXECUTABLE_OUTPUT_PATH PATH "$optarg"
;;
--lib-dir=*)
append_cache_entry LIBRARY_OUTPUT_PATH PATH "$optarg"
;;
--no-curl-examples)
append_cache_entry CAF_NO_CURL_EXAMPLES BOOL yes
;;
--no-unit-tests)
append_cache_entry CAF_NO_UNIT_TESTS BOOL yes
;;
--no-opencl)
append_cache_entry CAF_NO_OPENCL BOOL yes
;;
--no-openssl)
append_cache_entry CAF_NO_OPENSSL BOOL yes
;;
--build-static)
append_cache_entry CAF_BUILD_STATIC BOOL yes
;;
--build-static-only)
append_cache_entry CAF_BUILD_STATIC_ONLY BOOL yes
;;
--static-runtime)
append_cache_entry CAF_BUILD_STATIC_RUNTIME BOOL yes
;;
--dev-mode)
append_cache_entry CMAKE_BUILD_TYPE STRING Debug
append_cache_entry CAF_ENABLE_ADDRESS_SANITIZER BOOL yes
;;
*)
echo "Invalid option '$1'. Try $0 --help to see available options."
exit 1
;;
esac
shift
done
# -- CMake setup ---------------------------------------------------------------
CMakeDefaultCache=$CMakeCacheEntries
CMakeCacheEntries=$CMakeDefaultCache
# Set $workdir to the absolute path of $builddir.
case "$builddir" in
/*)
# Absolute path given
workdir="$builddir"
;;
*)
# Relative path given, convert to absolute path.
workdir="$PWD/$builddir"
;;
esac
# Make sure the build directory exists but has no CMakeCache.txt in it.
if [ -d "$workdir" ]; then
if [ -f "$workdir/CMakeCache.txt" ]; then
rm -f "$workdir/CMakeCache.txt"
fi
else
mkdir -p "$workdir"
fi
cd "$workdir"
if [ -n "$CMakeGenerator" ]; then
cmake -G "$CMakeGenerator" $CMakeCacheEntries "$sourcedir"
else
cmake $CMakeCacheEntries "$sourcedir"
fi
printf "#!/bin/sh\n\n" > config.status
printf "# Switch to the source of this build directory.\n" >> config.status
printf "cd \"$sourcedir\"\n\n" >> config.status
printf "# Invoke the command to configure this build.\n" >> config.status
if [ -n "$CC" ]; then
printf "CC=\"%s\"\n" "$CC" >> config.status
fi
if [ -n "$CXX" ]; then
printf "CXX=\"%s\"\n" "$CXX" >> config.status
fi
if [ -n "$CXXFLAGS" ]; then
printf "CXXFLAGS=\"%s\"\n" "$CXXFLAGS" >> config.status
fi
if [ -n "$LDFLAGS" ]; then
printf "LDFLAGS=\"%s\"\n" "$LDFLAGS" >> config.status
fi
echo $command >> config.status
chmod u+x config.status
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