Skip to content

Commit

Permalink
cmake: avoid amending of CMAKE_COMPILER_IS_[GNUCXX|CLANGCXX|CCACHE] vars
Browse files Browse the repository at this point in the history
- Recommended compiler checks:
  - GCC: CV_GCC
  - Clang: CV_CLANG
- fixed problem with CMAKE_CXX_COMPILER_ID=Clang/AppleClang mess on MacOSX
  Details: cmake --help-policy CMP0025
- do not declare Clang as GCC compiler
  • Loading branch information
alalek committed Mar 27, 2018
1 parent 24acbec commit 08941b7
Show file tree
Hide file tree
Showing 18 changed files with 120 additions and 84 deletions.
10 changes: 5 additions & 5 deletions 3rdparty/carotene/hal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ endif()

set(TEGRA_COMPILER_FLAGS "")

if(CMAKE_COMPILER_IS_GNUCXX)
if(CV_GCC OR CV_CLANG)
# Generate unwind information even for functions that can't throw/propagate exceptions.
# This lets debuggers and such get non-broken backtraces for such functions, even without debugging symbols.
list(APPEND TEGRA_COMPILER_FLAGS -funwind-tables)
endif()

if(CMAKE_COMPILER_IS_GNUCXX)
if(CV_GCC OR CV_CLANG)
if(X86 OR ARMEABI_V6 OR (MIPS AND ANDROID_COMPILER_VERSION VERSION_LESS "4.6"))
list(APPEND TEGRA_COMPILER_FLAGS -fweb -fwrapv -frename-registers -fsched-stalled-insns-dep=100 -fsched-stalled-insns=2)
elseif(CMAKE_COMPILER_IS_CLANGCXX)
elseif(CV_CLANG)
list(APPEND TEGRA_COMPILER_FLAGS -fwrapv)
else()
list(APPEND TEGRA_COMPILER_FLAGS -fweb -fwrapv -frename-registers -fsched2-use-superblocks -fsched2-use-traces
Expand All @@ -40,7 +40,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TEGRA_COMPILER_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TEGRA_COMPILER_FLAGS}")

if(ARMEABI_V7A)
if (CMAKE_COMPILER_IS_GNUCXX)
if(CV_GCC OR CV_CLANG)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-tree-vectorize" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-tree-vectorize" )
endif()
Expand Down Expand Up @@ -83,7 +83,7 @@ include_directories("${CAROTENE_DIR}/include")
get_target_property(carotene_defs carotene_objs INTERFACE_COMPILE_DEFINITIONS)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS ${carotene_defs})

