Commit d58645ed authored by Dmitry Kazakov's avatar Dmitry Kazakov

Merge remote-tracking branch 'origin/master' into video-export-kazakov

parents abf6ab0f fcd632f6
......@@ -35,7 +35,7 @@ Windows Only:
== Prepare your directory layout ==
1. Make a toplevel build directory, say $HOME/dev or c:\dev. We'll refer to this directory as BUILDROOT. You can use a variable for this, on WINDOWS %BUILDROOT%, on OSX and Linux $BUILDROOT.
1. Make a toplevel build directory, say $HOME/dev or c:\dev. We'll refer to this directory as BUILDROOT. You can use a variable for this, on WINDOWS %BUILDROOT%, on OSX and Linux $BUILDROOT. You will have to replace BUILDROOT with $BUILDROOT or %BUILDROOT whenever you copy and paste a command, depending on your operating system.
2. Checkout krita in BUILDROOT
cd BUILDROOT
......
SET(PREFIX_ext_vc "${EXTPREFIX}" )
ExternalProject_Add( ext_vc
DOWNLOAD_DIR ${EXTERNALS_DOWNLOAD_DIR}
URL http://files.kde.org/krita/build/dependencies/Vc-0.7.5.tar.gz
URL_MD5 59854e2381b78d602b4a00e459e3d333
URL http://files.kde.org/krita/build/dependencies/Vc-1.2.0.tar.gz
URL_MD5 f2a213ae4bad0dcf4ec6469e4dad41c1
INSTALL_DIR ${PREFIX_ext_vc}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${PREFIX_ext_vc} -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=${GLOBAL_BUILD_TYPE} ${GLOBAL_PROFILE}
......
......@@ -475,22 +475,13 @@ endif()
##
set(OLD_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} )
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules )
macro_optional_find_package(Vc 0.6.70)
# check if not too new version, Vc > 0.7.* not yet supported
# no proper way yet found how to set a max version with find_package,
# as workaround simply search the package again with an exact lower number
# TODO: improve or file feature request with cmake
if(Vc_FOUND)
if(Vc_VERSION_MAJOR GREATER 0 OR Vc_VERSION_MINOR GREATER 7)
message(STATUS "Vc ${Vc_VERSION} is too new, currently only Vc versions <= 0.7.5 can be used.")
# reset find results by looking exactly for latest valid version
find_package(Vc 0.7.5 EXACT QUIET)
endif()
set(HAVE_VC FALSE)
if( NOT MSVC)
macro_optional_find_package(Vc 1.1.0)
macro_log_feature(Vc_FOUND "Vc" "Portable, zero-overhead SIMD library for C++" "https://github.com/VcDevel/Vc" FALSE "" "Required by the Krita for vectorization")
macro_bool_to_01(Vc_FOUND HAVE_VC)
macro_bool_to_01(PACKAGERS_BUILD DO_PACKAGERS_BUILD)
endif()
macro_log_feature(Vc_FOUND "Vc" "Portable, zero-overhead SIMD library for C++" "https://github.com/VcDevel/Vc" FALSE "" "Required by the Krita for vectorization")
macro_bool_to_01(Vc_FOUND HAVE_VC)
macro_bool_to_01(PACKAGERS_BUILD DO_PACKAGERS_BUILD)
configure_file(config-vc.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-vc.h )
if(HAVE_VC)
......@@ -507,48 +498,28 @@ if(HAVE_VC)
endif()
#Handle Vc master
if(Vc_VERSION_MAJOR GREATER 0 OR Vc_VERSION_MINOR GREATER 7)
message(STATUS "Vc version is greater than 0.7, enabling AVX2 support")
if(Vc_COMPILER_IS_GCC OR Vc_COMPILER_IS_CLANG)
AddCompilerFlag("-std=c++11" _ok)
if(NOT _ok)
AddCompilerFlag("-std=c++0x" _ok)
endif()
if(Vc_COMPILER_IS_GCC OR Vc_COMPILER_IS_CLANG)
AddCompilerFlag("-std=c++11" _ok)
if(NOT _ok)
AddCompilerFlag("-std=c++0x" _ok)
endif()
endif()
macro(ko_compile_for_all_implementations_no_scalar _objs _src)
if(PACKAGERS_BUILD)
vc_compile_for_all_implementations(${_objs} ${_src} FLAGS ${ADDITIONAL_VC_FLAGS} ONLY SSE2 SSSE3 SSE4_1 AVX AVX2)
else()
set(${_objs} ${_src})
endif()
endmacro()
macro(ko_compile_for_all_implementations _objs _src)
if(PACKAGERS_BUILD)
vc_compile_for_all_implementations(${_objs} ${_src} FLAGS ${ADDITIONAL_VC_FLAGS} ONLY Scalar SSE2 SSSE3 SSE4_1 AVX AVX2)
else()
set(${_objs} ${_src})
endif()
endmacro()
macro(ko_compile_for_all_implementations_no_scalar _objs _src)
if(PACKAGERS_BUILD)
vc_compile_for_all_implementations(${_objs} ${_src} FLAGS ${ADDITIONAL_VC_FLAGS} ONLY SSE2 SSSE3 SSE4_1 AVX AVX2+FMA+BMI2)
else()
macro(ko_compile_for_all_implementations_no_scalar _objs _src)
if(PACKAGERS_BUILD)
vc_compile_for_all_implementations(${_objs} ${_src} FLAGS ${ADDITIONAL_VC_FLAGS} ONLY SSE2 SSSE3 SSE4_1 AVX)
else()
set(${_objs} ${_src})
endif()
endmacro()
set(${_objs} ${_src})
endif()
endmacro()
macro(ko_compile_for_all_implementations _objs _src)
if(PACKAGERS_BUILD)
vc_compile_for_all_implementations(${_objs} ${_src} FLAGS ${ADDITIONAL_VC_FLAGS} ONLY Scalar SSE2 SSSE3 SSE4_1 AVX)
else()
set(${_objs} ${_src})
endif()
endmacro()
macro(ko_compile_for_all_implementations _objs _src)
if(PACKAGERS_BUILD)
vc_compile_for_all_implementations(${_objs} ${_src} FLAGS ${ADDITIONAL_VC_FLAGS} ONLY Scalar SSE2 SSSE3 SSE4_1 AVX AVX2+FMA+BMI2)
else()
set(${_objs} ${_src})
endif()
endmacro()
if (NOT PACKAGERS_BUILD)
# Optimize everything for the current architecture
......
......@@ -73,4 +73,7 @@ target_link_libraries(KisGradientBenchmark kritaimage Qt5::Test)
target_link_libraries(KisLowMemoryBenchmark kritaimage Qt5::Test)
target_link_libraries(KisFilterSelectionsBenchmark kritaimage Qt5::Test)
target_link_libraries(KisCompositionBenchmark kritaimage Qt5::Test ${LINK_VC_LIB})
if(HAVE_VC)
set_property(TARGET KisCompositionBenchmark APPEND PROPERTY COMPILE_OPTIONS "${Vc_ARCHITECTURE_FLAGS}")
endif()
target_link_libraries(KisMaskGeneratorBenchmark kritaimage Qt5::Test)
......@@ -227,7 +227,7 @@ QVector<Tile> generateTiles(int size,
QVector<Tile> tiles(size);
#ifdef HAVE_VC
const int vecSize = Vc::float_v::Size;
const int vecSize = Vc::float_v::size();
#else
const int vecSize = 1;
#endif
......@@ -472,7 +472,7 @@ void checkRounding(qreal opacity, qreal flow, qreal averageOpacity = -1, quint32
QVector<Tile> tiles =
generateTiles(2, 0, 0, ALPHA_RANDOM, ALPHA_RANDOM, pixelSize);
const int vecSize = Vc::float_v::Size;
const int vecSize = Vc::float_v::size();
const int numBlocks = numPixels / vecSize;
......@@ -499,7 +499,7 @@ void checkRounding(qreal opacity, qreal flow, qreal averageOpacity = -1, quint32
// The error count is needed as 38.5 gets rounded to 38 instead of 39 in the vc version.
int errorcount = 0;
for (int i = 0; i < numBlocks; i++) {
Compositor::template compositeVector<true,true, VC_IMPL>(src1, dst1, msk1, params.opacity, optionalParams);
Compositor::template compositeVector<true,true, Vc::CurrentImplementation::current()>(src1, dst1, msk1, params.opacity, optionalParams);
for (int j = 0; j < vecSize; j++) {
//if (8 * i + j == 7080) {
......@@ -508,7 +508,7 @@ void checkRounding(qreal opacity, qreal flow, qreal averageOpacity = -1, quint32
// dbgKrita << "msk:" << msk2[0];
//}
Compositor::template compositeOnePixelScalar<true, VC_IMPL>(src2, dst2, msk2, params.opacity, optionalParams);
Compositor::template compositeOnePixelScalar<true, Vc::CurrentImplementation::current()>(src2, dst2, msk2, params.opacity, optionalParams);
bool compareResult = true;
if (pixelSize == 4) {
......@@ -810,7 +810,7 @@ void KisCompositionBenchmark::benchmarkMemcpy()
}
#ifdef HAVE_VC
const int vecSize = Vc::float_v::Size;
const int vecSize = Vc::float_v::size();
const size_t uint8VecAlignment = qMax(vecSize * sizeof(quint8), sizeof(void*));
const size_t uint32VecAlignment = qMax(vecSize * sizeof(quint32), sizeof(void*));
const size_t floatVecAlignment = qMax(vecSize * sizeof(float), sizeof(void*));
......@@ -819,6 +819,8 @@ void KisCompositionBenchmark::benchmarkMemcpy()
void KisCompositionBenchmark::benchmarkUintFloat()
{
#ifdef HAVE_VC
using uint_v = Vc::SimdArray<unsigned int, Vc::float_v::size()>;
const int dataSize = 4096;
void *ptr = 0;
int error = MEMALIGN_ALLOC(&ptr, uint8VecAlignment, dataSize);
......@@ -833,10 +835,10 @@ void KisCompositionBenchmark::benchmarkUintFloat()
float *fData = (float*)ptr;
QBENCHMARK {
for (int i = 0; i < dataSize; i += Vc::float_v::Size) {
for (int i = 0; i < dataSize; i += Vc::float_v::size()) {
// convert uint -> float directly, this causes
// static_cast helper be called
Vc::float_v b(Vc::uint_v(iData + i));
Vc::float_v b(uint_v(iData + i));
b.store(fData + i);
}
}
......@@ -849,6 +851,9 @@ void KisCompositionBenchmark::benchmarkUintFloat()
void KisCompositionBenchmark::benchmarkUintIntFloat()
{
#ifdef HAVE_VC
using int_v = Vc::SimdArray<int, Vc::float_v::size()>;
using uint_v = Vc::SimdArray<unsigned int, Vc::float_v::size()>;
const int dataSize = 4096;
void *ptr = 0;
int error = MEMALIGN_ALLOC(&ptr, uint8VecAlignment, dataSize);
......@@ -863,10 +868,10 @@ void KisCompositionBenchmark::benchmarkUintIntFloat()
float *fData = (float*)ptr;
QBENCHMARK {
for (int i = 0; i < dataSize; i += Vc::float_v::Size) {
for (int i = 0; i < dataSize; i += Vc::float_v::size()) {
// convert uint->int->float, that avoids special sign
// treating, and gives 2.6 times speedup
Vc::float_v b(Vc::int_v(Vc::uint_v(iData + i)));
Vc::float_v b(int_v(uint_v(iData + i)));
b.store(fData + i);
}
}
......@@ -879,6 +884,8 @@ void KisCompositionBenchmark::benchmarkUintIntFloat()
void KisCompositionBenchmark::benchmarkFloatUint()
{
#ifdef HAVE_VC
using uint_v = Vc::SimdArray<unsigned int, Vc::float_v::size()>;
const int dataSize = 4096;
void *ptr = 0;
int error = MEMALIGN_ALLOC(&ptr, uint32VecAlignment, dataSize * sizeof(quint32));
......@@ -893,9 +900,9 @@ void KisCompositionBenchmark::benchmarkFloatUint()
float *fData = (float*)ptr;
QBENCHMARK {
for (int i = 0; i < dataSize; i += Vc::float_v::Size) {
for (int i = 0; i < dataSize; i += Vc::float_v::size()) {
// conversion float -> uint
Vc::uint_v b(Vc::float_v(fData + i));
uint_v b(Vc::float_v(fData + i));
b.store(iData + i);
}
......@@ -909,6 +916,9 @@ void KisCompositionBenchmark::benchmarkFloatUint()
void KisCompositionBenchmark::benchmarkFloatIntUint()
{
#ifdef HAVE_VC
using int_v = Vc::SimdArray<int, Vc::float_v::size()>;
using uint_v = Vc::SimdArray<unsigned int, Vc::float_v::size()>;
const int dataSize = 4096;
void *ptr = 0;
int error = MEMALIGN_ALLOC(&ptr, uint32VecAlignment, dataSize * sizeof(quint32));
......@@ -923,9 +933,9 @@ void KisCompositionBenchmark::benchmarkFloatIntUint()
float *fData = (float*)ptr;
QBENCHMARK {
for (int i = 0; i < dataSize; i += Vc::float_v::Size) {
for (int i = 0; i < dataSize; i += Vc::float_v::size()) {
// conversion float -> int -> uint
Vc::uint_v b(Vc::int_v(Vc::float_v(fData + i)));
uint_v b(int_v(Vc::float_v(fData + i)));
b.store(iData + i);
}
......
......@@ -52,21 +52,46 @@ void KisMaskGeneratorBenchmark::benchmarkCircle()
}
}
void KisMaskGeneratorBenchmark::benchmarkSIMD()
{
#ifdef HAVE_VC
int width = 1000;
float *buffer = Vc::malloc<float, Vc::AlignOnVector>(width);
#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
#include "kis_fixed_paint_device.h"
#include "kis_types.h"
#include "kis_brush_mask_applicator_base.h"
#include "krita_utils.h"
void benchmarkSIMD(qreal fade) {
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
KisFixedPaintDeviceSP dev = new KisFixedPaintDevice(cs);
dev->setRect(QRect(0, 0, 1000, 1000));
dev->initialize();
MaskProcessingData data(dev, cs,
0.0, 1.0,
500, 500, 0);
KisCircleMaskGenerator gen(1000, 1.0, fade, fade, 2, false);
KisBrushMaskApplicatorBase *applicator = gen.applicator();
applicator->initializeData(&data);
QVector<QRect> rects = KritaUtils::splitRectIntoPatches(dev->bounds(), QSize(63, 63));
KisCircleMaskGenerator gen(1000, 0.5, 0.5, 0.5, 2, true);
QBENCHMARK{
for(int y = 0; y < 1000; ++y)
{
// gen.processRowFast(buffer, width, y, 0.0f, 1.0f, 500.0f, 500.0f, 0.5f, 0.5f);
Q_FOREACH (const QRect &rc, rects) {
applicator->process(rc);
}
}
Vc::free(buffer);
#endif
}
void KisMaskGeneratorBenchmark::benchmarkSIMD_SharpBrush()
{
benchmarkSIMD(1.0);
}
void KisMaskGeneratorBenchmark::benchmarkSIMD_FadedBrush()
{
benchmarkSIMD(0.5);
}
void KisMaskGeneratorBenchmark::benchmarkSquare()
......
......@@ -26,9 +26,10 @@ class KisMaskGeneratorBenchmark : public QObject
Q_OBJECT
private Q_SLOTS:
void benchmarkCircle();
void benchmarkSIMD();
void benchmarkSIMD_SharpBrush();
void benchmarkSIMD_FadedBrush();
void benchmarkSquare();
};
#endif
# - 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 tmp)
endif()
elseif(_arg STREQUAL "CXX_FLAGS")
set(state 2)
if(NOT DEFINED _cxx_result)
set(_cxx_result tmp)
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")
set(state 7)
elseif(_arg STREQUAL "MIC_CXX_FLAGS")
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)
set(${_c_flags} "${${_c_flags}} ${_flag}")
endif()
if(check_cxx_compiler_flag_${_flag_esc} AND DEFINED _cxx_flags)
set(${_cxx_flags} "${${_cxx_flags}} ${_flag}")
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)
#=============================================================================
# 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.
#=============================================================================
macro(add_target_property _target _prop _value)
get_target_property(_oldprop "${_target}" ${_prop})
if(NOT _oldprop)
set_target_properties("${_target}" PROPERTIES ${_prop} "${_value}")
else(NOT _oldprop)
set_target_properties("${_target}" PROPERTIES ${_prop} "${_oldprop} ${_value}")
endif(NOT _oldprop)
endmacro(add_target_property)
# - Check whether the C compiler supports a given flag.
# CHECK_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.
#=============================================================================
INCLUDE(CheckCSourceCompiles)
MACRO (CHECK_C_COMPILER_FLAG _FLAG _RESULT)
SET(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
SET(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
if(${ARGC} GREATER 2)
SET(TEST_SOURCE "${ARGV2}")
else()
SET(TEST_SOURCE "int main() { return 0;}")
endif()
CHECK_C_SOURCE_COMPILES("${TEST_SOURCE}" ${_RESULT}
# Some compilers do not fail with a bad flag
FAIL_REGEX "error: bad value (.*) for .* switch" # GNU
FAIL_REGEX "argument unused during compilation" # clang
FAIL_REGEX "is valid for .* but not for C" # GNU
FAIL_REGEX "unrecognized .*option" # GNU
FAIL_REGEX "ignored for target" # GNU
FAIL_REGEX "ignoring unknown option" # MSVC
FAIL_REGEX "[Uu]nknown option" # HP
FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro
FAIL_REGEX "command option .* is not recognized" # XL
FAIL_REGEX "WARNING: unknown flag:" # Open64
FAIL_REGEX "command line error" # ICC
FAIL_REGEX "command line warning" # ICC
FAIL_REGEX "#10236:" # ICC: File not found
)
SET (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
ENDMACRO (CHECK_C_COMPILER_FLAG)
# - 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. See help
# for CheckCXXSourceCompiles for a listing of variables that can
# modify the build.