mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'devel' of https://github.com/arangodb/arangodb into spdvpk
This commit is contained in:
commit
0bd6ac52cd
|
@ -65,16 +65,16 @@ else()
|
|||
message(ERROR "Not implemented for your OS")
|
||||
endif()
|
||||
|
||||
|
||||
include(ExternalProject)
|
||||
set (V8_BUILD_COMMAND $(MAKE) -f Makefile-v8 strictaliasing=off
|
||||
snapshot=off werror=no "${V8_PLATFORM}" CC="${CMAKE_C_COMPILER}"
|
||||
CXX="${CMAKE_CXX_COMPILER}" PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE})
|
||||
CXX="${CMAKE_CXX_COMPILER}" PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
|
||||
CXXFLAGS=${CMAKE_CXX_FLAGS})
|
||||
if (APPLE AND CMAKE_COMPILER_IS_CLANG)
|
||||
set (V8_BUILD_COMMAND "${V8_BUILD_COMMAND}" CXXFLAGS=-stdlib=libc++ LDFLAGS=-stdlib=libc++)
|
||||
set (V8_BUILD_COMMAND "${V8_BUILD_COMMAND} LDFLAGS=-stdlib=libc++")
|
||||
endif()
|
||||
ExternalProject_Add(v8_build SOURCE_DIR "${V8_DIR}"
|
||||
BUILD_IN_SOURCE TRUE BUILD_COMMAND "${V8_BUILD_COMMAND}"
|
||||
BUILD_IN_SOURCE TRUE BUILD_COMMAND "${V8_BUILD_COMMAND}"
|
||||
INSTALL_COMMAND "")
|
||||
|
||||
## V8
|
||||
|
@ -87,7 +87,6 @@ import_target(v8_libbase v8_build "${V8_DIR}/include"
|
|||
import_target(v8_libplatform v8_build "${V8_DIR}/include"
|
||||
"${V8_BIN_DIR}/libv8_libplatform.a")
|
||||
|
||||
|
||||
import_target(v8_nosnapshot v8_build "${V8_DIR}/include"
|
||||
"${V8_BIN_DIR}/libv8_nosnapshot.a")
|
||||
|
||||
|
|
|
@ -169,6 +169,10 @@ endif ()
|
|||
# Architecture
|
||||
math(EXPR BITS "8*${CMAKE_SIZEOF_VOID_P}")
|
||||
add_definitions("-DTRI_BITS=${BITS}")
|
||||
include (VcMacros)
|
||||
include (OptimizeForArchitecture)
|
||||
OptimizeForArchitecture()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Vc_ARCHITECTURE_FLAGS}")
|
||||
|
||||
# Enable Backtrace -------------------------------------------------------------
|
||||
option(USE_BACKTRACE "whether we should try to generate c-level stacktraces"
|
||||
|
|
|
@ -0,0 +1,176 @@
|
|||
# - Add a given compiler flag to flags variables.
|
||||
# AddCompilerFlag(<flag> [<var>])
|
||||
# or
|
||||
# AddCompilerFlag(<flag> [C_FLAGS <var>] [CXX_FLAGS <var>] [C_RESULT <var>]
|
||||
# [CXX_RESULT <var>])
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2010-2013 Matthias Kretz <kretz@kde.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# * The names of Kitware, Inc., the Insight Consortium, or the names of
|
||||
# any consortium members, or of any contributors, may not be used to
|
||||
# endorse or promote products derived from this software without
|
||||
# specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
|
||||
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#=============================================================================
|
||||
|
||||
get_filename_component(_currentDir "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
include("${_currentDir}/CheckCCompilerFlag.cmake")
|
||||
include("${_currentDir}/CheckCXXCompilerFlag.cmake")
|
||||
include("${_currentDir}/CheckMicCCompilerFlag.cmake")
|
||||
include("${_currentDir}/CheckMicCXXCompilerFlag.cmake")
|
||||
|
||||
macro(AddCompilerFlag _flag)
|
||||
string(REGEX REPLACE "[-.+/:= ]" "_" _flag_esc "${_flag}")
|
||||
|
||||
set(_c_flags "CMAKE_C_FLAGS")
|
||||
set(_cxx_flags "CMAKE_CXX_FLAGS")
|
||||
set(_mic_c_flags "CMAKE_MIC_C_FLAGS")
|
||||
set(_mic_cxx_flags "CMAKE_MIC_CXX_FLAGS")
|
||||
set(_c_result tmp)
|
||||
set(_cxx_result tmp)
|
||||
set(_mic_c_result)
|
||||
set(_mic_cxx_result)
|
||||
if(${ARGC} EQUAL 2)
|
||||
message(WARNING "Deprecated use of the AddCompilerFlag macro.")
|
||||
unset(_c_result)
|
||||
set(_cxx_result ${ARGV1})
|
||||
elseif(${ARGC} GREATER 2)
|
||||
set(state 0)
|
||||
unset(_c_flags)
|
||||
unset(_cxx_flags)
|
||||
unset(_mic_c_flags)
|
||||
unset(_mic_cxx_flags)
|
||||
unset(_c_result)
|
||||
unset(_cxx_result)
|
||||
unset(_mic_c_result)
|
||||
unset(_mic_cxx_result)
|
||||
foreach(_arg ${ARGN})
|
||||
if(_arg STREQUAL "C_FLAGS")
|
||||
set(state 1)
|
||||
if(NOT DEFINED _c_result)
|
||||
set(_c_result tmp0)
|
||||
endif()
|
||||
elseif(_arg STREQUAL "CXX_FLAGS")
|
||||
set(state 2)
|
||||
if(NOT DEFINED _cxx_result)
|
||||
set(_cxx_result tmp1)
|
||||
endif()
|
||||
elseif(_arg STREQUAL "C_RESULT")
|
||||
set(state 3)
|
||||
elseif(_arg STREQUAL "CXX_RESULT")
|
||||
set(state 4)
|
||||
elseif(_arg STREQUAL "MIC_C_RESULT")
|
||||
set(state 5)
|
||||
elseif(_arg STREQUAL "MIC_CXX_RESULT")
|
||||
set(state 6)
|
||||
elseif(_arg STREQUAL "MIC_C_FLAGS")
|
||||
if(NOT DEFINED _mic_c_result)
|
||||
set(_mic_c_result tmp2)
|
||||
endif()
|
||||
set(state 7)
|
||||
elseif(_arg STREQUAL "MIC_CXX_FLAGS")
|
||||
if(NOT DEFINED _mic_cxx_result)
|
||||
set(_mic_cxx_result tmp3)
|
||||
endif()
|
||||
set(state 8)
|
||||
elseif(state EQUAL 1)
|
||||
set(_c_flags "${_arg}")
|
||||
elseif(state EQUAL 2)
|
||||
set(_cxx_flags "${_arg}")
|
||||
elseif(state EQUAL 3)
|
||||
set(_c_result "${_arg}")
|
||||
elseif(state EQUAL 4)
|
||||
set(_cxx_result "${_arg}")
|
||||
elseif(state EQUAL 5)
|
||||
set(_mic_c_result "${_arg}")
|
||||
elseif(state EQUAL 6)
|
||||
set(_mic_cxx_result "${_arg}")
|
||||
elseif(state EQUAL 7)
|
||||
set(_mic_c_flags "${_arg}")
|
||||
elseif(state EQUAL 8)
|
||||
set(_mic_cxx_flags "${_arg}")
|
||||
else()
|
||||
message(FATAL_ERROR "Syntax error for AddCompilerFlag")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if("${_flag}" STREQUAL "-mfma")
|
||||
# Compiling with FMA3 support may fail only at the assembler level.
|
||||
# In that case we need to have such an instruction in the test code
|
||||
set(_code "#include <immintrin.h>
|
||||
__m128 foo(__m128 x) { return _mm_fmadd_ps(x, x, x); }
|
||||
int main() { return 0; }")
|
||||
elseif("${_flag}" STREQUAL "-stdlib=libc++")
|
||||
# Compiling with libc++ not only requires a compiler that understands it, but also
|
||||
# the libc++ headers itself
|
||||
set(_code "#include <iostream>
|
||||
int main() { return 0; }")
|
||||
else()
|
||||
set(_code "int main() { return 0; }")
|
||||
endif()
|
||||
|
||||
if(DEFINED _c_result)
|
||||
check_c_compiler_flag("${_flag}" check_c_compiler_flag_${_flag_esc} "${_code}")
|
||||
set(${_c_result} ${check_c_compiler_flag_${_flag_esc}})
|
||||
endif()
|
||||
if(DEFINED _cxx_result)
|
||||
check_cxx_compiler_flag("${_flag}" check_cxx_compiler_flag_${_flag_esc} "${_code}")
|
||||
set(${_cxx_result} ${check_cxx_compiler_flag_${_flag_esc}})
|
||||
endif()
|
||||
|
||||
if(check_c_compiler_flag_${_flag_esc} AND DEFINED _c_flags)
|
||||
if(${_c_flags})
|
||||
set(${_c_flags} "${${_c_flags}} ${_flag}")
|
||||
else()
|
||||
set(${_c_flags} "${_flag}")
|
||||
endif()
|
||||
endif()
|
||||
if(check_cxx_compiler_flag_${_flag_esc} AND DEFINED _cxx_flags)
|
||||
if(${_cxx_flags})
|
||||
set(${_cxx_flags} "${${_cxx_flags}} ${_flag}")
|
||||
else()
|
||||
set(${_cxx_flags} "${_flag}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MIC_NATIVE_FOUND)
|
||||
if(DEFINED _mic_c_result)
|
||||
check_mic_c_compiler_flag("${_flag}" check_mic_c_compiler_flag_${_flag_esc} "${_code}")
|
||||
set(${_mic_c_result} ${check_mic_c_compiler_flag_${_flag_esc}})
|
||||
endif()
|
||||
if(DEFINED _mic_cxx_result)
|
||||
check_mic_cxx_compiler_flag("${_flag}" check_mic_cxx_compiler_flag_${_flag_esc} "${_code}")
|
||||
set(${_mic_cxx_result} ${check_mic_cxx_compiler_flag_${_flag_esc}})
|
||||
endif()
|
||||
|
||||
if(check_mic_c_compiler_flag_${_flag_esc} AND DEFINED _mic_c_flags)
|
||||
set(${_mic_c_flags} "${${_mic_c_flags}} ${_flag}")
|
||||
endif()
|
||||
if(check_mic_cxx_compiler_flag_${_flag_esc} AND DEFINED _mic_cxx_flags)
|
||||
set(${_mic_cxx_flags} "${${_mic_cxx_flags}} ${_flag}")
|
||||
endif()
|
||||
endif()
|
||||
endmacro(AddCompilerFlag)
|
|
@ -0,0 +1,159 @@
|
|||
# - Check which parts of the C++11 standard the compiler supports
|
||||
#
|
||||
# When found it will set the following variables
|
||||
#
|
||||
# CXX11_COMPILER_FLAGS - the compiler flags needed to get C++11 features
|
||||
#
|
||||
# HAS_CXX11_AUTO - auto keyword
|
||||
# HAS_CXX11_AUTO_RET_TYPE - function declaration with deduced return types
|
||||
# HAS_CXX11_CLASS_OVERRIDE - override and final keywords for classes and methods
|
||||
# HAS_CXX11_CONSTEXPR - constexpr keyword
|
||||
# HAS_CXX11_CSTDINT_H - cstdint header
|
||||
# HAS_CXX11_DECLTYPE - decltype keyword
|
||||
# HAS_CXX11_FUNC - __func__ preprocessor constant
|
||||
# HAS_CXX11_INITIALIZER_LIST - initializer list
|
||||
# HAS_CXX11_LAMBDA - lambdas
|
||||
# HAS_CXX11_LIB_REGEX - regex library
|
||||
# HAS_CXX11_LONG_LONG - long long signed & unsigned types
|
||||
# HAS_CXX11_NULLPTR - nullptr
|
||||
# HAS_CXX11_RVALUE_REFERENCES - rvalue references
|
||||
# HAS_CXX11_SIZEOF_MEMBER - sizeof() non-static members
|
||||
# HAS_CXX11_STATIC_ASSERT - static_assert()
|
||||
# HAS_CXX11_VARIADIC_TEMPLATES - variadic templates
|
||||
# HAS_CXX11_SHARED_PTR - Shared Pointer
|
||||
# HAS_CXX11_THREAD - thread
|
||||
# HAS_CXX11_MUTEX - mutex
|
||||
# HAS_CXX11_NOEXCEPT - noexcept
|
||||
# HAS_CXX11_CONDITIONAL - conditional type definitions
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2011,2012 Rolf Eike Beer <eike@sf-mail.de>
|
||||
# Copyright 2012 Andreas Weis
|
||||
# Copyright 2014 Kaveh Vahedipour <kaveh@codeare.org>
|
||||
#
|
||||
# Distributed under the OSI-approved BSD License (the "License");
|
||||
# see accompanying file Copyright.txt for details.
|
||||
#
|
||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the License for more information.
|
||||
#=============================================================================
|
||||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
#
|
||||
# Each feature may have up to 3 checks, every one of them in it's own file
|
||||
# FEATURE.cpp - example that must build and return 0 when run
|
||||
# FEATURE_fail.cpp - example that must build, but may not return 0 when run
|
||||
# FEATURE_fail_compile.cpp - example that must fail compilation
|
||||
#
|
||||
# The first one is mandatory, the latter 2 are optional and do not depend on
|
||||
# each other (i.e. only one may be present).
|
||||
#
|
||||
# Modification for std::thread (Kaveh Vahdipour, Forschungszentrum Juelich)
|
||||
#
|
||||
|
||||
IF (NOT CMAKE_CXX_COMPILER_LOADED)
|
||||
message(FATAL_ERROR "CheckCXX11Features modules only works if language CXX is enabled")
|
||||
endif ()
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.3)
|
||||
|
||||
#
|
||||
### Check for needed compiler flags
|
||||
#
|
||||
include(CheckCXXCompilerFlag)
|
||||
check_cxx_compiler_flag("-std=c++11" _HAS_CXX11_FLAG)
|
||||
if (NOT _HAS_CXX11_FLAG)
|
||||
check_cxx_compiler_flag("-std=c++0x" _HAS_CXX0X_FLAG)
|
||||
endif ()
|
||||
|
||||
if (_HAS_CXX11_FLAG)
|
||||
set(CXX11_COMPILER_FLAGS "-std=c++11")
|
||||
elseif (_HAS_CXX0X_FLAG)
|
||||
set(CXX11_COMPILER_FLAGS "-std=c++0x")
|
||||
endif ()
|
||||
|
||||
function(cxx11_check_feature FEATURE_NAME RESULT_VAR)
|
||||
if (NOT DEFINED ${RESULT_VAR})
|
||||
set(_bindir "${CMAKE_CURRENT_BINARY_DIR}/cxx11_${FEATURE_NAME}")
|
||||
|
||||
set(_SRCFILE_BASE ${CMAKE_CURRENT_LIST_DIR}/CheckCXX11Features/cxx11-test-${FEATURE_NAME})
|
||||
set(_LOG_NAME "\"${FEATURE_NAME}\"")
|
||||
message(STATUS "Checking C++11 support for ${_LOG_NAME}")
|
||||
|
||||
set(_SRCFILE "${_SRCFILE_BASE}.cpp")
|
||||
set(_SRCFILE_FAIL "${_SRCFILE_BASE}_fail.cpp")
|
||||
set(_SRCFILE_FAIL_COMPILE "${_SRCFILE_BASE}_fail_compile.cpp")
|
||||
|
||||
if (CROSS_COMPILING)
|
||||
try_compile(${RESULT_VAR} "${_bindir}" "${_SRCFILE}"
|
||||
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
|
||||
if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
|
||||
try_compile(${RESULT_VAR} "${_bindir}_fail" "${_SRCFILE_FAIL}"
|
||||
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
|
||||
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
|
||||
else (CROSS_COMPILING)
|
||||
try_run(_RUN_RESULT_VAR _COMPILE_RESULT_VAR
|
||||
"${_bindir}" "${_SRCFILE}"
|
||||
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
|
||||
if (_COMPILE_RESULT_VAR AND NOT _RUN_RESULT_VAR)
|
||||
set(${RESULT_VAR} TRUE)
|
||||
else (_COMPILE_RESULT_VAR AND NOT _RUN_RESULT_VAR)
|
||||
set(${RESULT_VAR} FALSE)
|
||||
endif (_COMPILE_RESULT_VAR AND NOT _RUN_RESULT_VAR)
|
||||
if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
|
||||
try_run(_RUN_RESULT_VAR _COMPILE_RESULT_VAR
|
||||
"${_bindir}_fail" "${_SRCFILE_FAIL}"
|
||||
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
|
||||
if (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR)
|
||||
set(${RESULT_VAR} TRUE)
|
||||
else (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR)
|
||||
set(${RESULT_VAR} FALSE)
|
||||
endif (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR)
|
||||
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
|
||||
endif (CROSS_COMPILING)
|
||||
if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE})
|
||||
try_compile(_TMP_RESULT "${_bindir}_fail_compile" "${_SRCFILE_FAIL_COMPILE}"
|
||||
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
|
||||
if (_TMP_RESULT)
|
||||
set(${RESULT_VAR} FALSE)
|
||||
else (_TMP_RESULT)
|
||||
set(${RESULT_VAR} TRUE)
|
||||
endif (_TMP_RESULT)
|
||||
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE})
|
||||
|
||||
if (${RESULT_VAR})
|
||||
message(STATUS "Checking C++11 support for ${_LOG_NAME}: works")
|
||||
else (${RESULT_VAR})
|
||||
message(STATUS "Checking C++11 support for ${_LOG_NAME}: not supported")
|
||||
endif (${RESULT_VAR})
|
||||
set(${RESULT_VAR} ${${RESULT_VAR}} CACHE INTERNAL "C++11 support for ${_LOG_NAME}")
|
||||
endif (NOT DEFINED ${RESULT_VAR})
|
||||
endfunction(cxx11_check_feature)
|
||||
|
||||
cxx11_check_feature("__func__" HAS_CXX11_FUNC)
|
||||
cxx11_check_feature("auto" HAS_CXX11_AUTO)
|
||||
cxx11_check_feature("auto_ret_type" HAS_CXX11_AUTO_RET_TYPE)
|
||||
cxx11_check_feature("class_override_final" HAS_CXX11_CLASS_OVERRIDE)
|
||||
cxx11_check_feature("constexpr" HAS_CXX11_CONSTEXPR)
|
||||
cxx11_check_feature("conditional" HAS_CXX11_CONDITIONAL)
|
||||
#cxx11_check_feature("cstdint" HAS_CXX11_CSTDINT_H)
|
||||
cxx11_check_feature("decltype" HAS_CXX11_DECLTYPE)
|
||||
cxx11_check_feature("initializer_list" HAS_CXX11_INITIALIZER_LIST)
|
||||
cxx11_check_feature("lambda" HAS_CXX11_LAMBDA)
|
||||
cxx11_check_feature("range_based_for_loop" HAS_CXX11_RANGE_BASED_FOR_LOOP)
|
||||
#cxx11_check_feature("long_long" HAS_CXX11_LONG_LONG)
|
||||
cxx11_check_feature("nullptr" HAS_CXX11_NULLPTR)
|
||||
cxx11_check_feature("tuple" HAS_CXX11_TUPLE)
|
||||
cxx11_check_feature("regex" HAS_CXX11_LIB_REGEX)
|
||||
cxx11_check_feature("rvalue-references" HAS_CXX11_RVALUE_REFERENCES)
|
||||
cxx11_check_feature("sizeof_member" HAS_CXX11_SIZEOF_MEMBER)
|
||||
cxx11_check_feature("static_assert" HAS_CXX11_STATIC_ASSERT)
|
||||
cxx11_check_feature("variadic_templates" HAS_CXX11_VARIADIC_TEMPLATES)
|
||||
cxx11_check_feature("shared_ptr" HAS_CXX11_SHARED_PTR)
|
||||
cxx11_check_feature("unique_ptr" HAS_CXX11_UNIQUE_PTR)
|
||||
cxx11_check_feature("weak_ptr" HAS_CXX11_WEAK_PTR)
|
||||
cxx11_check_feature("thread" HAS_CXX11_THREAD)
|
||||
cxx11_check_feature("mutex" HAS_CXX11_MUTEX)
|
||||
cxx11_check_feature("noexcept" HAS_CXX11_NOEXCEPT)
|
|
@ -0,0 +1,8 @@
|
|||
int main(void)
|
||||
{
|
||||
if (!__func__)
|
||||
return 1;
|
||||
if (!(*__func__))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
auto i = 5;
|
||||
auto f = 3.14159f;
|
||||
auto d = 3.14159;
|
||||
bool ret = (
|
||||
(sizeof(f) < sizeof(d)) &&
|
||||
(sizeof(i) == sizeof(int))
|
||||
);
|
||||
return ret ? 0 : 1;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
int main(void)
|
||||
{
|
||||
// must fail because there is no initializer
|
||||
auto i;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
auto foo(int i) -> int {
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
return foo(1);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
class base {
|
||||
public:
|
||||
virtual int foo(int a)
|
||||
{ return 4 + a; }
|
||||
int bar(int a) final
|
||||
{ return a - 2; }
|
||||
};
|
||||
|
||||
class sub final : public base {
|
||||
public:
|
||||
virtual int foo(int a) override
|
||||
{ return 8 + 2 * a; };
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
base b;
|
||||
sub s;
|
||||
|
||||
return (b.foo(2) * 2 == s.foo(2)) ? 0 : 1;
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
class base {
|
||||
public:
|
||||
virtual int foo(int a)
|
||||
{ return 4 + a; }
|
||||
virtual int bar(int a) final
|
||||
{ return a - 2; }
|
||||
};
|
||||
|
||||
class sub final : public base {
|
||||
public:
|
||||
virtual int foo(int a) override
|
||||
{ return 8 + 2 * a; };
|
||||
virtual int bar(int a)
|
||||
{ return a; }
|
||||
};
|
||||
|
||||
class impossible : public sub { };
|
||||
|
||||
int main(void)
|
||||
{
|
||||
base b;
|
||||
sub s;
|
||||
|
||||
return 1;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#include <type_traits>
|
||||
#include <string>
|
||||
|
||||
template<class T> class A {
|
||||
public:
|
||||
typedef typename std::conditional<false, const std::string, std::string>::type StringType;
|
||||
A() : s(""), t(0) {}
|
||||
virtual ~A () {}
|
||||
private:
|
||||
StringType s;
|
||||
T t;
|
||||
};
|
||||
|
||||
int main() {
|
||||
A<float> a;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
constexpr int square(int x)
|
||||
{
|
||||
return x*x;
|
||||
}
|
||||
|
||||
constexpr int the_answer()
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int test_arr[square(3)];
|
||||
bool ret = (
|
||||
(square(the_answer()) == 1764) &&
|
||||
(sizeof(test_arr)/sizeof(test_arr[0]) == 9)
|
||||
);
|
||||
return ret ? 0 : 1;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
#include <cstdint>
|
||||
|
||||
int main()
|
||||
{
|
||||
bool test =
|
||||
(sizeof(int8_t) == 1) &&
|
||||
(sizeof(int16_t) == 2) &&
|
||||
(sizeof(int32_t) == 4) &&
|
||||
(sizeof(int64_t) == 8);
|
||||
return test ? 0 : 1;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
bool check_size(int i)
|
||||
{
|
||||
return sizeof(int) == sizeof(decltype(i));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
bool ret = check_size(42);
|
||||
return ret ? 0 : 1;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
#include <vector>
|
||||
|
||||
class seq {
|
||||
public:
|
||||
seq(std::initializer_list<int> list);
|
||||
|
||||
int length() const;
|
||||
private:
|
||||
std::vector<int> m_v;
|
||||
};
|
||||
|
||||
seq::seq(std::initializer_list<int> list)
|
||||
: m_v(list)
|
||||
{
|
||||
}
|
||||
|
||||
int seq::length() const
|
||||
{
|
||||
return m_v.size();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
seq a = {18, 20, 2, 0, 4, 7};
|
||||
|
||||
return (a.length() == 6) ? 0 : 1;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
int main()
|
||||
{
|
||||
int ret = 0;
|
||||
return ([&ret]() -> int { return ret; })();
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
int main(void)
|
||||
{
|
||||
long long l;
|
||||
unsigned long long ul;
|
||||
|
||||
return ((sizeof(l) >= 8) && (sizeof(ul) >= 8)) ? 0 : 1;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#include <mutex>
|
||||
|
||||
int main() {
|
||||
std::mutex _mutex;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
volatile void dummy () noexcept {
|
||||
int a = 0;
|
||||
}
|
||||
|
||||
int main () {
|
||||
dummy();
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
int main(void)
|
||||
{
|
||||
void *v = nullptr;
|
||||
|
||||
return v ? 1 : 0;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
int main(void)
|
||||
{
|
||||
int i = nullptr;
|
||||
|
||||
return 1;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
|
||||
int main() {
|
||||
int my_array[5] = {1, 2, 3, 4, 5};
|
||||
|
||||
for (int &x : my_array) {
|
||||
x *= 2;
|
||||
}
|
||||
|
||||
for (auto &x : my_array) {
|
||||
x *= 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#include <algorithm>
|
||||
#include <regex>
|
||||
|
||||
int parse_line(std::string const& line)
|
||||
{
|
||||
std::string tmp;
|
||||
if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+//(-)?(\\d)+(\\s)+"))) {
|
||||
tmp = std::regex_replace(line, std::regex("(-)?(\\d)+//(-)?(\\d)+"), std::string("V"));
|
||||
} else if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+/(-)?(\\d)+(\\s)+"))) {
|
||||
tmp = std::regex_replace(line, std::regex("(-)?(\\d)+/(-)?(\\d)+"), std::string("V"));
|
||||
} else if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+/(-)?(\\d)+/(-)?(\\d)+(\\s)+"))) {
|
||||
tmp = std::regex_replace(line, std::regex("(-)?(\\d)+/(-)?(\\d)+/(-)?(\\d)+"), std::string("V"));
|
||||
} else {
|
||||
tmp = std::regex_replace(line, std::regex("(-)?(\\d)+"), std::string("V"));
|
||||
}
|
||||
return static_cast<int>(std::count(tmp.begin(), tmp.end(), 'V'));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
bool test = (parse_line("f 7/7/7 -3/3/-3 2/-2/2") == 3) &&
|
||||
(parse_line("f 7//7 3//-3 -2//2") == 3) &&
|
||||
(parse_line("f 7/7 3/-3 -2/2") == 3) &&
|
||||
(parse_line("f 7 3 -2") == 3);
|
||||
return test ? 0 : 1;
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
#include <cassert>
|
||||
|
||||
class rvmove {
|
||||
public:
|
||||
void *ptr;
|
||||
char *array;
|
||||
|
||||
rvmove()
|
||||
: ptr(0),
|
||||
array(new char[10])
|
||||
{
|
||||
ptr = this;
|
||||
}
|
||||
|
||||
rvmove(rvmove &&other)
|
||||
: ptr(other.ptr),
|
||||
array(other.array)
|
||||
{
|
||||
other.array = 0;
|
||||
other.ptr = 0;
|
||||
}
|
||||
|
||||
~rvmove()
|
||||
{
|
||||
assert(((ptr != 0) && (array != 0)) || ((ptr == 0) && (array == 0)));
|
||||
delete[] array;
|
||||
}
|
||||
|
||||
rvmove &operator=(rvmove &&other)
|
||||
{
|
||||
delete[] array;
|
||||
ptr = other.ptr;
|
||||
array = other.array;
|
||||
other.array = 0;
|
||||
other.ptr = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
static rvmove create()
|
||||
{
|
||||
return rvmove();
|
||||
}
|
||||
private:
|
||||
rvmove(const rvmove &);
|
||||
rvmove &operator=(const rvmove &);
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
rvmove mine;
|
||||
if (mine.ptr != &mine)
|
||||
return 1;
|
||||
mine = rvmove::create();
|
||||
if (mine.ptr == &mine)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#include <memory>
|
||||
|
||||
int main() {
|
||||
std::shared_ptr<int> test;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
struct foo {
|
||||
char bar;
|
||||
int baz;
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
bool ret = (
|
||||
(sizeof(foo::bar) == 1) &&
|
||||
(sizeof(foo::baz) >= sizeof(foo::bar)) &&
|
||||
(sizeof(foo) >= sizeof(foo::bar) + sizeof(foo::baz))
|
||||
);
|
||||
return ret ? 0 : 1;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
struct foo {
|
||||
int baz;
|
||||
double bar;
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return (sizeof(foo::bar) == 4) ? 0 : 1;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
int main(void)
|
||||
{
|
||||
static_assert(0 < 1, "your ordering of integers is screwed");
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
int main(void)
|
||||
{
|
||||
static_assert(1 < 0, "your ordering of integers is screwed");
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#include <thread>
|
||||
|
||||
int main() {
|
||||
std::thread test;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
#include <tuple>
|
||||
|
||||
int main () {
|
||||
typedef std::tuple <int, double, long &, const char *> test_tuple;
|
||||
long lengthy = 12;
|
||||
test_tuple proof (18, 6.5, lengthy, "Ciao!");
|
||||
lengthy = std::get<0>(proof);
|
||||
std::get<3>(proof) = " Beautiful!";
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#include <memory>
|
||||
|
||||
int main() {
|
||||
std::unique_ptr<int> test;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
int Accumulate()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename T, typename... Ts>
|
||||
int Accumulate(T v, Ts... vs)
|
||||
{
|
||||
return v + Accumulate(vs...);
|
||||
}
|
||||
|
||||
template<int... Is>
|
||||
int CountElements()
|
||||
{
|
||||
return sizeof...(Is);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int acc = Accumulate(1, 2, 3, 4, -5);
|
||||
int count = CountElements<1,2,3,4,5>();
|
||||
return ((acc == 5) && (count == 5)) ? 0 : 1;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#include <memory>
|
||||
|
||||
int main() {
|
||||
std::weak_ptr<int> test;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
#.rst:
|
||||
# CheckCXXCompilerFlag
|
||||
# --------------------
|
||||
#
|
||||
# Check whether the CXX compiler supports a given flag.
|
||||
#
|
||||
# CHECK_CXX_COMPILER_FLAG(<flag> <var>)
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# <flag> - the compiler flag
|
||||
# <var> - variable to store the result
|
||||
#
|
||||
# This internally calls the check_cxx_source_compiles macro and sets
|
||||
# CMAKE_REQUIRED_DEFINITIONS to <flag>. See help for
|
||||
# CheckCXXSourceCompiles for a listing of variables that can otherwise
|
||||
# modify the build. The result only tells that the compiler does not
|
||||
# give an error message when it encounters the flag. If the flag has
|
||||
# any effect or even a specific one is beyond the scope of this module.
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2006-2010 Kitware, Inc.
|
||||
# Copyright 2006 Alexander Neundorf <neundorf@kde.org>
|
||||
# Copyright 2011 Matthias Kretz <kretz@kde.org>
|
||||
#
|
||||
# Distributed under the OSI-approved BSD License (the "License");
|
||||
# see accompanying file Copyright.txt for details.
|
||||
#
|
||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the License for more information.
|
||||
#=============================================================================
|
||||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
include(CheckCXXSourceCompiles)
|
||||
include(CMakeCheckCompilerFlagCommonPatterns)
|
||||
|
||||
macro (CHECK_CXX_COMPILER_FLAG _FLAG _RESULT)
|
||||
set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
|
||||
set(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
|
||||
|
||||
# Normalize locale during test compilation.
|
||||
set(_CheckCXXCompilerFlag_LOCALE_VARS LC_ALL LC_MESSAGES LANG)
|
||||
foreach(v ${_CheckCXXCompilerFlag_LOCALE_VARS})
|
||||
set(_CheckCXXCompilerFlag_SAVED_${v} "$ENV{${v}}")
|
||||
set(ENV{${v}} C)
|
||||
endforeach()
|
||||
CHECK_COMPILER_FLAG_COMMON_PATTERNS(_CheckCXXCompilerFlag_COMMON_PATTERNS)
|
||||
CHECK_CXX_SOURCE_COMPILES("int main() { return 0; }" ${_RESULT}
|
||||
# Some compilers do not fail with a bad flag
|
||||
FAIL_REGEX "command line option .* is valid for .* but not for C\\\\+\\\\+" # GNU
|
||||
${_CheckCXXCompilerFlag_COMMON_PATTERNS}
|
||||
)
|
||||
foreach(v ${_CheckCXXCompilerFlag_LOCALE_VARS})
|
||||
set(ENV{${v}} ${_CheckCXXCompilerFlag_SAVED_${v}})
|
||||
unset(_CheckCXXCompilerFlag_SAVED_${v})
|
||||
endforeach()
|
||||
unset(_CheckCXXCompilerFlag_LOCALE_VARS)
|
||||
unset(_CheckCXXCompilerFlag_COMMON_PATTERNS)
|
||||
|
||||
set (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
|
||||
endmacro ()
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
#.rst:
|
||||
# CheckCXXSourceCompiles
|
||||
# ----------------------
|
||||
#
|
||||
# Check if given C++ source compiles and links into an executable
|
||||
#
|
||||
# CHECK_CXX_SOURCE_COMPILES(<code> <var> [FAIL_REGEX <fail-regex>])
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# <code> - source code to try to compile, must define 'main'
|
||||
# <var> - variable to store whether the source code compiled
|
||||
# Will be created as an internal cache variable.
|
||||
# <fail-regex> - fail if test output matches this regex
|
||||
#
|
||||
# The following variables may be set before calling this macro to modify
|
||||
# the way the check is run:
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
|
||||
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
|
||||
# CMAKE_REQUIRED_INCLUDES = list of include directories
|
||||
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
|
||||
# CMAKE_REQUIRED_QUIET = execute quietly without messages
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2005-2009 Kitware, Inc.
|
||||
#
|
||||
# Distributed under the OSI-approved BSD License (the "License");
|
||||
# see accompanying file Copyright.txt for details.
|
||||
#
|
||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the License for more information.
|
||||
#=============================================================================
|
||||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
|
||||
|
||||
macro(CHECK_CXX_SOURCE_COMPILES SOURCE VAR)
|
||||
if(NOT DEFINED "${VAR}")
|
||||
set(_FAIL_REGEX)
|
||||
set(_key)
|
||||
foreach(arg ${ARGN})
|
||||
if("${arg}" MATCHES "^(FAIL_REGEX)$")
|
||||
set(_key "${arg}")
|
||||
elseif(_key)
|
||||
list(APPEND _${_key} "${arg}")
|
||||
else()
|
||||
message(FATAL_ERROR "Unknown argument:\n ${arg}\n")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(MACRO_CHECK_FUNCTION_DEFINITIONS
|
||||
"-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
|
||||
if(CMAKE_REQUIRED_LIBRARIES)
|
||||
set(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES
|
||||
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
|
||||
else()
|
||||
set(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES)
|
||||
endif()
|
||||
if(CMAKE_REQUIRED_INCLUDES)
|
||||
set(CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES
|
||||
"-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
|
||||
else()
|
||||
set(CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES)
|
||||
endif()
|
||||
file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx"
|
||||
"${SOURCE}\n")
|
||||
|
||||
if(NOT CMAKE_REQUIRED_QUIET)
|
||||
message(STATUS "Performing Test ${VAR}")
|
||||
endif()
|
||||
try_compile(${VAR}
|
||||
${CMAKE_BINARY_DIR}
|
||||
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx
|
||||
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
|
||||
${CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES}
|
||||
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
|
||||
"${CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES}"
|
||||
OUTPUT_VARIABLE OUTPUT)
|
||||
|
||||
foreach(_regex ${_FAIL_REGEX})
|
||||
if("${OUTPUT}" MATCHES "${_regex}")
|
||||
set(${VAR} 0)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(${VAR})
|
||||
set(${VAR} 1 CACHE INTERNAL "Test ${VAR}")
|
||||
if(NOT CMAKE_REQUIRED_QUIET)
|
||||
message(STATUS "Performing Test ${VAR} - Success")
|
||||
endif()
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
||||
"Performing C++ SOURCE FILE Test ${VAR} succeded with the following output:\n"
|
||||
"${OUTPUT}\n"
|
||||
"Source file was:\n${SOURCE}\n")
|
||||
else()
|
||||
if(NOT CMAKE_REQUIRED_QUIET)
|
||||
message(STATUS "Performing Test ${VAR} - Failed")
|
||||
endif()
|
||||
set(${VAR} "" CACHE INTERNAL "Test ${VAR}")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||
"Performing C++ SOURCE FILE Test ${VAR} failed with the following output:\n"
|
||||
"${OUTPUT}\n"
|
||||
"Source file was:\n${SOURCE}\n")
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
#.rst:
|
||||
# CheckCXXSymbolExists
|
||||
# --------------------
|
||||
#
|
||||
# Check if a symbol exists as a function, variable, or macro in C++
|
||||
#
|
||||
# CHECK_CXX_SYMBOL_EXISTS(<symbol> <files> <variable>)
|
||||
#
|
||||
# Check that the <symbol> is available after including given header
|
||||
# <files> and store the result in a <variable>. Specify the list of
|
||||
# files in one argument as a semicolon-separated list.
|
||||
# CHECK_CXX_SYMBOL_EXISTS() can be used to check in C++ files, as
|
||||
# opposed to CHECK_SYMBOL_EXISTS(), which works only for C.
|
||||
#
|
||||
# If the header files define the symbol as a macro it is considered
|
||||
# available and assumed to work. If the header files declare the symbol
|
||||
# as a function or variable then the symbol must also be available for
|
||||
# linking. If the symbol is a type or enum value it will not be
|
||||
# recognized (consider using CheckTypeSize or CheckCSourceCompiles).
|
||||
#
|
||||
# The following variables may be set before calling this macro to modify
|
||||
# the way the check is run:
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
|
||||
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
|
||||
# CMAKE_REQUIRED_INCLUDES = list of include directories
|
||||
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
|
||||
# CMAKE_REQUIRED_QUIET = execute quietly without messages
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2003-2011 Kitware, Inc.
|
||||
#
|
||||
# Distributed under the OSI-approved BSD License (the "License");
|
||||
# see accompanying file Copyright.txt for details.
|
||||
#
|
||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the License for more information.
|
||||
#=============================================================================
|
||||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
include(CheckSymbolExists)
|
||||
|
||||
macro(CHECK_CXX_SYMBOL_EXISTS SYMBOL FILES VARIABLE)
|
||||
_CHECK_SYMBOL_EXISTS("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.cxx" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
|
||||
endmacro()
|
|
@ -0,0 +1,101 @@
|
|||
# - Check whether the MIC C compiler supports a given flag.
|
||||
# CHECK_MIC_C_COMPILER_FLAG(<flag> <var>)
|
||||
# <flag> - the compiler flag
|
||||
# <var> - variable to store the result
|
||||
# This internally calls the check_c_source_compiles macro. See help
|
||||
# for CheckCSourceCompiles for a listing of variables that can
|
||||
# modify the build.
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2006-2009 Kitware, Inc.
|
||||
# Copyright 2006 Alexander Neundorf <neundorf@kde.org>
|
||||
# Copyright 2011-2013 Matthias Kretz <kretz@kde.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# * The names of Kitware, Inc., the Insight Consortium, or the names of
|
||||
# any consortium members, or of any contributors, may not be used to
|
||||
# endorse or promote products derived from this software without
|
||||
# specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
|
||||
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#=============================================================================
|
||||
|
||||
macro(check_mic_c_compiler_flag _FLAG _RESULT)
|
||||
if("${_RESULT}" MATCHES "^${_RESULT}$")
|
||||
set(_tmpdir "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp")
|
||||
if(${ARGC} GREATER 2)
|
||||
file(WRITE "${_tmpdir}/src.c" "${ARGV2}")
|
||||
else()
|
||||
file(WRITE "${_tmpdir}/src.c" "int main() { return 0; }")
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND "${MIC_CC}" -mmic -c -o "${_tmpdir}/src.o"
|
||||
"${_FLAG}" "${_tmpdir}/src.c"
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
RESULT_VARIABLE ${_RESULT}
|
||||
OUTPUT_VARIABLE OUTPUT
|
||||
ERROR_VARIABLE OUTPUT
|
||||
)
|
||||
|
||||
if(${_RESULT})
|
||||
foreach(_fail_regex
|
||||
"error: bad value (.*) for .* switch" # GNU
|
||||
"argument unused during compilation" # clang
|
||||
"is valid for .* but not for C" # GNU
|
||||
"unrecognized .*option" # GNU
|
||||
"ignored for target" # GNU
|
||||
"ignoring unknown option" # MSVC
|
||||
"[Uu]nknown option" # HP
|
||||
"[Ww]arning: [Oo]ption" # SunPro
|
||||
"command option .* is not recognized" # XL
|
||||
"WARNING: unknown flag:" # Open64
|
||||
"command line error" # ICC
|
||||
"command line warning" # ICC
|
||||
"#10236:" # ICC: File not found
|
||||
)
|
||||
if("${OUTPUT}" MATCHES "${_fail_regex}")
|
||||
set(${_RESULT} FALSE)
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if(${_RESULT})
|
||||
set(${_RESULT} 1 CACHE INTERNAL "Test ${_FLAG}")
|
||||
message(STATUS "Performing Test Check MIC C Compiler flag ${_FLAG} - Success")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
||||
"Performing MIC C Compiler Flag Test ${_FLAG} succeded with the following output:\n"
|
||||
"${OUTPUT}\n"
|
||||
"COMMAND: ${MIC_CC} -mmic -c -o ${_tmpdir}/src.o ${_FLAG} ${_tmpdir}/src.cpp\n"
|
||||
)
|
||||
else()
|
||||
message(STATUS "Performing Test Check MIC C Compiler flag ${_FLAG} - Failed")
|
||||
set(${_RESULT} "" CACHE INTERNAL "Test ${_FLAG}")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||
"Performing MIC C Compiler Flag Test ${_FLAG} failed with the following output:\n"
|
||||
"${OUTPUT}\n"
|
||||
"COMMAND: ${MIC_CC} -mmic -c -o ${_tmpdir}/src.o ${_FLAG} ${_tmpdir}/src.cpp\n"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
# - Check whether the MIC CXX compiler supports a given flag.
|
||||
# CHECK_MIC_CXX_COMPILER_FLAG(<flag> <var>)
|
||||
# <flag> - the compiler flag
|
||||
# <var> - variable to store the result
|
||||
# This internally calls the check_cxx_source_compiles macro. See help
|
||||
# for CheckCXXSourceCompiles for a listing of variables that can
|
||||
# modify the build.
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2006-2009 Kitware, Inc.
|
||||
# Copyright 2006 Alexander Neundorf <neundorf@kde.org>
|
||||
# Copyright 2011-2013 Matthias Kretz <kretz@kde.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# * The names of Kitware, Inc., the Insight Consortium, or the names of
|
||||
# any consortium members, or of any contributors, may not be used to
|
||||
# endorse or promote products derived from this software without
|
||||
# specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
|
||||
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#=============================================================================
|
||||
|
||||
macro(check_mic_cxx_compiler_flag _FLAG _RESULT)
|
||||
if("${_RESULT}" MATCHES "^${_RESULT}$")
|
||||
set(_tmpdir "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp")
|
||||
if(${ARGC} GREATER 2)
|
||||
file(WRITE "${_tmpdir}/src.cpp" "${ARGV2}")
|
||||
else()
|
||||
file(WRITE "${_tmpdir}/src.cpp" "int main() { return 0; }")
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND "${MIC_CXX}" -mmic -c -o "${_tmpdir}/src.o"
|
||||
"${_FLAG}" "${_tmpdir}/src.cpp"
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
RESULT_VARIABLE ${_RESULT}
|
||||
OUTPUT_VARIABLE OUTPUT
|
||||
ERROR_VARIABLE OUTPUT
|
||||
)
|
||||
|
||||
if(${_RESULT} EQUAL 0)
|
||||
foreach(_fail_regex
|
||||
"error: bad value (.*) for .* switch" # GNU
|
||||
"argument unused during compilation" # clang
|
||||
"is valid for .* but not for C\\\\+\\\\+" # GNU
|
||||
"unrecognized .*option" # GNU
|
||||
"ignored for target" # GNU
|
||||
"ignoring unknown option" # MSVC
|
||||
"[Uu]nknown option" # HP
|
||||
"[Ww]arning: [Oo]ption" # SunPro
|
||||
"command option .* is not recognized" # XL
|
||||
"WARNING: unknown flag:" # Open64
|
||||
"command line error" # ICC
|
||||
"command line warning" # ICC
|
||||
"#10236:" # ICC: File not found
|
||||
)
|
||||
if("${OUTPUT}" MATCHES "${_fail_regex}")
|
||||
set(${_RESULT} FALSE)
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if(${_RESULT} EQUAL 0)
|
||||
set(${_RESULT} 1 CACHE INTERNAL "Test ${_FLAG}")
|
||||
message(STATUS "Performing Test Check MIC C++ Compiler flag ${_FLAG} - Success")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
||||
"Performing MIC C++ Compiler Flag Test ${_FLAG} succeded with the following output:\n"
|
||||
"${OUTPUT}\n"
|
||||
"COMMAND: ${MIC_CXX} -mmic -c -o ${_tmpdir}/src.o ${_FLAG} ${_tmpdir}/src.cpp\n"
|
||||
)
|
||||
else()
|
||||
message(STATUS "Performing Test Check MIC C++ Compiler flag ${_FLAG} - Failed")
|
||||
set(${_RESULT} "" CACHE INTERNAL "Test ${_FLAG}")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||
"Performing MIC C++ Compiler Flag Test ${_FLAG} failed with the following output:\n"
|
||||
"${OUTPUT}\n"
|
||||
"COMMAND: ${MIC_CXX} -mmic -c -o ${_tmpdir}/src.o ${_FLAG} ${_tmpdir}/src.cpp\n"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
|
@ -0,0 +1,494 @@
|
|||
#=============================================================================
|
||||
# Copyright 2010-2013 Matthias Kretz <kretz@kde.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# * The names of Kitware, Inc., the Insight Consortium, or the names of
|
||||
# any consortium members, or of any contributors, may not be used to
|
||||
# endorse or promote products derived from this software without
|
||||
# specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
|
||||
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#=============================================================================
|
||||
|
||||
get_filename_component(_currentDir "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
include("${_currentDir}/AddCompilerFlag.cmake")
|
||||
include(CheckIncludeFile)
|
||||
|
||||
macro(_my_find _list _value _ret)
|
||||
list(FIND ${_list} "${_value}" _found)
|
||||
if(_found EQUAL -1)
|
||||
set(${_ret} FALSE)
|
||||
else(_found EQUAL -1)
|
||||
set(${_ret} TRUE)
|
||||
endif(_found EQUAL -1)
|
||||
endmacro(_my_find)
|
||||
|
||||
macro(AutodetectHostArchitecture)
|
||||
set(TARGET_ARCHITECTURE "generic")
|
||||
set(Vc_ARCHITECTURE_FLAGS)
|
||||
set(_vendor_id)
|
||||
set(_cpu_family)
|
||||
set(_cpu_model)
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
file(READ "/proc/cpuinfo" _cpuinfo)
|
||||
string(REGEX REPLACE ".*vendor_id[ \t]*:[ \t]+([a-zA-Z0-9_-]+).*" "\\1" _vendor_id "${_cpuinfo}")
|
||||
string(REGEX REPLACE ".*cpu family[ \t]*:[ \t]+([a-zA-Z0-9_-]+).*" "\\1" _cpu_family "${_cpuinfo}")
|
||||
string(REGEX REPLACE ".*model[ \t]*:[ \t]+([a-zA-Z0-9_-]+).*" "\\1" _cpu_model "${_cpuinfo}")
|
||||
string(REGEX REPLACE ".*flags[ \t]*:[ \t]+([^\n]+).*" "\\1" _cpu_flags "${_cpuinfo}")
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||
exec_program("/usr/sbin/sysctl -n machdep.cpu.vendor" OUTPUT_VARIABLE _vendor_id)
|
||||
exec_program("/usr/sbin/sysctl -n machdep.cpu.model" OUTPUT_VARIABLE _cpu_model)
|
||||
exec_program("/usr/sbin/sysctl -n machdep.cpu.family" OUTPUT_VARIABLE _cpu_family)
|
||||
exec_program("/usr/sbin/sysctl -n machdep.cpu.features" OUTPUT_VARIABLE _cpu_flags)
|
||||
string(TOLOWER "${_cpu_flags}" _cpu_flags)
|
||||
string(REPLACE "." "_" _cpu_flags "${_cpu_flags}")
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
get_filename_component(_vendor_id "[HKEY_LOCAL_MACHINE\\Hardware\\Description\\System\\CentralProcessor\\0;VendorIdentifier]" NAME CACHE)
|
||||
get_filename_component(_cpu_id "[HKEY_LOCAL_MACHINE\\Hardware\\Description\\System\\CentralProcessor\\0;Identifier]" NAME CACHE)
|
||||
mark_as_advanced(_vendor_id _cpu_id)
|
||||
string(REGEX REPLACE ".* Family ([0-9]+) .*" "\\1" _cpu_family "${_cpu_id}")
|
||||
string(REGEX REPLACE ".* Model ([0-9]+) .*" "\\1" _cpu_model "${_cpu_id}")
|
||||
endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
if(_vendor_id STREQUAL "GenuineIntel")
|
||||
if(_cpu_family EQUAL 6)
|
||||
# Any recent Intel CPU except NetBurst
|
||||
if(_cpu_model EQUAL 70)
|
||||
set(TARGET_ARCHITECTURE "haswell")
|
||||
elseif(_cpu_model EQUAL 63)
|
||||
set(TARGET_ARCHITECTURE "haswell")
|
||||
elseif(_cpu_model EQUAL 62)
|
||||
set(TARGET_ARCHITECTURE "ivy-bridge")
|
||||
elseif(_cpu_model EQUAL 60)
|
||||
set(TARGET_ARCHITECTURE "haswell")
|
||||
elseif(_cpu_model EQUAL 60)
|
||||
set(TARGET_ARCHITECTURE "haswell")
|
||||
elseif(_cpu_model EQUAL 58)
|
||||
set(TARGET_ARCHITECTURE "ivy-bridge")
|
||||
elseif(_cpu_model EQUAL 47) # Xeon E7 4860
|
||||
set(TARGET_ARCHITECTURE "westmere")
|
||||
elseif(_cpu_model EQUAL 46) # Xeon 7500 series
|
||||
set(TARGET_ARCHITECTURE "westmere")
|
||||
elseif(_cpu_model EQUAL 45) # Xeon TNG
|
||||
set(TARGET_ARCHITECTURE "sandy-bridge")
|
||||
elseif(_cpu_model EQUAL 44) # Xeon 5600 series
|
||||
set(TARGET_ARCHITECTURE "westmere")
|
||||
elseif(_cpu_model EQUAL 42) # Core TNG
|
||||
set(TARGET_ARCHITECTURE "sandy-bridge")
|
||||
elseif(_cpu_model EQUAL 37) # Core i7/i5/i3
|
||||
set(TARGET_ARCHITECTURE "westmere")
|
||||
elseif(_cpu_model EQUAL 31) # Core i7/i5
|
||||
set(TARGET_ARCHITECTURE "westmere")
|
||||
elseif(_cpu_model EQUAL 30) # Core i7/i5
|
||||
set(TARGET_ARCHITECTURE "westmere")
|
||||
elseif(_cpu_model EQUAL 29)
|
||||
set(TARGET_ARCHITECTURE "penryn")
|
||||
elseif(_cpu_model EQUAL 28)
|
||||
set(TARGET_ARCHITECTURE "atom")
|
||||
elseif(_cpu_model EQUAL 26)
|
||||
set(TARGET_ARCHITECTURE "nehalem")
|
||||
elseif(_cpu_model EQUAL 23)
|
||||
set(TARGET_ARCHITECTURE "penryn")
|
||||
elseif(_cpu_model EQUAL 15)
|
||||
set(TARGET_ARCHITECTURE "merom")
|
||||
elseif(_cpu_model EQUAL 14)
|
||||
set(TARGET_ARCHITECTURE "core")
|
||||
elseif(_cpu_model LESS 14)
|
||||
message(WARNING "Your CPU (family ${_cpu_family}, model ${_cpu_model}) is not known. Auto-detection of optimization flags failed and will use the generic CPU settings with SSE2.")
|
||||
set(TARGET_ARCHITECTURE "generic")
|
||||
else()
|
||||
message(WARNING "Your CPU (family ${_cpu_family}, model ${_cpu_model}) is not known. Auto-detection of optimization flags failed and will use the 65nm Core 2 CPU settings.")
|
||||
set(TARGET_ARCHITECTURE "merom")
|
||||
endif()
|
||||
elseif(_cpu_family EQUAL 7) # Itanium (not supported)
|
||||
message(WARNING "Your CPU (Itanium: family ${_cpu_family}, model ${_cpu_model}) is not supported by OptimizeForArchitecture.cmake.")
|
||||
elseif(_cpu_family EQUAL 15) # NetBurst
|
||||
list(APPEND _available_vector_units_list "sse" "sse2")
|
||||
if(_cpu_model GREATER 2) # Not sure whether this must be 3 or even 4 instead
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3")
|
||||
endif(_cpu_model GREATER 2)
|
||||
endif(_cpu_family EQUAL 6)
|
||||
elseif(_vendor_id STREQUAL "AuthenticAMD")
|
||||
if(_cpu_family EQUAL 22) # 16h
|
||||
set(TARGET_ARCHITECTURE "AMD 16h")
|
||||
elseif(_cpu_family EQUAL 21) # 15h
|
||||
if(_cpu_model LESS 2)
|
||||
set(TARGET_ARCHITECTURE "bulldozer")
|
||||
else()
|
||||
set(TARGET_ARCHITECTURE "piledriver")
|
||||
endif()
|
||||
elseif(_cpu_family EQUAL 20) # 14h
|
||||
set(TARGET_ARCHITECTURE "AMD 14h")
|
||||
elseif(_cpu_family EQUAL 18) # 12h
|
||||
elseif(_cpu_family EQUAL 16) # 10h
|
||||
set(TARGET_ARCHITECTURE "barcelona")
|
||||
elseif(_cpu_family EQUAL 15)
|
||||
set(TARGET_ARCHITECTURE "k8")
|
||||
if(_cpu_model GREATER 64) # I don't know the right number to put here. This is just a guess from the hardware I have access to
|
||||
set(TARGET_ARCHITECTURE "k8-sse3")
|
||||
endif(_cpu_model GREATER 64)
|
||||
endif()
|
||||
endif(_vendor_id STREQUAL "GenuineIntel")
|
||||
endmacro()
|
||||
|
||||
macro(OptimizeForArchitecture)
|
||||
set(TARGET_ARCHITECTURE "auto" CACHE STRING "CPU architecture to optimize for. Using an incorrect setting here can result in crashes of the resulting binary because of invalid instructions used.\nSetting the value to \"auto\" will try to optimize for the architecture where cmake is called.\nOther supported values are: \"none\", \"generic\", \"core\", \"merom\" (65nm Core2), \"penryn\" (45nm Core2), \"nehalem\", \"westmere\", \"sandy-bridge\", \"ivy-bridge\", \"haswell\", \"atom\", \"k8\", \"k8-sse3\", \"barcelona\", \"istanbul\", \"magny-cours\", \"bulldozer\", \"interlagos\", \"piledriver\", \"AMD 14h\", \"AMD 16h\".")
|
||||
set(_force)
|
||||
if(NOT _last_target_arch STREQUAL "${TARGET_ARCHITECTURE}")
|
||||
message(STATUS "target changed from \"${_last_target_arch}\" to \"${TARGET_ARCHITECTURE}\"")
|
||||
set(_force FORCE)
|
||||
endif()
|
||||
set(_last_target_arch "${TARGET_ARCHITECTURE}" CACHE STRING "" FORCE)
|
||||
mark_as_advanced(_last_target_arch)
|
||||
string(TOLOWER "${TARGET_ARCHITECTURE}" TARGET_ARCHITECTURE)
|
||||
|
||||
set(_march_flag_list)
|
||||
set(_available_vector_units_list)
|
||||
|
||||
if(TARGET_ARCHITECTURE STREQUAL "auto")
|
||||
AutodetectHostArchitecture()
|
||||
message(STATUS "Detected CPU: ${TARGET_ARCHITECTURE}")
|
||||
endif(TARGET_ARCHITECTURE STREQUAL "auto")
|
||||
|
||||
if(TARGET_ARCHITECTURE STREQUAL "core")
|
||||
list(APPEND _march_flag_list "core2")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "merom")
|
||||
list(APPEND _march_flag_list "merom")
|
||||
list(APPEND _march_flag_list "core2")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3" "ssse3")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "penryn")
|
||||
list(APPEND _march_flag_list "penryn")
|
||||
list(APPEND _march_flag_list "core2")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3" "ssse3")
|
||||
message(STATUS "Sadly the Penryn architecture exists in variants with SSE4.1 and without SSE4.1.")
|
||||
if(_cpu_flags MATCHES "sse4_1")
|
||||
message(STATUS "SSE4.1: enabled (auto-detected from this computer's CPU flags)")
|
||||
list(APPEND _available_vector_units_list "sse4.1")
|
||||
else()
|
||||
message(STATUS "SSE4.1: disabled (auto-detected from this computer's CPU flags)")
|
||||
endif()
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "nehalem")
|
||||
list(APPEND _march_flag_list "nehalem")
|
||||
list(APPEND _march_flag_list "corei7")
|
||||
list(APPEND _march_flag_list "core2")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3" "ssse3" "sse4.1" "sse4.2")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "westmere")
|
||||
list(APPEND _march_flag_list "westmere")
|
||||
list(APPEND _march_flag_list "corei7")
|
||||
list(APPEND _march_flag_list "core2")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3" "ssse3" "sse4.1" "sse4.2")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "haswell")
|
||||
list(APPEND _march_flag_list "core-avx2")
|
||||
list(APPEND _march_flag_list "core-avx-i")
|
||||
list(APPEND _march_flag_list "corei7-avx")
|
||||
list(APPEND _march_flag_list "core2")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3" "ssse3" "sse4.1" "sse4.2" "avx" "avx2" "rdrnd" "f16c" "fma")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "ivy-bridge")
|
||||
list(APPEND _march_flag_list "core-avx-i")
|
||||
list(APPEND _march_flag_list "corei7-avx")
|
||||
list(APPEND _march_flag_list "core2")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3" "ssse3" "sse4.1" "sse4.2" "avx" "rdrnd" "f16c")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "sandy-bridge")
|
||||
list(APPEND _march_flag_list "sandybridge")
|
||||
list(APPEND _march_flag_list "corei7-avx")
|
||||
list(APPEND _march_flag_list "core2")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3" "ssse3" "sse4.1" "sse4.2" "avx")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "atom")
|
||||
list(APPEND _march_flag_list "atom")
|
||||
list(APPEND _march_flag_list "core2")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3" "ssse3")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "k8")
|
||||
list(APPEND _march_flag_list "k8")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "k8-sse3")
|
||||
list(APPEND _march_flag_list "k8-sse3")
|
||||
list(APPEND _march_flag_list "k8")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "AMD 16h")
|
||||
list(APPEND _march_flag_list "btver2")
|
||||
list(APPEND _march_flag_list "btver1")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3" "ssse3" "sse4a" "sse4.1" "sse4.2" "avx" "f16c")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "AMD 14h")
|
||||
list(APPEND _march_flag_list "btver1")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3" "ssse3" "sse4a")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "piledriver")
|
||||
list(APPEND _march_flag_list "bdver2")
|
||||
list(APPEND _march_flag_list "bdver1")
|
||||
list(APPEND _march_flag_list "bulldozer")
|
||||
list(APPEND _march_flag_list "barcelona")
|
||||
list(APPEND _march_flag_list "core2")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3" "ssse3" "sse4a" "sse4.1" "sse4.2" "avx" "xop" "fma4" "fma" "f16c")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "interlagos")
|
||||
list(APPEND _march_flag_list "bdver1")
|
||||
list(APPEND _march_flag_list "bulldozer")
|
||||
list(APPEND _march_flag_list "barcelona")
|
||||
list(APPEND _march_flag_list "core2")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3" "ssse3" "sse4a" "sse4.1" "sse4.2" "avx" "xop" "fma4")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "bulldozer")
|
||||
list(APPEND _march_flag_list "bdver1")
|
||||
list(APPEND _march_flag_list "bulldozer")
|
||||
list(APPEND _march_flag_list "barcelona")
|
||||
list(APPEND _march_flag_list "core2")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3" "ssse3" "sse4a" "sse4.1" "sse4.2" "avx" "xop" "fma4")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "barcelona")
|
||||
list(APPEND _march_flag_list "barcelona")
|
||||
list(APPEND _march_flag_list "core2")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3" "sse4a")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "istanbul")
|
||||
list(APPEND _march_flag_list "barcelona")
|
||||
list(APPEND _march_flag_list "core2")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3" "sse4a")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "magny-cours")
|
||||
list(APPEND _march_flag_list "barcelona")
|
||||
list(APPEND _march_flag_list "core2")
|
||||
list(APPEND _available_vector_units_list "sse" "sse2" "sse3" "sse4a")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "generic")
|
||||
list(APPEND _march_flag_list "generic")
|
||||
elseif(TARGET_ARCHITECTURE STREQUAL "none")
|
||||
# add this clause to remove it from the else clause
|
||||
else(TARGET_ARCHITECTURE STREQUAL "core")
|
||||
message(FATAL_ERROR "Unknown target architecture: \"${TARGET_ARCHITECTURE}\". Please set TARGET_ARCHITECTURE to a supported value.")
|
||||
endif(TARGET_ARCHITECTURE STREQUAL "core")
|
||||
|
||||
if(NOT TARGET_ARCHITECTURE STREQUAL "none")
|
||||
set(_disable_vector_unit_list)
|
||||
set(_enable_vector_unit_list)
|
||||
_my_find(_available_vector_units_list "sse2" SSE2_FOUND)
|
||||
_my_find(_available_vector_units_list "sse3" SSE3_FOUND)
|
||||
_my_find(_available_vector_units_list "ssse3" SSSE3_FOUND)
|
||||
_my_find(_available_vector_units_list "sse4.1" SSE4_1_FOUND)
|
||||
_my_find(_available_vector_units_list "sse4.2" SSE4_2_FOUND)
|
||||
_my_find(_available_vector_units_list "sse4a" SSE4a_FOUND)
|
||||
if(DEFINED Vc_AVX_INTRINSICS_BROKEN AND Vc_AVX_INTRINSICS_BROKEN)
|
||||
UserWarning("AVX disabled per default because of old/broken compiler")
|
||||
set(AVX_FOUND false)
|
||||
set(XOP_FOUND false)
|
||||
set(FMA4_FOUND false)
|
||||
set(AVX2_FOUND false)
|
||||
else()
|
||||
_my_find(_available_vector_units_list "avx" AVX_FOUND)
|
||||
if(DEFINED Vc_FMA4_INTRINSICS_BROKEN AND Vc_FMA4_INTRINSICS_BROKEN)
|
||||
UserWarning("FMA4 disabled per default because of old/broken compiler")
|
||||
set(FMA4_FOUND false)
|
||||
else()
|
||||
_my_find(_available_vector_units_list "fma4" FMA4_FOUND)
|
||||
endif()
|
||||
if(DEFINED Vc_XOP_INTRINSICS_BROKEN AND Vc_XOP_INTRINSICS_BROKEN)
|
||||
UserWarning("XOP disabled per default because of old/broken compiler")
|
||||
set(XOP_FOUND false)
|
||||
else()
|
||||
_my_find(_available_vector_units_list "xop" XOP_FOUND)
|
||||
endif()
|
||||
if(DEFINED Vc_AVX2_INTRINSICS_BROKEN AND Vc_AVX2_INTRINSICS_BROKEN)
|
||||
UserWarning("AVX2 disabled per default because of old/broken compiler")
|
||||
set(AVX2_FOUND false)
|
||||
else()
|
||||
_my_find(_available_vector_units_list "avx2" AVX2_FOUND)
|
||||
endif()
|
||||
endif()
|
||||
set(USE_SSE2 ${SSE2_FOUND} CACHE BOOL "Use SSE2. If SSE2 instructions are not enabled the SSE implementation will be disabled." ${_force})
|
||||
set(USE_SSE3 ${SSE3_FOUND} CACHE BOOL "Use SSE3. If SSE3 instructions are not enabled they will be emulated." ${_force})
|
||||
set(USE_SSSE3 ${SSSE3_FOUND} CACHE BOOL "Use SSSE3. If SSSE3 instructions are not enabled they will be emulated." ${_force})
|
||||
set(USE_SSE4_1 ${SSE4_1_FOUND} CACHE BOOL "Use SSE4.1. If SSE4.1 instructions are not enabled they will be emulated." ${_force})
|
||||
set(USE_SSE4_2 ${SSE4_2_FOUND} CACHE BOOL "Use SSE4.2. If SSE4.2 instructions are not enabled they will be emulated." ${_force})
|
||||
set(USE_SSE4a ${SSE4a_FOUND} CACHE BOOL "Use SSE4a. If SSE4a instructions are not enabled they will be emulated." ${_force})
|
||||
set(USE_AVX ${AVX_FOUND} CACHE BOOL "Use AVX. This will double some of the vector sizes relative to SSE." ${_force})
|
||||
set(USE_AVX2 ${AVX2_FOUND} CACHE BOOL "Use AVX2. This will double all of the vector sizes relative to SSE." ${_force})
|
||||
set(USE_XOP ${XOP_FOUND} CACHE BOOL "Use XOP." ${_force})
|
||||
set(USE_FMA4 ${FMA4_FOUND} CACHE BOOL "Use FMA4." ${_force})
|
||||
mark_as_advanced(USE_SSE2 USE_SSE3 USE_SSSE3 USE_SSE4_1 USE_SSE4_2 USE_SSE4a USE_AVX USE_AVX2 USE_XOP USE_FMA4)
|
||||
if(USE_SSE2)
|
||||
list(APPEND _enable_vector_unit_list "sse2")
|
||||
else(USE_SSE2)
|
||||
list(APPEND _disable_vector_unit_list "sse2")
|
||||
endif(USE_SSE2)
|
||||
if(USE_SSE3)
|
||||
list(APPEND _enable_vector_unit_list "sse3")
|
||||
else(USE_SSE3)
|
||||
list(APPEND _disable_vector_unit_list "sse3")
|
||||
endif(USE_SSE3)
|
||||
if(USE_SSSE3)
|
||||
list(APPEND _enable_vector_unit_list "ssse3")
|
||||
else(USE_SSSE3)
|
||||
list(APPEND _disable_vector_unit_list "ssse3")
|
||||
endif(USE_SSSE3)
|
||||
if(USE_SSE4_1)
|
||||
list(APPEND _enable_vector_unit_list "sse4.1")
|
||||
else(USE_SSE4_1)
|
||||
list(APPEND _disable_vector_unit_list "sse4.1")
|
||||
endif(USE_SSE4_1)
|
||||
if(USE_SSE4_2)
|
||||
list(APPEND _enable_vector_unit_list "sse4.2")
|
||||
else(USE_SSE4_2)
|
||||
list(APPEND _disable_vector_unit_list "sse4.2")
|
||||
endif(USE_SSE4_2)
|
||||
if(USE_SSE4a)
|
||||
list(APPEND _enable_vector_unit_list "sse4a")
|
||||
else(USE_SSE4a)
|
||||
list(APPEND _disable_vector_unit_list "sse4a")
|
||||
endif(USE_SSE4a)
|
||||
if(USE_AVX)
|
||||
list(APPEND _enable_vector_unit_list "avx")
|
||||
# we want SSE intrinsics to result in instructions using the VEX prefix.
|
||||
# Otherwise integer ops (which require the older SSE intrinsics) would
|
||||
# always have a large penalty.
|
||||
list(APPEND _enable_vector_unit_list "sse2avx")
|
||||
else(USE_AVX)
|
||||
list(APPEND _disable_vector_unit_list "avx")
|
||||
endif(USE_AVX)
|
||||
if(USE_XOP)
|
||||
list(APPEND _enable_vector_unit_list "xop")
|
||||
else()
|
||||
list(APPEND _disable_vector_unit_list "xop")
|
||||
endif()
|
||||
if(USE_FMA4)
|
||||
list(APPEND _enable_vector_unit_list "fma4")
|
||||
else()
|
||||
list(APPEND _disable_vector_unit_list "fma4")
|
||||
endif()
|
||||
if(USE_AVX2)
|
||||
list(APPEND _enable_vector_unit_list "avx2")
|
||||
else()
|
||||
list(APPEND _disable_vector_unit_list "avx2")
|
||||
endif()
|
||||
if(MSVC)
|
||||
# MSVC on 32 bit can select /arch:SSE2 (since 2010 also /arch:AVX)
|
||||
# MSVC on 64 bit cannot select anything (should have changed with MSVC 2010)
|
||||
_my_find(_enable_vector_unit_list "avx" _avx)
|
||||
set(_avx_flag FALSE)
|
||||
if(_avx)
|
||||
AddCompilerFlag("/arch:AVX" CXX_FLAGS Vc_ARCHITECTURE_FLAGS CXX_RESULT _avx_flag)
|
||||
endif()
|
||||
if(NOT _avx_flag)
|
||||
_my_find(_enable_vector_unit_list "sse2" _found)
|
||||
if(_found)
|
||||
AddCompilerFlag("/arch:SSE2" CXX_FLAGS Vc_ARCHITECTURE_FLAGS)
|
||||
endif()
|
||||
endif()
|
||||
foreach(_flag ${_enable_vector_unit_list})
|
||||
string(TOUPPER "${_flag}" _flag)
|
||||
string(REPLACE "." "_" _flag "__${_flag}__")
|
||||
add_definitions("-D${_flag}")
|
||||
endforeach(_flag)
|
||||
elseif(CMAKE_CXX_COMPILER MATCHES "/(icpc|icc)$") # ICC (on Linux)
|
||||
_my_find(_available_vector_units_list "avx2" _found)
|
||||
if(_found)
|
||||
AddCompilerFlag("-xCORE-AVX2" CXX_FLAGS Vc_ARCHITECTURE_FLAGS)
|
||||
else(_found)
|
||||
_my_find(_available_vector_units_list "f16c" _found)
|
||||
if(_found)
|
||||
AddCompilerFlag("-march=native" CXX_FLAGS Vc_ARCHITECTURE_FLAGS)
|
||||
else(_found)
|
||||
_my_find(_available_vector_units_list "avx" _found)
|
||||
if(_found)
|
||||
AddCompilerFlag("-xAVX" CXX_FLAGS Vc_ARCHITECTURE_FLAGS)
|
||||
else(_found)
|
||||
_my_find(_available_vector_units_list "sse4.2" _found)
|
||||
if(_found)
|
||||
AddCompilerFlag("-xSSE4.2" CXX_FLAGS Vc_ARCHITECTURE_FLAGS)
|
||||
else(_found)
|
||||
_my_find(_available_vector_units_list "sse4.1" _found)
|
||||
if(_found)
|
||||
AddCompilerFlag("-xSSE4.1" CXX_FLAGS Vc_ARCHITECTURE_FLAGS)
|
||||
else(_found)
|
||||
_my_find(_available_vector_units_list "ssse3" _found)
|
||||
if(_found)
|
||||
AddCompilerFlag("-xSSSE3" CXX_FLAGS Vc_ARCHITECTURE_FLAGS)
|
||||
else(_found)
|
||||
_my_find(_available_vector_units_list "sse3" _found)
|
||||
if(_found)
|
||||
# If the target host is an AMD machine then we still want to use -xSSE2 because the binary would refuse to run at all otherwise
|
||||
_my_find(_march_flag_list "barcelona" _found)
|
||||
if(NOT _found)
|
||||
_my_find(_march_flag_list "k8-sse3" _found)
|
||||
endif(NOT _found)
|
||||
if(_found)
|
||||
AddCompilerFlag("-xSSE2" CXX_FLAGS Vc_ARCHITECTURE_FLAGS)
|
||||
else(_found)
|
||||
AddCompilerFlag("-xSSE3" CXX_FLAGS Vc_ARCHITECTURE_FLAGS)
|
||||
endif(_found)
|
||||
else(_found)
|
||||
_my_find(_available_vector_units_list "sse2" _found)
|
||||
if(_found)
|
||||
AddCompilerFlag("-xSSE2" CXX_FLAGS Vc_ARCHITECTURE_FLAGS)
|
||||
endif(_found)
|
||||
endif(_found)
|
||||
endif(_found)
|
||||
endif(_found)
|
||||
endif(_found)
|
||||
endif(_found)
|
||||
endif(_found)
|
||||
endif(_found)
|
||||
else() # not MSVC and not ICC => GCC, Clang, Open64
|
||||
foreach(_flag ${_march_flag_list})
|
||||
AddCompilerFlag("-march=${_flag}" CXX_RESULT _good CXX_FLAGS Vc_ARCHITECTURE_FLAGS)
|
||||
if(_good)
|
||||
break()
|
||||
endif(_good)
|
||||
endforeach(_flag)
|
||||
foreach(_flag ${_enable_vector_unit_list})
|
||||
AddCompilerFlag("-m${_flag}" CXX_RESULT _result CXX_FLAGS Vc_ARCHITECTURE_FLAGS)
|
||||
if(_result)
|
||||
set(_header FALSE)
|
||||
if(_flag STREQUAL "sse3")
|
||||
set(_header "pmmintrin.h")
|
||||
elseif(_flag STREQUAL "ssse3")
|
||||
set(_header "tmmintrin.h")
|
||||
elseif(_flag STREQUAL "sse4.1")
|
||||
set(_header "smmintrin.h")
|
||||
elseif(_flag STREQUAL "sse4.2")
|
||||
set(_header "smmintrin.h")
|
||||
elseif(_flag STREQUAL "sse4a")
|
||||
set(_header "ammintrin.h")
|
||||
elseif(_flag STREQUAL "avx")
|
||||
set(_header "immintrin.h")
|
||||
elseif(_flag STREQUAL "avx2")
|
||||
set(_header "immintrin.h")
|
||||
elseif(_flag STREQUAL "fma4")
|
||||
set(_header "x86intrin.h")
|
||||
elseif(_flag STREQUAL "xop")
|
||||
set(_header "x86intrin.h")
|
||||
endif()
|
||||
set(_resultVar "HAVE_${_header}")
|
||||
string(REPLACE "." "_" _resultVar "${_resultVar}")
|
||||
if(_header)
|
||||
CHECK_INCLUDE_FILE("${_header}" ${_resultVar} "-m${_flag}")
|
||||
if(NOT ${_resultVar})
|
||||
set(_useVar "USE_${_flag}")
|
||||
string(TOUPPER "${_useVar}" _useVar)
|
||||
string(REPLACE "." "_" _useVar "${_useVar}")
|
||||
message(STATUS "disabling ${_useVar} because ${_header} is missing")
|
||||
set(${_useVar} FALSE)
|
||||
list(APPEND _disable_vector_unit_list "${_flag}")
|
||||
endif()
|
||||
endif()
|
||||
if(NOT _header OR ${_resultVar})
|
||||
set(Vc_ARCHITECTURE_FLAGS "${Vc_ARCHITECTURE_FLAGS} -m${_flag}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach(_flag)
|
||||
foreach(_flag ${_disable_vector_unit_list})
|
||||
AddCompilerFlag("-mno-${_flag}" CXX_FLAGS Vc_ARCHITECTURE_FLAGS)
|
||||
endforeach(_flag)
|
||||
endif()
|
||||
endif()
|
||||
endmacro(OptimizeForArchitecture)
|
|
@ -0,0 +1,520 @@
|
|||
# Macros for use with the Vc library. Vc can be found at http://code.compeng.uni-frankfurt.de/projects/vc
|
||||
#
|
||||
# The following macros are provided:
|
||||
# vc_determine_compiler
|
||||
# vc_set_preferred_compiler_flags
|
||||
#
|
||||
#=============================================================================
|
||||
# Copyright 2009-2013 Matthias Kretz <kretz@kde.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# * The names of Kitware, Inc., the Insight Consortium, or the names of
|
||||
# any consortium members, or of any contributors, may not be used to
|
||||
# endorse or promote products derived from this software without
|
||||
# specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
|
||||
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#=============================================================================
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.3)
|
||||
|
||||
get_filename_component(_currentDir "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
include ("${_currentDir}/UserWarning.cmake")
|
||||
include ("${_currentDir}/AddCompilerFlag.cmake")
|
||||
include ("${_currentDir}/OptimizeForArchitecture.cmake")
|
||||
|
||||
macro(vc_determine_compiler)
|
||||
if(NOT DEFINED Vc_COMPILER_IS_INTEL)
|
||||
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version" OUTPUT_VARIABLE _cxx_compiler_version ERROR_VARIABLE _cxx_compiler_version)
|
||||
set(Vc_COMPILER_IS_INTEL false)
|
||||
set(Vc_COMPILER_IS_OPEN64 false)
|
||||
set(Vc_COMPILER_IS_CLANG false)
|
||||
set(Vc_COMPILER_IS_MSVC false)
|
||||
set(Vc_COMPILER_IS_GCC false)
|
||||
if(CMAKE_CXX_COMPILER MATCHES "/(icpc|icc)$")
|
||||
set(Vc_COMPILER_IS_INTEL true)
|
||||
exec_program(${CMAKE_C_COMPILER} ARGS -dumpversion OUTPUT_VARIABLE Vc_ICC_VERSION)
|
||||
message(STATUS "Detected Compiler: Intel ${Vc_ICC_VERSION}")
|
||||
elseif(CMAKE_CXX_COMPILER MATCHES "(opencc|openCC)$")
|
||||
set(Vc_COMPILER_IS_OPEN64 true)
|
||||
message(STATUS "Detected Compiler: Open64")
|
||||
elseif(CMAKE_CXX_COMPILER MATCHES "clang\\+\\+$" OR "${_cxx_compiler_version}" MATCHES "clang")
|
||||
set(Vc_COMPILER_IS_CLANG true)
|
||||
exec_program(${CMAKE_CXX_COMPILER} ARGS --version OUTPUT_VARIABLE Vc_CLANG_VERSION)
|
||||
string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" Vc_CLANG_VERSION "${Vc_CLANG_VERSION}")
|
||||
message(STATUS "Detected Compiler: Clang ${Vc_CLANG_VERSION}")
|
||||
elseif(MSVC)
|
||||
set(Vc_COMPILER_IS_MSVC true)
|
||||
message(STATUS "Detected Compiler: MSVC ${MSVC_VERSION}")
|
||||
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(Vc_COMPILER_IS_GCC true)
|
||||
exec_program(${CMAKE_C_COMPILER} ARGS -dumpversion OUTPUT_VARIABLE Vc_GCC_VERSION)
|
||||
message(STATUS "Detected Compiler: GCC ${Vc_GCC_VERSION}")
|
||||
|
||||
# some distributions patch their GCC to return nothing or only major and minor version on -dumpversion.
|
||||
# In that case we must extract the version number from --version.
|
||||
if(NOT Vc_GCC_VERSION OR Vc_GCC_VERSION MATCHES "^[0-9]\\.[0-9]+$")
|
||||
exec_program(${CMAKE_C_COMPILER} ARGS --version OUTPUT_VARIABLE Vc_GCC_VERSION)
|
||||
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" Vc_GCC_VERSION "${Vc_GCC_VERSION}")
|
||||
message(STATUS "GCC Version from --version: ${Vc_GCC_VERSION}")
|
||||
endif()
|
||||
|
||||
# some distributions patch their GCC to be API incompatible to what the FSF released. In
|
||||
# those cases we require a macro to identify the distribution version
|
||||
find_program(_lsb_release lsb_release)
|
||||
mark_as_advanced(_lsb_release)
|
||||
if(_lsb_release)
|
||||
execute_process(COMMAND ${_lsb_release} -is OUTPUT_VARIABLE _distributor_id OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
execute_process(COMMAND ${_lsb_release} -rs OUTPUT_VARIABLE _distributor_release OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(TOUPPER "${_distributor_id}" _distributor_id)
|
||||
if(_distributor_id STREQUAL "UBUNTU")
|
||||
execute_process(COMMAND ${CMAKE_C_COMPILER} --version OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE _gcc_version)
|
||||
string(REGEX MATCH "\\(.* ${Vc_GCC_VERSION}-([0-9]+).*\\)" _tmp "${_gcc_version}")
|
||||
if(_tmp)
|
||||
set(_patch ${CMAKE_MATCH_1})
|
||||
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)$" _tmp "${_distributor_release}")
|
||||
execute_process(COMMAND printf 0x%x%02x%02x ${CMAKE_MATCH_1} ${CMAKE_MATCH_2} ${_patch} OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE _tmp)
|
||||
set(Vc_DEFINITIONS "${Vc_DEFINITIONS} -D__GNUC_UBUNTU_VERSION__=${_tmp}")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
message(WARNING "Untested/-supported Compiler (${CMAKE_CXX_COMPILER}) for use with Vc.\nPlease fill out the missing parts in the CMake scripts and submit a patch to http://code.compeng.uni-frankfurt.de/projects/vc")
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(vc_set_gnu_buildtype_flags)
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g3" CACHE STRING "Flags used by the compiler during debug builds." FORCE)
|
||||
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING "Flags used by the compiler during release minsize builds." FORCE)
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files)." FORCE)
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBUG "-O3" CACHE STRING "Flags used by the compiler during release builds containing runtime checks." FORCE)
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBUG} -g" CACHE STRING "Flags used by the compiler during Release with Debug Info builds." FORCE)
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "Flags used by the compiler during debug builds." FORCE)
|
||||
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}" CACHE STRING "Flags used by the compiler during release minsize builds." FORCE)
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files)." FORCE)
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBUG "${CMAKE_CXX_FLAGS_RELWITHDEBUG}" CACHE STRING "Flags used by the compiler during release builds containing runtime checks." FORCE)
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}" CACHE STRING "Flags used by the compiler during Release with Debug Info builds." FORCE)
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebug")
|
||||
set(ENABLE_STRICT_ALIASING true CACHE BOOL "Enables strict aliasing rules for more aggressive optimizations")
|
||||
if(NOT ENABLE_STRICT_ALIASING)
|
||||
AddCompilerFlag(-fno-strict-aliasing)
|
||||
endif(NOT ENABLE_STRICT_ALIASING)
|
||||
endif()
|
||||
mark_as_advanced(CMAKE_CXX_FLAGS_RELWITHDEBUG CMAKE_C_FLAGS_RELWITHDEBUG)
|
||||
endmacro()
|
||||
|
||||
macro(vc_add_compiler_flag VAR _flag)
|
||||
AddCompilerFlag("${_flag}" CXX_FLAGS ${VAR})
|
||||
endmacro()
|
||||
|
||||
macro(vc_check_assembler)
|
||||
if(APPLE)
|
||||
if(NOT Vc_COMPILER_IS_CLANG)
|
||||
message(WARNING "Apple does not provide an assembler with AVX support. AVX will not be available. Please use Clang if you want to use AVX.")
|
||||
set(Vc_DEFINITIONS "${Vc_DEFINITIONS} -DVC_NO_XGETBV")
|
||||
set(Vc_AVX_INTRINSICS_BROKEN true)
|
||||
set(Vc_AVX2_INTRINSICS_BROKEN true)
|
||||
endif()
|
||||
else(APPLE)
|
||||
if(${ARGC} EQUAL 1)
|
||||
set(_as "${ARGV1}")
|
||||
else()
|
||||
exec_program(${CMAKE_CXX_COMPILER} ARGS -print-prog-name=as OUTPUT_VARIABLE _as)
|
||||
mark_as_advanced(_as)
|
||||
endif()
|
||||
if(NOT _as)
|
||||
message(WARNING "Could not find 'as', the assembler used by GCC. Hoping everything will work out...")
|
||||
else()
|
||||
exec_program(${_as} ARGS --version OUTPUT_VARIABLE _as_version)
|
||||
string(REGEX REPLACE "\\([^\\)]*\\)" "" _as_version "${_as_version}")
|
||||
string(REGEX MATCH "[1-9]\\.[0-9]+(\\.[0-9]+)?" _as_version "${_as_version}")
|
||||
if(_as_version VERSION_LESS "2.18.93")
|
||||
UserWarning("Your binutils is too old (${_as_version}). Some optimizations of Vc will be disabled.")
|
||||
add_definitions(-DVC_NO_XGETBV) # old assembler doesn't know the xgetbv instruction
|
||||
set(Vc_AVX_INTRINSICS_BROKEN true)
|
||||
set(Vc_XOP_INTRINSICS_BROKEN true)
|
||||
set(Vc_FMA4_INTRINSICS_BROKEN true)
|
||||
elseif(_as_version VERSION_LESS "2.21.0")
|
||||
UserWarning("Your binutils is too old (${_as_version}) for XOP instructions. They will therefore not be provided in libVc.")
|
||||
set(Vc_XOP_INTRINSICS_BROKEN true)
|
||||
endif()
|
||||
endif()
|
||||
endif(APPLE)
|
||||
endmacro()
|
||||
|
||||
macro(vc_check_fpmath)
|
||||
# if compiling for 32 bit x86 we need to use the -mfpmath=sse since the x87 is broken by design
|
||||
include (CheckCXXSourceRuns)
|
||||
check_cxx_source_runs("int main() { return sizeof(void*) != 8; }" Vc_VOID_PTR_IS_64BIT)
|
||||
if(NOT Vc_VOID_PTR_IS_64BIT)
|
||||
exec_program(${CMAKE_C_COMPILER} ARGS -dumpmachine OUTPUT_VARIABLE _gcc_machine)
|
||||
if(_gcc_machine MATCHES "[x34567]86" OR _gcc_machine STREQUAL "mingw32")
|
||||
vc_add_compiler_flag(Vc_DEFINITIONS "-mfpmath=sse")
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(vc_set_preferred_compiler_flags)
|
||||
vc_determine_compiler()
|
||||
|
||||
set(_add_warning_flags false)
|
||||
set(_add_buildtype_flags false)
|
||||
foreach(_arg ${ARGN})
|
||||
if(_arg STREQUAL "WARNING_FLAGS")
|
||||
set(_add_warning_flags true)
|
||||
elseif(_arg STREQUAL "BUILDTYPE_FLAGS")
|
||||
set(_add_buildtype_flags true)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(Vc_SSE_INTRINSICS_BROKEN false)
|
||||
set(Vc_AVX_INTRINSICS_BROKEN false)
|
||||
set(Vc_AVX2_INTRINSICS_BROKEN false)
|
||||
set(Vc_XOP_INTRINSICS_BROKEN false)
|
||||
set(Vc_FMA4_INTRINSICS_BROKEN false)
|
||||
|
||||
if(Vc_COMPILER_IS_OPEN64)
|
||||
##################################################################################################
|
||||
# Open64 #
|
||||
##################################################################################################
|
||||
if(_add_warning_flags)
|
||||
AddCompilerFlag("-W")
|
||||
AddCompilerFlag("-Wall")
|
||||
AddCompilerFlag("-Wimplicit")
|
||||
AddCompilerFlag("-Wswitch")
|
||||
AddCompilerFlag("-Wformat")
|
||||
AddCompilerFlag("-Wchar-subscripts")
|
||||
AddCompilerFlag("-Wparentheses")
|
||||
AddCompilerFlag("-Wmultichar")
|
||||
AddCompilerFlag("-Wtrigraphs")
|
||||
AddCompilerFlag("-Wpointer-arith")
|
||||
AddCompilerFlag("-Wcast-align")
|
||||
AddCompilerFlag("-Wreturn-type")
|
||||
AddCompilerFlag("-Wno-unused-function")
|
||||
AddCompilerFlag("-pedantic")
|
||||
AddCompilerFlag("-Wno-long-long")
|
||||
AddCompilerFlag("-Wshadow")
|
||||
AddCompilerFlag("-Wold-style-cast")
|
||||
AddCompilerFlag("-Wno-variadic-macros")
|
||||
endif()
|
||||
if(_add_buildtype_flags)
|
||||
vc_set_gnu_buildtype_flags()
|
||||
endif()
|
||||
|
||||
vc_check_assembler()
|
||||
|
||||
# Open64 4.5.1 still doesn't ship immintrin.h
|
||||
set(Vc_AVX_INTRINSICS_BROKEN true)
|
||||
set(Vc_AVX2_INTRINSICS_BROKEN true)
|
||||
elseif(Vc_COMPILER_IS_GCC)
|
||||
##################################################################################################
|
||||
# GCC #
|
||||
##################################################################################################
|
||||
if(_add_warning_flags)
|
||||
foreach(_f -W -Wall -Wswitch -Wformat -Wchar-subscripts -Wparentheses -Wmultichar -Wtrigraphs -Wpointer-arith -Wcast-align -Wreturn-type -Wno-unused-function -pedantic -Wshadow -Wundef -Wold-style-cast -Wno-variadic-macros)
|
||||
AddCompilerFlag("${_f}")
|
||||
endforeach()
|
||||
if(Vc_GCC_VERSION VERSION_GREATER "4.5.2" AND Vc_GCC_VERSION VERSION_LESS "4.6.4")
|
||||
# GCC gives bogus "array subscript is above array bounds" warnings in math.cpp
|
||||
AddCompilerFlag("-Wno-array-bounds")
|
||||
endif()
|
||||
if(Vc_GCC_VERSION VERSION_GREATER "4.7.99")
|
||||
# GCC 4.8 warns about stuff we don't care about
|
||||
# Some older GCC versions have problems to note that they don't support the flag
|
||||
AddCompilerFlag("-Wno-unused-local-typedefs")
|
||||
endif()
|
||||
endif()
|
||||
vc_add_compiler_flag(Vc_DEFINITIONS "-Wabi")
|
||||
vc_add_compiler_flag(Vc_DEFINITIONS "-fabi-version=0") # ABI version 4 is required to make __m128 and __m256 appear as different types. 0 should give us the latest version.
|
||||
|
||||
if(_add_buildtype_flags)
|
||||
vc_set_gnu_buildtype_flags()
|
||||
endif()
|
||||
|
||||
# GCC 4.5.[01] fail at inlining some functions, creating functions with a single instructions,
|
||||
# thus creating a large overhead.
|
||||
if(Vc_GCC_VERSION VERSION_LESS "4.5.2" AND NOT Vc_GCC_VERSION VERSION_LESS "4.5.0")
|
||||
UserWarning("GCC 4.5.0 and 4.5.1 have problems with inlining correctly. Setting early-inlining-insns=12 as workaround.")
|
||||
AddCompilerFlag("--param early-inlining-insns=12")
|
||||
endif()
|
||||
|
||||
if(Vc_GCC_VERSION VERSION_LESS "4.1.99")
|
||||
UserWarning("Your GCC is ancient and crashes on some important optimizations. The full set of SSE2 intrinsics is not supported. Vc will fall back to the scalar implementation. Use of the may_alias and always_inline attributes will be disabled. In turn all code using Vc must be compiled with -fno-strict-aliasing")
|
||||
vc_add_compiler_flag(Vc_DEFINITIONS "-fno-strict-aliasing")
|
||||
set(Vc_AVX_INTRINSICS_BROKEN true)
|
||||
set(Vc_AVX2_INTRINSICS_BROKEN true)
|
||||
set(Vc_SSE_INTRINSICS_BROKEN true)
|
||||
elseif(Vc_GCC_VERSION VERSION_LESS "4.4.6")
|
||||
UserWarning("Your GCC is older than 4.4.6. This is known to cause problems/bugs. Please update to the latest GCC if you can.")
|
||||
set(Vc_AVX_INTRINSICS_BROKEN true)
|
||||
set(Vc_AVX2_INTRINSICS_BROKEN true)
|
||||
if(Vc_GCC_VERSION VERSION_LESS "4.3.0")
|
||||
UserWarning("Your GCC is older than 4.3.0. It is unable to handle the full set of SSE2 intrinsics. All SSE code will be disabled. Please update to the latest GCC if you can.")
|
||||
set(Vc_SSE_INTRINSICS_BROKEN true)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(Vc_GCC_VERSION VERSION_LESS 4.5.0)
|
||||
UserWarning("GCC 4.4.x shows false positives for -Wparentheses, thus we rather disable the warning.")
|
||||
string(REPLACE " -Wparentheses " " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
||||
string(REPLACE " -Wparentheses " " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
set(Vc_DEFINITIONS "${Vc_DEFINITIONS} -Wno-parentheses")
|
||||
|
||||
UserWarning("GCC 4.4.x shows false positives for -Wstrict-aliasing, thus we rather disable the warning. Use a newer GCC for better warnings.")
|
||||
AddCompilerFlag("-Wno-strict-aliasing")
|
||||
|
||||
UserWarning("GCC 4.4.x shows false positives for -Wuninitialized, thus we rather disable the warning. Use a newer GCC for better warnings.")
|
||||
AddCompilerFlag("-Wno-uninitialized")
|
||||
elseif(Vc_GCC_VERSION VERSION_EQUAL 4.6.0)
|
||||
UserWarning("GCC 4.6.0 miscompiles AVX loads/stores, leading to spurious segfaults. Disabling AVX per default.")
|
||||
set(Vc_AVX_INTRINSICS_BROKEN true)
|
||||
set(Vc_AVX2_INTRINSICS_BROKEN true)
|
||||
elseif(Vc_GCC_VERSION VERSION_EQUAL 4.7.0)
|
||||
UserWarning("GCC 4.7.0 miscompiles at -O3, adding -fno-predictive-commoning to the compiler flags as workaround")
|
||||
set(Vc_DEFINITIONS "${Vc_DEFINITIONS} -fno-predictive-commoning")
|
||||
endif()
|
||||
|
||||
vc_check_fpmath()
|
||||
vc_check_assembler()
|
||||
elseif(Vc_COMPILER_IS_INTEL)
|
||||
##################################################################################################
|
||||
# Intel Compiler #
|
||||
##################################################################################################
|
||||
|
||||
if(_add_buildtype_flags)
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DNDEBUG -O3")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DNDEBUG -O3")
|
||||
|
||||
set(ALIAS_FLAGS "-no-ansi-alias")
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
||||
# default ICC to -no-ansi-alias because otherwise tests/utils_sse fails. So far I suspect a miscompilation...
|
||||
set(ENABLE_STRICT_ALIASING true CACHE BOOL "Enables strict aliasing rules for more aggressive optimizations")
|
||||
if(ENABLE_STRICT_ALIASING)
|
||||
set(ALIAS_FLAGS "-ansi-alias")
|
||||
endif(ENABLE_STRICT_ALIASING)
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ALIAS_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ALIAS_FLAGS}")
|
||||
endif()
|
||||
vc_add_compiler_flag(Vc_DEFINITIONS "-diag-disable 913")
|
||||
# Disable warning #13211 "Immediate parameter to intrinsic call too large". (sse/vector.tcc rotated(int))
|
||||
vc_add_compiler_flag(Vc_DEFINITIONS "-diag-disable 13211")
|
||||
|
||||
if(NOT "$ENV{DASHBOARD_TEST_FROM_CTEST}" STREQUAL "")
|
||||
# disable warning #2928: the __GXX_EXPERIMENTAL_CXX0X__ macro is disabled when using GNU version 4.6 with the c++0x option
|
||||
# this warning just adds noise about problems in the compiler - but I'm only interested in seeing problems in Vc
|
||||
vc_add_compiler_flag(Vc_DEFINITIONS "-diag-disable 2928")
|
||||
endif()
|
||||
|
||||
# Intel doesn't implement the XOP or FMA4 intrinsics
|
||||
set(Vc_XOP_INTRINSICS_BROKEN true)
|
||||
set(Vc_FMA4_INTRINSICS_BROKEN true)
|
||||
elseif(Vc_COMPILER_IS_MSVC)
|
||||
##################################################################################################
|
||||
# Microsoft Visual Studio #
|
||||
##################################################################################################
|
||||
|
||||
if(_add_warning_flags)
|
||||
AddCompilerFlag("/wd4800") # Disable warning "forcing value to bool"
|
||||
AddCompilerFlag("/wd4996") # Disable warning about strdup vs. _strdup
|
||||
AddCompilerFlag("/wd4244") # Disable warning "conversion from 'unsigned int' to 'float', possible loss of data"
|
||||
AddCompilerFlag("/wd4146") # Disable warning "unary minus operator applied to unsigned type, result still unsigned"
|
||||
AddCompilerFlag("/wd4227") # Disable warning "anachronism used : qualifiers on reference are ignored" (this is about 'restrict' usage on references, stupid MSVC)
|
||||
AddCompilerFlag("/wd4722") # Disable warning "destructor never returns, potential memory leak" (warns about ~_UnitTest_Global_Object which we don't care about)
|
||||
AddCompilerFlag("/wd4748") # Disable warning "/GS can not protect parameters and local variables from local buffer overrun because optimizations are disabled in function" (I don't get it)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
# MSVC does not support inline assembly on 64 bit! :(
|
||||
# searching the help for xgetbv doesn't turn up anything. So just fall back to not supporting AVX on Windows :(
|
||||
# TODO: apparently MSVC 2010 SP1 added _xgetbv
|
||||
set(Vc_DEFINITIONS "${Vc_DEFINITIONS} -DVC_NO_XGETBV")
|
||||
|
||||
# get rid of the min/max macros
|
||||
set(Vc_DEFINITIONS "${Vc_DEFINITIONS} -DNOMINMAX")
|
||||
|
||||
# MSVC doesn't implement the XOP or FMA4 intrinsics
|
||||
set(Vc_XOP_INTRINSICS_BROKEN true)
|
||||
set(Vc_FMA4_INTRINSICS_BROKEN true)
|
||||
|
||||
if(MSVC_VERSION LESS 1700)
|
||||
UserWarning("MSVC before 2012 has a broken std::vector::resize implementation. STL + Vc code will probably not compile.")
|
||||
endif()
|
||||
elseif(Vc_COMPILER_IS_CLANG)
|
||||
##################################################################################################
|
||||
# Clang #
|
||||
##################################################################################################
|
||||
|
||||
# for now I don't know of any arguments I want to pass. -march and stuff is tried by OptimizeForArchitecture...
|
||||
if(Vc_CLANG_VERSION VERSION_EQUAL "3.0")
|
||||
UserWarning("Clang 3.0 has serious issues to compile Vc code and will most likely crash when trying to do so.\nPlease update to a recent clang version.")
|
||||
elseif(Vc_CLANG_VERSION VERSION_LESS "3.3")
|
||||
# the LLVM assembler gets FMAs wrong (bug 15040)
|
||||
vc_add_compiler_flag(Vc_DEFINITIONS "-no-integrated-as")
|
||||
else()
|
||||
vc_add_compiler_flag(Vc_DEFINITIONS "-integrated-as")
|
||||
endif()
|
||||
|
||||
# disable these warnings because clang shows them for function overloads that were discarded via SFINAE
|
||||
vc_add_compiler_flag(Vc_DEFINITIONS "-Wno-local-type-template-args")
|
||||
vc_add_compiler_flag(Vc_DEFINITIONS "-Wno-unnamed-type-template-args")
|
||||
|
||||
if(XCODE)
|
||||
# set_target_properties(${_target} PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
|
||||
else()
|
||||
AddCompilerFlag(-stdlib=libc++)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT Vc_COMPILER_IS_MSVC)
|
||||
vc_add_compiler_flag(Vc_DEFINITIONS "-ffp-contract=fast")
|
||||
endif()
|
||||
|
||||
OptimizeForArchitecture()
|
||||
set(Vc_DEFINITIONS "${Vc_ARCHITECTURE_FLAGS} ${Vc_DEFINITIONS}")
|
||||
|
||||
set(VC_IMPL "auto" CACHE STRING "Force the Vc implementation globally to the selected instruction set. \"auto\" lets Vc use the best available instructions.")
|
||||
if(NOT VC_IMPL STREQUAL "auto")
|
||||
set(Vc_DEFINITIONS "${Vc_DEFINITIONS} -DVC_IMPL=${VC_IMPL}")
|
||||
if(NOT VC_IMPL STREQUAL "Scalar")
|
||||
set(_use_var "USE_${VC_IMPL}")
|
||||
if(VC_IMPL STREQUAL "SSE")
|
||||
set(_use_var "USE_SSE2")
|
||||
endif()
|
||||
if(NOT ${_use_var})
|
||||
message(WARNING "The selected value for VC_IMPL (${VC_IMPL}) will not work because the relevant instructions are not enabled via compiler flags.")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# helper macro for vc_compile_for_all_implementations
|
||||
macro(_vc_compile_one_implementation _srcs _impl)
|
||||
list(FIND _disabled_targets "${_impl}" _disabled_index)
|
||||
list(FIND _only_targets "${_impl}" _only_index)
|
||||
if(${_disabled_index} EQUAL -1 AND (NOT _only_targets OR ${_only_index} GREATER -1))
|
||||
set(_extra_flags)
|
||||
set(_ok FALSE)
|
||||
foreach(_flags ${ARGN})
|
||||
if(_flags STREQUAL "NO_FLAG")
|
||||
set(_ok TRUE)
|
||||
break()
|
||||
endif()
|
||||
string(REPLACE " " ";" _flag_list "${_flags}")
|
||||
foreach(_f ${_flag_list})
|
||||
AddCompilerFlag(${_f} CXX_RESULT _ok)
|
||||
if(NOT _ok)
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
if(_ok)
|
||||
set(_extra_flags ${_flags})
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(Vc_COMPILER_IS_MSVC)
|
||||
# MSVC for 64bit does not recognize /arch:SSE2 anymore. Therefore we set override _ok if _impl
|
||||
# says SSE
|
||||
if("${_impl}" MATCHES "SSE")
|
||||
set(_ok TRUE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(_ok)
|
||||
get_filename_component(_out "${_vc_compile_src}" NAME_WE)
|
||||
get_filename_component(_ext "${_vc_compile_src}" EXT)
|
||||
set(_out "${CMAKE_CURRENT_BINARY_DIR}/${_out}_${_impl}${_ext}")
|
||||
add_custom_command(OUTPUT "${_out}"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${_vc_compile_src}" "${_out}"
|
||||
MAIN_DEPENDENCY "${_vc_compile_src}"
|
||||
COMMENT "Copy to ${_out}"
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
VERBATIM)
|
||||
set_source_files_properties( "${_out}" PROPERTIES
|
||||
COMPILE_DEFINITIONS "VC_IMPL=${_impl}"
|
||||
COMPILE_FLAGS "${_flags} ${_extra_flags}"
|
||||
)
|
||||
list(APPEND ${_srcs} "${_out}")
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Generate compile rules for the given C++ source file for all available implementations and return
|
||||
# the resulting list of object files in _obj
|
||||
# all remaining arguments are additional flags
|
||||
# Example:
|
||||
# vc_compile_for_all_implementations(_objs src/trigonometric.cpp FLAGS -DCOMPILE_BLAH EXCLUDE Scalar)
|
||||
# add_executable(executable main.cpp ${_objs})
|
||||
macro(vc_compile_for_all_implementations _srcs _src)
|
||||
set(_flags)
|
||||
unset(_disabled_targets)
|
||||
unset(_only_targets)
|
||||
set(_state 0)
|
||||
foreach(_arg ${ARGN})
|
||||
if(_arg STREQUAL "FLAGS")
|
||||
set(_state 1)
|
||||
elseif(_arg STREQUAL "EXCLUDE")
|
||||
set(_state 2)
|
||||
elseif(_arg STREQUAL "ONLY")
|
||||
set(_state 3)
|
||||
elseif(_state EQUAL 1)
|
||||
set(_flags "${_flags} ${_arg}")
|
||||
elseif(_state EQUAL 2)
|
||||
list(APPEND _disabled_targets "${_arg}")
|
||||
elseif(_state EQUAL 3)
|
||||
list(APPEND _only_targets "${_arg}")
|
||||
else()
|
||||
message(FATAL_ERROR "incorrect argument to vc_compile_for_all_implementations")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(_vc_compile_src "${_src}")
|
||||
|
||||
_vc_compile_one_implementation(${_srcs} Scalar NO_FLAG)
|
||||
if(NOT Vc_SSE_INTRINSICS_BROKEN)
|
||||
_vc_compile_one_implementation(${_srcs} SSE2 "-xSSE2" "-msse2" "/arch:SSE2")
|
||||
_vc_compile_one_implementation(${_srcs} SSE3 "-xSSE3" "-msse3" "/arch:SSE2")
|
||||
_vc_compile_one_implementation(${_srcs} SSSE3 "-xSSSE3" "-mssse3" "/arch:SSE2")
|
||||
_vc_compile_one_implementation(${_srcs} SSE4_1 "-xSSE4.1" "-msse4.1" "/arch:SSE2")
|
||||
_vc_compile_one_implementation(${_srcs} SSE4_2 "-xSSE4.2" "-msse4.2" "/arch:SSE2")
|
||||
_vc_compile_one_implementation(${_srcs} SSE3+SSE4a "-msse4a")
|
||||
endif()
|
||||
if(NOT Vc_AVX_INTRINSICS_BROKEN)
|
||||
_vc_compile_one_implementation(${_srcs} AVX "-xAVX" "-mavx" "/arch:AVX")
|
||||
if(NOT Vc_XOP_INTRINSICS_BROKEN)
|
||||
if(NOT Vc_FMA4_INTRINSICS_BROKEN)
|
||||
_vc_compile_one_implementation(${_srcs} SSE+XOP+FMA4 "-mxop -mfma4" "" "")
|
||||
_vc_compile_one_implementation(${_srcs} AVX+XOP+FMA4 "-mavx -mxop -mfma4" "" "")
|
||||
endif()
|
||||
_vc_compile_one_implementation(${_srcs} SSE+XOP+FMA "-mxop -mfma" "" "")
|
||||
_vc_compile_one_implementation(${_srcs} AVX+XOP+FMA "-mavx -mxop -mfma" "" "")
|
||||
endif()
|
||||
_vc_compile_one_implementation(${_srcs} AVX+FMA "-mavx -mfma" "" "")
|
||||
endif()
|
||||
if(NOT Vc_AVX2_INTRINSICS_BROKEN)
|
||||
_vc_compile_one_implementation(${_srcs} AVX2 "-xCORE-AVX2" "-mavx2" "/arch:AVX2")
|
||||
endif()
|
||||
endmacro()
|
Loading…
Reference in New Issue