Commit 9cfda04a authored by Dominik Charousset's avatar Dominik Charousset

let CMake check for clang >= 3.2

parent 270b9098
cmake_minimum_required(VERSION 2.4) cmake_minimum_required(VERSION 2.4)
project(cppa CXX) project(cppa CXX)
# Prohibit in-source builds. set(LIBCPPA_VERSION_MAJOR 0)
set(LIBCPPA_VERSION_MINOR 3)
set(LIBCPPA_VERSION_PATCH 0)
# prohibit in-source builds
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "In-source builds are not allowed. Please use " message(FATAL_ERROR "In-source builds are not allowed. Please use "
"./configure to choose a build directory and " "./configure to choose a build directory and "
...@@ -10,11 +14,10 @@ endif () ...@@ -10,11 +14,10 @@ endif ()
set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
# Check if the user provided CXXFLAGS on the command line. # check if the user provided CXXFLAGS on the command line
if (CMAKE_CXX_FLAGS) if (CMAKE_CXX_FLAGS)
set(CXXFLAGS_PROVIDED true) set(CXXFLAGS_PROVIDED true)
endif () endif ()
if (CXXFLAGS_PROVIDED) if (CXXFLAGS_PROVIDED)
set(CMAKE_CXX_FLAGS_DEBUG "") set(CMAKE_CXX_FLAGS_DEBUG "")
set(CMAKE_CXX_FLAGS_MINSIZEREL "") set(CMAKE_CXX_FLAGS_MINSIZEREL "")
...@@ -28,13 +31,25 @@ else () ...@@ -28,13 +31,25 @@ else ()
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
endif () endif ()
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") # check for g++ >= 4.7 or clang++ > = 3.2
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion try_run(ProgramResult
OUTPUT_VARIABLE GCC_VERSION) CompilationSucceeded
if (NOT (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7)) ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/src/get_compiler_version.cpp
message(FATAL_ERROR "${PROJECT_NAME} requires g++ 4.7 or greater.") RUN_OUTPUT_VARIABLE CompilerVersion)
if (NOT CompilationSucceeded OR NOT ProgramResult EQUAL 0)
message(FATAL_ERROR "Cannot determine compiler version")
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
if (CompilerVersion VERSION_GREATER 4.6)
message(STATUS "Found g++ version ${CompilerVersion}")
else ()
message(FATAL_ERROR "g++ >= 4.7 required (found: ${CompilerVersion}.")
endif () endif ()
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
if (CompilerVersion VERSION_GREATER 3.1)
message(STATUS "Found clang++ version ${CompilerVersion}")
else ()
message(FATAL_ERROR "clang++ >= 3.2 required (found: ${CompilerVersion}.")
endif ()
if (NOT CXXFLAGS_PROVIDED) if (NOT CXXFLAGS_PROVIDED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif () endif ()
...@@ -42,6 +57,7 @@ else () ...@@ -42,6 +57,7 @@ else ()
message(FATAL_ERROR "Your C++ compiler does not support C++11.") message(FATAL_ERROR "Your C++ compiler does not support C++11.")
endif () endif ()
# set build type (evaluate ENABLE_DEBUG flag)
if (ENABLE_DEBUG) if (ENABLE_DEBUG)
set(CMAKE_BUILD_TYPE Debug) set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCPPA_DEBUG") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCPPA_DEBUG")
...@@ -51,7 +67,7 @@ endif () ...@@ -51,7 +67,7 @@ endif ()
if (DISABLE_CONTEXT_SWITCHING) if (DISABLE_CONTEXT_SWITCHING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCPPA_DISABLE_CONTEXT_SWITCHING") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCPPA_DISABLE_CONTEXT_SWITCHING")
endif() endif ()
set(LIBCPPA_SRC set(LIBCPPA_SRC
src/abstract_tuple.cpp src/abstract_tuple.cpp
...@@ -111,22 +127,22 @@ set(LIBCPPA_SRC ...@@ -111,22 +127,22 @@ set(LIBCPPA_SRC
set(boost_context third_party/boost_context) set(boost_context third_party/boost_context)
# add third party Boost.Context sources if context-switching is enabled # add third party Boost.Context sources if context-switching is enabled
if(NOT DISABLE_CONTEXT_SWITCHING) if (NOT DISABLE_CONTEXT_SWITCHING)
if(CMAKE_SIZEOF_VOID_P EQUAL 4) if (CMAKE_SIZEOF_VOID_P EQUAL 4)
if(APPLE) if (APPLE)
set(fcontext_asm ${boost_context}/src/asm/fcontext_i386_sysv_macho_gas.S) set(fcontext_asm ${boost_context}/src/asm/fcontext_i386_sysv_macho_gas.S)
else() else ()
set(fcontext_asm ${boost_context}/src/asm/fcontext_i386_sysv_elf_gas.S) set(fcontext_asm ${boost_context}/src/asm/fcontext_i386_sysv_elf_gas.S)
endif() endif ()
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8) elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
if(APPLE) if (APPLE)
set(fcontext_asm ${boost_context}/src/asm/fcontext_x86_64_sysv_macho_gas.S) set(fcontext_asm ${boost_context}/src/asm/fcontext_x86_64_sysv_macho_gas.S)
else() else ()
set(fcontext_asm ${boost_context}/src/asm/fcontext_x86_64_sysv_elf_gas.S) set(fcontext_asm ${boost_context}/src/asm/fcontext_x86_64_sysv_elf_gas.S)
endif() endif ()
else() else ()
message(FATAL_ERROR "Unsupported platform (neither 32 nor 64 bit)") message(FATAL_ERROR "Unsupported platform (neither 32 nor 64 bit)")
endif() endif ()
set_property(SOURCE ${fcontext_asm} PROPERTY LANGUAGE CXX) set_property(SOURCE ${fcontext_asm} PROPERTY LANGUAGE CXX)
set(LIBCPPA_SRC set(LIBCPPA_SRC
${LIBCPPA_SRC} ${LIBCPPA_SRC}
...@@ -135,7 +151,7 @@ if(NOT DISABLE_CONTEXT_SWITCHING) ...@@ -135,7 +151,7 @@ if(NOT DISABLE_CONTEXT_SWITCHING)
${boost_context}/src/stack_allocator_posix.cpp ${boost_context}/src/stack_allocator_posix.cpp
${boost_context}/src/fcontext.cpp ${boost_context}/src/fcontext.cpp
) )
endif() endif ()
find_package(Boost COMPONENTS thread REQUIRED) find_package(Boost COMPONENTS thread REQUIRED)
...@@ -146,10 +162,6 @@ add_library(libcppa SHARED ${LIBCPPA_SRC}) ...@@ -146,10 +162,6 @@ add_library(libcppa SHARED ${LIBCPPA_SRC})
target_link_libraries(libcppa ${CMAKE_LD_LIBS} ${Boost_THREAD_LIBRARY}) target_link_libraries(libcppa ${CMAKE_LD_LIBS} ${Boost_THREAD_LIBRARY})
set(LIBCPPA_VERSION_MAJOR 0)
set(LIBCPPA_VERSION_MINOR 3)
set(LIBCPPA_VERSION_PATCH 0)
set(LIBRARY_VERSION ${LIBCPPA_VERSION_MAJOR}.${LIBCPPA_VERSION_MINOR}.${LIBCPPA_VERSION_PATCH}) set(LIBRARY_VERSION ${LIBCPPA_VERSION_MAJOR}.${LIBCPPA_VERSION_MINOR}.${LIBCPPA_VERSION_PATCH})
set(LIBRARY_SOVERSION ${LIBCPPA_VERSION_MAJOR}) set(LIBRARY_SOVERSION ${LIBCPPA_VERSION_MAJOR})
...@@ -178,11 +190,11 @@ add_custom_target(uninstall ...@@ -178,11 +190,11 @@ add_custom_target(uninstall
if (LIBRARY_OUTPUT_PATH) if (LIBRARY_OUTPUT_PATH)
set (CPPA_LIBRARY_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH}) set (CPPA_LIBRARY_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH})
set (CPPA_LIBRARY_PATH ${LIBRARY_OUTPUT_PATH}) set (CPPA_LIBRARY_PATH ${LIBRARY_OUTPUT_PATH})
else() else ()
set (CPPA_LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib) set (CPPA_LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib)
set (CPPA_LIBRARY_PATH ${CPPA_LIBRARY_OUTPUT_PATH}) set (CPPA_LIBRARY_PATH ${CPPA_LIBRARY_OUTPUT_PATH})
set (LIBRARY_OUTPUT_PATH ${CPPA_LIBRARY_OUTPUT_PATH} CACHE PATH "Single directory for all libraries") set (LIBRARY_OUTPUT_PATH ${CPPA_LIBRARY_OUTPUT_PATH} CACHE PATH "Single directory for all libraries")
endif() endif ()
# setting path to cppa headers and libcppa # setting path to cppa headers and libcppa
set (CPPA_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/libcppa) set (CPPA_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/libcppa)
...@@ -244,35 +256,37 @@ string(TOUPPER ${CMAKE_BUILD_TYPE} build_type) ...@@ -244,35 +256,37 @@ string(TOUPPER ${CMAKE_BUILD_TYPE} build_type)
set(CONTEXT_SWITCHING true) set(CONTEXT_SWITCHING true)
if (DISABLE_CONTEXT_SWITCHING) if (DISABLE_CONTEXT_SWITCHING)
set(CONTEXT_SWITCHING false) set(CONTEXT_SWITCHING false)
endif() endif ()
# check for doxygen and add custom "doc" target to Makefile # check for doxygen and add custom "doc" target to Makefile
find_package(Doxygen) find_package(Doxygen)
if (DOXYGEN_FOUND) if (DOXYGEN_FOUND)
configure_file(${CMAKE_SOURCE_DIR}/Doxyfile.in ${CMAKE_SOURCE_DIR}/Doxyfile @ONLY) configure_file(${CMAKE_SOURCE_DIR}/Doxyfile.in ${CMAKE_SOURCE_DIR}/Doxyfile
#add_custom_command(TARGET doc COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Doxyfile WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) @ONLY)
add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_HOME_DIRECTORY}/Doxyfile WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY} COMMENT "Generating API documentation with Doxygen" VERBATIM) add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_HOME_DIRECTORY}/Doxyfile
endif (DOXYGEN_FOUND) WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
endif ()
# done (print summary) # done (print summary)
message("\n====================| Build Summary |====================" message("\n====================| Build Summary |===================="
"\n" "\n"
"\nLibcppa version: ${LIBRARY_VERSION}" "\nLibcppa version: ${LIBRARY_VERSION}"
"\n" "\n"
"\nBuild type: ${CMAKE_BUILD_TYPE}" "\nBuild type: ${CMAKE_BUILD_TYPE}"
"\nDebug mode: ${ENABLE_DEBUG}" "\nDebug mode: ${ENABLE_DEBUG}"
"\nContext switching: ${CONTEXT_SWITCHING}" "\nContext switching: ${CONTEXT_SWITCHING}"
"\n" "\n"
"\nCXX: ${CMAKE_CXX_COMPILER}" "\nCXX: ${CMAKE_CXX_COMPILER}"
"\nCXXFLAGS: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${build_type}}" "\nCXXFLAGS: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${build_type}}"
"\n" "\n"
"\nSource directory: ${CMAKE_SOURCE_DIR}" "\nSource directory: ${CMAKE_SOURCE_DIR}"
"\nBuild directory: ${CMAKE_BINARY_DIR}" "\nBuild directory: ${CMAKE_BINARY_DIR}"
"\nExecutable path: ${EXECUTABLE_OUTPUT_PATH}" "\nExecutable path: ${EXECUTABLE_OUTPUT_PATH}"
"\nLibrary path: ${LIBRARY_OUTPUT_PATH}" "\nLibrary path: ${LIBRARY_OUTPUT_PATH}"
"\nInstall prefix: ${CMAKE_INSTALL_PREFIX}" "\nInstall prefix: ${CMAKE_INSTALL_PREFIX}"
"\n" "\n"
"\nBoost: ${Boost_INCLUDE_DIR}" "\nBoost: ${Boost_INCLUDE_DIR}"
"\n" "\n"
"\n===========================================================\n" "\n===========================================================\n")
)
#include <iostream>
using namespace std;
int main() {
# ifdef __clang__
cout << __clang_major__
<< "."
<< __clang_minor__
<< endl;
# elif defined(__GNUC__)
cout << __GNUC__
<< "."
<< __GNUC_MINOR__
<< endl;
# else
cout << "0.0" << endl;
# endif
return 0;
}
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