if (CMAKE_COMPILER_IS_GNUCXX)
if(CV_GCC)
# allow more inlines - these parameters improve performance for:
# matchTemplate about 5-10%
# goodFeaturesToTrack 10-20%
Expand Down
4 changes: 2 additions & 2 deletions 3rdparty/ippicv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ file(GLOB lib_hdrs ${IPP_IW_PATH}/include/*.h ${IPP_IW_PATH}/include/iw/*.h ${IP
add_library(${IPP_IW_LIBRARY} STATIC ${lib_srcs} ${lib_hdrs})

if(UNIX)
if(CMAKE_COMPILER_IS_GNUCXX OR CV_ICC)
if(CV_GCC OR CV_CLANG OR CV_ICC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function -Wno-missing-braces -Wno-missing-field-initializers")
endif()
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
if(CV_CLANG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-self-assign")
endif()
endif()
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/libjpeg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ endif()

add_library(${JPEG_LIBRARY} STATIC ${lib_srcs} ${lib_hdrs})

if(CMAKE_COMPILER_IS_GNUCXX)
if(CV_GCC OR CV_CLANG)
set_source_files_properties(jcdctmgr.c PROPERTIES COMPILE_FLAGS "-O1")
endif()

Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/libtiff/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ mark_as_advanced(HAVE_IEEEFP)

# Large file support
if(UNIX OR MINGW)
if(ANDROID AND (ANDROID_NATIVE_API_LEVEL LESS 21) AND (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES Clang))
if(ANDROID AND (ANDROID_NATIVE_API_LEVEL LESS 21) AND CV_GCC)
# Android NDK build problem: 'mmap' issue with GCC and API<21
else()
# This might not catch every possibility catered for by
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/tbb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ if(HAVE_PTHREAD)
add_definitions(-DUSE_PTHREAD) #required for Unix
endif()

if(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_COMPILER_IS_CLANGCXX)
if(CV_GCC)
add_definitions(-DTBB_USE_GCC_BUILTINS=1) #required for ARM GCC
if(NOT CMAKE_CXX_COMPILER_VERSION LESS 6.0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flifetime-dse=1") # workaround for GCC 6.x
Expand Down
24 changes: 12 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -313,23 +313,23 @@ OCV_OPTION(INSTALL_TESTS "Install accuracy and performance test binar
OCV_OPTION(ENABLE_CCACHE "Use ccache" (UNIX AND NOT IOS AND (CMAKE_GENERATOR MATCHES "Makefile" OR CMAKE_GENERATOR MATCHES "Ninja")) )
OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers" ON IF (NOT IOS AND NOT CMAKE_CROSSCOMPILING) )
OCV_OPTION(ENABLE_SOLUTION_FOLDERS "Solution folder in Visual Studio or in other IDEs" (MSVC_IDE OR CMAKE_GENERATOR MATCHES Xcode) )
OCV_OPTION(ENABLE_PROFILING "Enable profiling in the GCC compiler (Add flags: -g -pg)" OFF IF CMAKE_COMPILER_IS_GNUCXX )
OCV_OPTION(ENABLE_COVERAGE "Enable coverage collection with GCov" OFF IF CMAKE_COMPILER_IS_GNUCXX )
OCV_OPTION(ENABLE_OMIT_FRAME_POINTER "Enable -fomit-frame-pointer for GCC" ON IF CMAKE_COMPILER_IS_GNUCXX AND NOT (APPLE AND CMAKE_COMPILER_IS_CLANGCXX) )
OCV_OPTION(ENABLE_POWERPC "Enable PowerPC for GCC" ON IF (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_SYSTEM_PROCESSOR MATCHES powerpc.*) )
OCV_OPTION(ENABLE_VSX "Enable POWER8 and above VSX (64-bit little-endian)" ON IF (CMAKE_COMPILER_IS_GNUCXX AND PPC64LE) )
OCV_OPTION(ENABLE_FAST_MATH "Enable -ffast-math (not recommended for GCC 4.6.x)" OFF IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) )
OCV_OPTION(ENABLE_NEON "Enable NEON instructions" (NEON OR ANDROID_ARM_NEON OR AARCH64) IF CMAKE_COMPILER_IS_GNUCXX AND (ARM OR AARCH64 OR IOS) )
OCV_OPTION(ENABLE_VFPV3 "Enable VFPv3-D32 instructions" OFF IF CMAKE_COMPILER_IS_GNUCXX AND (ARM OR AARCH64 OR IOS) )
OCV_OPTION(ENABLE_PROFILING "Enable profiling in the GCC compiler (Add flags: -g -pg)" OFF IF CV_GCC )
OCV_OPTION(ENABLE_COVERAGE "Enable coverage collection with GCov" OFF IF CV_GCC )
OCV_OPTION(ENABLE_OMIT_FRAME_POINTER "Enable -fomit-frame-pointer for GCC" ON IF CV_GCC )
OCV_OPTION(ENABLE_POWERPC "Enable PowerPC for GCC" ON IF (CV_GCC AND CMAKE_SYSTEM_PROCESSOR MATCHES powerpc.*) )
OCV_OPTION(ENABLE_VSX "Enable POWER8 and above VSX (64-bit little-endian)" ON IF (CV_GCC AND PPC64LE) )
OCV_OPTION(ENABLE_FAST_MATH "Enable -ffast-math (not recommended for GCC 4.6.x)" OFF IF (CV_GCC AND (X86 OR X86_64)) )
OCV_OPTION(ENABLE_NEON "Enable NEON instructions" (NEON OR ANDROID_ARM_NEON OR AARCH64) IF (CV_GCC OR CV_CLANG) AND (ARM OR AARCH64 OR IOS) )
OCV_OPTION(ENABLE_VFPV3 "Enable VFPv3-D32 instructions" OFF IF (CV_GCC OR CV_CLANG) AND (ARM OR AARCH64 OR IOS) )
OCV_OPTION(ENABLE_NOISY_WARNINGS "Show all warnings even if they are too noisy" OFF )
OCV_OPTION(OPENCV_WARNINGS_ARE_ERRORS "Treat warnings as errors" OFF )
OCV_OPTION(ANDROID_EXAMPLES_WITH_LIBS "Build binaries of Android examples with native libraries" OFF IF ANDROID )
OCV_OPTION(ENABLE_IMPL_COLLECTION "Collect implementation data on function call" OFF )
OCV_OPTION(ENABLE_INSTRUMENTATION "Instrument functions to collect calls trace and performance" OFF )
OCV_OPTION(ENABLE_GNU_STL_DEBUG "Enable GNU STL Debug mode (defines _GLIBCXX_DEBUG)" OFF IF ((NOT CMAKE_VERSION VERSION_LESS "2.8.11") AND CMAKE_COMPILER_IS_GNUCXX) )
OCV_OPTION(ENABLE_GNU_STL_DEBUG "Enable GNU STL Debug mode (defines _GLIBCXX_DEBUG)" OFF IF ((NOT CMAKE_VERSION VERSION_LESS "2.8.11") AND CV_GCC) )
OCV_OPTION(ENABLE_BUILD_HARDENING "Enable hardening of the resulting binaries (against security attacks, detects memory corruption, etc)" OFF)
OCV_OPTION(ENABLE_LTO "Enable Link Time Optimization" OFF IF CMAKE_COMPILER_IS_GNUCXX OR MSVC)
OCV_OPTION(ENABLE_THIN_LTO "Enable Thin LTO" OFF IF CMAKE_COMPILER_IS_CLANGCXX)
OCV_OPTION(ENABLE_LTO "Enable Link Time Optimization" OFF IF CV_GCC OR MSVC)
OCV_OPTION(ENABLE_THIN_LTO "Enable Thin LTO" OFF IF CV_CLANG)
OCV_OPTION(GENERATE_ABI_DESCRIPTOR "Generate XML file for abi_compliance_checker tool" OFF IF UNIX)
OCV_OPTION(CV_ENABLE_INTRINSICS "Use intrinsic-based optimized code" ON )
OCV_OPTION(CV_DISABLE_OPTIMIZATION "Disable explicit optimized code (dispatched code/intrinsics/loop unrolling/etc)" OFF )
Expand Down Expand Up @@ -1037,7 +1037,7 @@ else()
status(" Linker flags (Release):" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_RELEASE})
status(" Linker flags (Debug):" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_DEBUG})
endif()
status(" ccache:" CMAKE_COMPILER_IS_CCACHE THEN YES ELSE NO)
status(" ccache:" OPENCV_COMPILER_IS_CCACHE THEN YES ELSE NO)
status(" Precompiled headers:" PCHSupport_FOUND AND ENABLE_PRECOMPILED_HEADERS THEN YES ELSE NO)

# ========================== Dependencies ============================
Expand Down
6 changes: 3 additions & 3 deletions cmake/OpenCVCompilerDefenses.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if(MSVC)
if(NOT X86_64)
set(OPENCV_LINKER_DEFENSES_FLAGS_COMMON "${OPENCV_LINKER_DEFENSES_FLAGS_COMMON} /safeseh")
endif()
elseif(CMAKE_COMPILER_IS_GNUCXX)
elseif(CV_GCC)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9")
ocv_add_defense_compiler_flag("-fstack-protector")
else()
Expand All @@ -71,7 +71,7 @@ else()
endif()

set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
if(CMAKE_COMPILER_IS_GNUCXX)
if(CV_GCC OR CV_CLANG)
if(NOT CMAKE_CXX_FLAGS MATCHES "-fPIC")
ocv_add_defense_compiler_flag("-fPIC")
endif()
Expand All @@ -82,7 +82,7 @@ set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OPENCV_LINKER_DEF
set( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${OPENCV_LINKER_DEFENSES_FLAGS_COMMON}" )
set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OPENCV_LINKER_DEFENSES_FLAGS_COMMON}" )

if(CMAKE_COMPILER_IS_GNUCXX)
if(CV_GCC OR CV_CLANG)
foreach(flags
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG
CMAKE_C_FLAGS CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_DEBUG)
Expand Down
8 changes: 4 additions & 4 deletions cmake/OpenCVCompilerOptimizations.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ if(X86 OR X86_64)
endif()
ocv_intel_compiler_optimization_option(AVX_512F "-march=common-avx512" "/arch:COMMON-AVX512")
ocv_intel_compiler_optimization_option(AVX512_SKX "-march=core-avx512" "/arch:CORE-AVX512")
elseif(CMAKE_COMPILER_IS_GNUCXX)
elseif(CV_GCC OR CV_CLANG)
ocv_update(CPU_AVX2_FLAGS_ON "-mavx2")
ocv_update(CPU_FP16_FLAGS_ON "-mf16c")
ocv_update(CPU_AVX_FLAGS_ON "-mavx")
Expand All @@ -223,7 +223,7 @@ if(X86 OR X86_64)
ocv_update(CPU_SSSE3_FLAGS_ON "-mssse3")
ocv_update(CPU_SSE2_FLAGS_ON "-msse2")
ocv_update(CPU_SSE_FLAGS_ON "-msse")
if(NOT (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0")) # GCC >= 5.0
if(NOT (CV_GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0")) # GCC >= 5.0
# -mavx512f -mavx512pf -mavx512er -mavx512cd -mavx512vl -mavx512bw -mavx512dq -mavx512ifma -mavx512vbmi
ocv_update(CPU_AVX_512F_FLAGS_ON "-mavx512f")
ocv_update(CPU_AVX512_SKX_FLAGS_ON "-mavx512f -mavx512cd -mavx512vl -mavx512bw -mavx512dq")
Expand Down Expand Up @@ -288,7 +288,7 @@ elseif(PPC64LE)
ocv_update(CPU_KNOWN_OPTIMIZATIONS "VSX")
ocv_update(CPU_VSX_TEST_FILE "${OpenCV_SOURCE_DIR}/cmake/checks/cpu_vsx.cpp")

if(CMAKE_COMPILER_IS_CLANGCXX AND (NOT ${CMAKE_CXX_COMPILER} MATCHES "xlc"))
if(CV_CLANG AND (NOT ${CMAKE_CXX_COMPILER} MATCHES "xlc"))
ocv_update(CPU_VSX_FLAGS_ON "-mvsx -maltivec")
else()
ocv_update(CPU_VSX_FLAGS_ON "-mcpu=power8")
Expand Down Expand Up @@ -545,7 +545,7 @@ macro(ocv_compiler_optimization_options)
endmacro()

macro(ocv_compiler_optimization_options_finalize)
if(CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64))
if((CV_GCC OR CV_CLANG) AND (X86 OR X86_64))
if(NOT APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 4)
if(OPENCV_EXTRA_CXX_FLAGS MATCHES "-m(sse2|avx)")
add_extra_compiler_option(-mfpmath=sse) # !! important - be on the same wave with x64 compilers
Expand Down
28 changes: 20 additions & 8 deletions cmake/OpenCVCompilerOptions.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
if(ENABLE_CCACHE AND NOT CMAKE_COMPILER_IS_CCACHE)
if("${CMAKE_CXX_COMPILER};${CMAKE_C_COMPILER};${CMAKE_CXX_COMPILER_LAUNCHER}" MATCHES "ccache")
set(CMAKE_COMPILER_IS_CCACHE 1) # FIXIT Avoid setting of CMAKE_ variables
set(OPENCV_COMPILER_IS_CCACHE 1)
endif()
function(access_CMAKE_COMPILER_IS_CCACHE)
if(NOT OPENCV_SUPPRESS_DEPRECATIONS)
message(WARNING "DEPRECATED: CMAKE_COMPILER_IS_CCACHE is replaced to OPENCV_COMPILER_IS_CCACHE.")
endif()
endfunction()
variable_watch(CMAKE_COMPILER_IS_CCACHE access_CMAKE_COMPILER_IS_CCACHE)
if(ENABLE_CCACHE AND NOT OPENCV_COMPILER_IS_CCACHE AND NOT CMAKE_GENERATOR MATCHES "Xcode")
# This works fine with Unix Makefiles and Ninja generators
find_host_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
Expand All @@ -13,7 +23,7 @@ if(ENABLE_CCACHE AND NOT CMAKE_COMPILER_IS_CCACHE)
# ocv_check_compiler_flag(CXX "" IS_CCACHE_WORKS)
set(IS_CCACHE_WORKS 1)
if(IS_CCACHE_WORKS)
set(CMAKE_COMPILER_IS_CCACHE 1)
set(OPENCV_COMPILER_IS_CCACHE 1)
else()
message(STATUS "Unable to compile program with enabled ccache, reverting...")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${__OLD_RULE_LAUNCH_COMPILE}")
Expand All @@ -24,7 +34,9 @@ if(ENABLE_CCACHE AND NOT CMAKE_COMPILER_IS_CCACHE)
endif()
endif()

if((CMAKE_COMPILER_IS_CLANGCXX OR CMAKE_COMPILER_IS_CLANGCC OR CMAKE_COMPILER_IS_CCACHE) AND NOT CMAKE_GENERATOR MATCHES "Xcode")
if((CV_CLANG AND NOT CMAKE_GENERATOR MATCHES "Xcode") # PCH has no support for Clang
OR OPENCV_COMPILER_IS_CCACHE
)
set(ENABLE_PRECOMPILED_HEADERS OFF CACHE BOOL "" FORCE)
endif()

Expand Down Expand Up @@ -71,7 +83,7 @@ if(CV_ICC AND NOT ENABLE_FAST_MATH)
endif()
endif()

if(CMAKE_COMPILER_IS_GNUCXX)
if(CV_GCC OR CV_CLANG)
# High level of warnings.
add_extra_compiler_option(-W)
add_extra_compiler_option(-Wall)
Expand Down Expand Up @@ -101,7 +113,7 @@ if(CMAKE_COMPILER_IS_GNUCXX)
add_extra_compiler_option(-Wno-unnamed-type-template-args)
add_extra_compiler_option(-Wno-comment)
add_extra_compiler_option(-Wno-implicit-fallthrough)
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 7.2.0)
if(CV_GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 7.2.0)
add_extra_compiler_option(-Wno-strict-overflow) # Issue is fixed in GCC 7.2.1
endif()
endif()
Expand All @@ -113,11 +125,11 @@ if(CMAKE_COMPILER_IS_GNUCXX)
endif()

# We need pthread's
if(UNIX AND NOT ANDROID AND NOT (APPLE AND CMAKE_COMPILER_IS_CLANGCXX)) # TODO
if(UNIX AND NOT ANDROID AND NOT (APPLE AND CV_CLANG)) # TODO
add_extra_compiler_option(-pthread)
endif()

if(CMAKE_COMPILER_IS_CLANGCXX)
if(CV_CLANG)
add_extra_compiler_option(-Qunused-arguments)
endif()

Expand Down Expand Up @@ -241,7 +253,7 @@ if(COMMAND ocv_compiler_optimization_options_finalize)
endif()

# set default visibility to hidden
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if((CV_GCC OR CV_CLANG)
AND NOT OPENCV_SKIP_VISIBILITY_HIDDEN
AND NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " -fvisibility")
add_extra_compiler_option(-fvisibility=hidden)
Expand Down
4 changes: 2 additions & 2 deletions cmake/OpenCVDetectCUDA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if(WIN32 AND NOT MSVC)
return()
endif()

if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(NOT APPLE AND CV_CLANG)
message(STATUS "CUDA compilation is disabled (due to Clang unsupported on your platform).")
return()
endif()
Expand Down Expand Up @@ -222,7 +222,7 @@ if(CUDA_FOUND)
endif()

# disabled because of multiple warnings during building nvcc auto generated files
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.6.0")
if(CV_GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.6.0")
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wunused-but-set-variable)
endif()

Expand Down
73 changes: 48 additions & 25 deletions cmake/OpenCVDetectCXXCompiler.cmake
Original file line number Diff line number Diff line change
@@ -1,29 +1,54 @@
# Compilers:
# - CV_GCC - GNU compiler (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# - CV_CLANG - Clang-compatible compiler (CMAKE_CXX_COMPILER_ID MATCHES "Clang" - Clang or AppleClang, see CMP0025)
# - CV_ICC - Intel compiler
# - MSVC - Microsoft Visual Compiler (CMake variable)
# - MSVC64 - additional flag, 64-bit
# - MINGW / CYGWIN / CMAKE_COMPILER_IS_MINGW / CMAKE_COMPILER_IS_CYGWIN (CMake original variables)
# - MINGW64 - 64-bit
#
# CPU Platforms:
# - X86 / X86_64
# - ARM - ARM CPU, not defined for AArch64
# - AARCH64 - ARMv8+ (64-bit)
# - PPC64 / PPC64LE - PowerPC
#
# OS:
# - WIN32 - Windows | MINGW
# - UNIX - Linux | MacOSX | ANDROID
# - ANDROID
# - IOS
# - APPLE - MacOSX | iOS
# ----------------------------------------------------------------------------
# Detect Microsoft compiler:
# ----------------------------------------------------------------------------

if(CMAKE_CL_64)
set(MSVC64 1)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_COMPILER_IS_GNUCXX 1)
set(CMAKE_COMPILER_IS_CLANGCXX 1)
if(NOT DEFINED CV_GCC AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CV_GCC 1)
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(CMAKE_COMPILER_IS_GNUCC 1)
set(CMAKE_COMPILER_IS_CLANGCC 1)
endif()
if("${CMAKE_CXX_COMPILER};${CMAKE_C_COMPILER};${CMAKE_CXX_COMPILER_LAUNCHER}" MATCHES "ccache")
set(CMAKE_COMPILER_IS_CCACHE 1)
if(NOT DEFINED CV_CLANG AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Clang or AppleClang (see CMP0025)
set(CV_CLANG 1)
set(CMAKE_COMPILER_IS_CLANGCXX 1) # TODO next release: remove this
set(CMAKE_COMPILER_IS_CLANGCC 1) # TODO next release: remove this
endif()

function(access_CMAKE_COMPILER_IS_CLANGCXX)
if(NOT OPENCV_SUPPRESS_DEPRECATIONS)
message(WARNING "DEPRECATED: CMAKE_COMPILER_IS_CLANGCXX support is deprecated in OpenCV.
Consider using:
- CV_GCC # GCC
- CV_CLANG # Clang or AppleClang (see CMP0025)
")
endif()
endfunction()
variable_watch(CMAKE_COMPILER_IS_CLANGCXX access_CMAKE_COMPILER_IS_CLANGCXX)
variable_watch(CMAKE_COMPILER_IS_CLANGCC access_CMAKE_COMPILER_IS_CLANGCXX)


# ----------------------------------------------------------------------------
# Detect Intel ICC compiler -- for -fPIC in 3rdparty ( UNIX ONLY ):
# see include/opencv/cxtypes.h file for related ICC & CV_ICC defines.
# NOTE: The system needs to determine if the '-fPIC' option needs to be added
# for the 3rdparty static libs being compiled. The CMakeLists.txt files
# in 3rdparty use the CV_ICC definition being set here to determine if
# the -fPIC flag should be used.
# Detect Intel ICC compiler
# ----------------------------------------------------------------------------
if(UNIX)
if (__ICL)
Expand All @@ -49,14 +74,12 @@ if(NOT DEFINED CMAKE_CXX_COMPILER_VERSION)
message(WARNING "Compiler version is not available: CMAKE_CXX_COMPILER_VERSION is not set")
endif()

if(CMAKE_COMPILER_IS_GNUCXX)
if(WIN32)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine
OUTPUT_VARIABLE OPENCV_GCC_TARGET_MACHINE
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(OPENCV_GCC_TARGET_MACHINE MATCHES "amd64|x86_64|AMD64")
set(MINGW64 1)
endif()
if(WIN32 AND CV_GCC)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine
OUTPUT_VARIABLE OPENCV_GCC_TARGET_MACHINE
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(OPENCV_GCC_TARGET_MACHINE MATCHES "amd64|x86_64|AMD64")
set(MINGW64 1)
endif()
endif()

Expand Down
2 changes: 1 addition & 1 deletion cmake/OpenCVDetectTBB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function(ocv_tbb_env_guess _found)
INTERFACE_INCLUDE_DIRECTORIES "${TBB_ENV_INCLUDE}"
)
# workaround: system TBB library is used for linking instead of provided
if(CMAKE_COMPILER_IS_GNUCXX)
if(CV_GCC)
get_filename_component(_dir "${TBB_ENV_LIB}" DIRECTORY)
set_target_properties(tbb PROPERTIES INTERFACE_LINK_LIBRARIES "-L${_dir}")
endif()
Expand Down
2 changes: 1 addition & 1 deletion cmake/OpenCVFindLibsGUI.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ endif(WITH_OPENGL)
if(APPLE)
if(WITH_CARBON)
set(HAVE_CARBON YES)
elseif(NOT IOS AND CMAKE_COMPILER_IS_CLANGCXX)
elseif(NOT IOS AND CV_CLANG)
set(HAVE_COCOA YES)
endif()
endif()
Loading

0 comments on commit 08941b7

Please sign in to comment.