2024-05-13 11:53:28 +00:00
# cmake_minimum_required(VERSION 3.0)
2024-05-07 20:02:47 +00:00
cmake_policy ( SET CMP0028 NEW ) # Double colon in target name means ALIAS or IMPORTED target.
cmake_policy ( SET CMP0048 NEW ) # The ``project()`` command manages VERSION variables.
if ( PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR )
message ( FATAL_ERROR "You don't want to configure in the source directory!" )
endif ( )
if ( NOT DEFINED CMAKE_BUILD_TYPE )
set ( CMAKE_BUILD_TYPE Release CACHE STRING
" C h o o s e t h e t y p e o f b u i l d , o p t i o n s a r e : N o n e D e b u g R e l e a s e R e l W i t h D e b u g R e l W i t h D e b I n f o M i n S i z e R e l . "
F O R C E )
endif ( )
# read version parts from version.h
file ( STRINGS ${ CMAKE_CURRENT_SOURCE_DIR } /Vc/version.h _version_lines REGEX "^#define Vc_VERSION_STRING " )
string ( REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" _version_matches "${_version_lines}" )
project ( Vc VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}" LANGUAGES C CXX )
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake" )
set ( disabled_targets )
include ( VcMacros )
include ( AddTargetProperty )
include ( OptimizeForArchitecture )
vc_determine_compiler ( )
if ( "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "(i686|x86|AMD64|amd64)" )
set ( Vc_X86 TRUE )
elseif ( "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "(arm|aarch32|aarch64)" )
message ( WARNING "No optimized implementation of the Vc types available for ${CMAKE_SYSTEM_PROCESSOR}" )
set ( Vc_ARM TRUE )
else ( )
message ( WARNING "No optimized implementation of the Vc types available for ${CMAKE_SYSTEM_PROCESSOR}" )
endif ( )
option ( USE_CCACHE "If enabled, ccache will be used (if it exists on the system) to speed up recompiles." OFF )
if ( USE_CCACHE )
find_program ( CCACHE_COMMAND ccache )
if ( CCACHE_COMMAND )
mark_as_advanced ( CCACHE_COMMAND )
set_property ( GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_COMMAND}" )
endif ( )
endif ( )
if ( NOT Vc_COMPILER_IS_MSVC )
AddCompilerFlag ( "-std=c++14" CXX_RESULT _ok CXX_FLAGS CMAKE_CXX_FLAGS )
if ( NOT _ok )
AddCompilerFlag ( "-std=c++1y" CXX_RESULT _ok CXX_FLAGS CMAKE_CXX_FLAGS )
if ( NOT _ok )
AddCompilerFlag ( "-std=c++11" CXX_RESULT _ok CXX_FLAGS CMAKE_CXX_FLAGS )
if ( NOT _ok )
AddCompilerFlag ( "-std=c++0x" CXX_RESULT _ok CXX_FLAGS CMAKE_CXX_FLAGS )
if ( NOT _ok )
message ( FATAL_ERROR "Vc 1.x requires C++11, better even C++14. It seems this is not available. If this was incorrectly determined please notify vc-devel@compeng.uni-frankfurt.de" )
endif ( )
endif ( )
endif ( )
endif ( )
# elseif(MSVC_VERSION LESS 1920)
# message(FATAL_ERROR "Vc 1.x requires at least Visual Studio 2019.")
# AddCompilerFlag("/std:c++14" CXX_RESULT _ok CXX_FLAGS CMAKE_CXX_FLAGS)
endif ( )
# if(MSVC AND (NOT DEFINED Vc_USE_MSVC_SSA_OPTIMIZER_DESPITE_BUGGY_EXP OR NOT Vc_USE_MSVC_SSA_OPTIMIZER_DESPITE_BUGGY_EXP))
# # bug report: https://developercommunity.visualstudio.com/t/AVX-codegen-bug-on-Vc-with-MSVC-2019/1470844#T-N1521672
# message(STATUS "WARNING! MSVC starting with 19.20 uses a new optimizer that has a bug causing Vc::exp() to return slighly wrong results.\
# You can set Vc_USE_MSVC_SSA_OPTIMIZER_DESPITE_BUGGY_EXP=ON to still use the new optimizer on the affected MSVC versions.")
# AddCompilerFlag("/d2SSAOptimizer-" CXX_RESULT _ok CXX_FLAGS CMAKE_CXX_FLAGS)
# endif()
if ( Vc_COMPILER_IS_GCC )
if ( Vc_GCC_VERSION VERSION_GREATER "5.0.0" AND Vc_GCC_VERSION VERSION_LESS "6.0.0" )
UserWarning ( "GCC 5 goes into an endless loop comiling example_scaling_scalar. Therefore, this target is disabled." )
list ( APPEND disabled_targets
e x a m p l e _ s c a l i n g _ s c a l a r
)
endif ( )
# elseif(Vc_COMPILER_IS_MSVC)
# # Disable warning "C++ exception specification ignored except to indicate a function is not __declspec(nothrow)"
# # MSVC emits the warning for the _UnitTest_Compare desctructor which needs the throw declaration so that it doesn't std::terminate
# AddCompilerFlag("/wd4290")
endif ( )
vc_set_preferred_compiler_flags ( WARNING_FLAGS BUILDTYPE_FLAGS )
add_definitions ( ${ Vc_DEFINITIONS } )
add_compile_options ( ${ Vc_COMPILE_FLAGS } )
if ( Vc_COMPILER_IS_INTEL )
# per default icc is not IEEE compliant, but we need that for verification
AddCompilerFlag ( "-fp-model source" )
endif ( )
if ( CMAKE_BUILD_TYPE STREQUAL "" AND NOT CMAKE_CXX_FLAGS MATCHES "-O[123]" )
message ( STATUS "WARNING! It seems you are compiling without optimization. Please set CMAKE_BUILD_TYPE." )
endif ( CMAKE_BUILD_TYPE STREQUAL "" AND NOT CMAKE_CXX_FLAGS MATCHES "-O[123]" )
include_directories ( ${ CMAKE_CURRENT_SOURCE_DIR } ) # ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_custom_target ( other VERBATIM )
add_custom_target ( Scalar COMMENT "build Scalar code" VERBATIM )
add_custom_target ( SSE COMMENT "build SSE code" VERBATIM )
add_custom_target ( AVX COMMENT "build AVX code" VERBATIM )
add_custom_target ( AVX2 COMMENT "build AVX2 code" VERBATIM )
AddCompilerFlag ( -ftemplate-depth=128 CXX_FLAGS CMAKE_CXX_FLAGS )
set ( libvc_compile_flags "-DVc_COMPILE_LIB" )
AddCompilerFlag ( "-fPIC" CXX_FLAGS libvc_compile_flags )
# -fstack-protector is the default of GCC, but at least Ubuntu changes the default to -fstack-protector-strong, which is crazy
AddCompilerFlag ( "-fstack-protector" CXX_FLAGS libvc_compile_flags )
set ( _srcs src/const.cpp )
if ( Vc_X86 )
list ( APPEND _srcs src/cpuid.cpp src/support_x86.cpp )
vc_compile_for_all_implementations ( _srcs src/trigonometric.cpp ONLY SSE2 SSE3 SSSE3 SSE4_1 AVX AVX+FMA AVX2+FMA+BMI2 )
if ( NOT Vc_XOP_INTRINSICS_BROKEN )
vc_compile_for_all_implementations ( _srcs src/trigonometric.cpp ONLY AVX+XOP+FMA )
if ( NOT Vc_FMA4_INTRINSICS_BROKEN )
vc_compile_for_all_implementations ( _srcs src/trigonometric.cpp ONLY SSE+XOP+FMA4 AVX+XOP+FMA4 )
endif ( )
endif ( )
vc_compile_for_all_implementations ( _srcs src/sse_sorthelper.cpp ONLY SSE2 SSE4_1 AVX AVX2+FMA+BMI2 )
vc_compile_for_all_implementations ( _srcs src/avx_sorthelper.cpp ONLY AVX AVX2+FMA+BMI2 )
elseif ( Vc_ARM )
list ( APPEND _srcs src/support_dummy.cpp )
else ( )
list ( APPEND _srcs src/support_dummy.cpp )
endif ( )
add_library ( Vc STATIC ${ _srcs } )
set_property ( TARGET Vc APPEND PROPERTY COMPILE_OPTIONS ${ libvc_compile_flags } )
add_target_property ( Vc LABELS "other" )
if ( XCODE )
# TODO: document what this does and why it has no counterpart in the non-XCODE logic
set_target_properties ( Vc PROPERTIES XCODE_ATTRIBUTE_GCC_INLINES_ARE_PRIVATE_EXTERN "NO" )
set_target_properties ( Vc PROPERTIES XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN "YES" )
set_target_properties ( Vc PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++0x" )
set_target_properties ( Vc PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++" )
elseif ( UNIX AND Vc_COMPILER_IS_CLANG )
# On UNIX (Linux) the standard library used by default typically is libstdc++ (GCC).
# To get the full clang deal we rather want to build against libc++. This requires
# additionally the libc++abi and libsupc++ libraries in all linker invokations.
option ( USE_LIBC++ "Use libc++ instead of the system default C++ standard library." OFF )
if ( USE_LIBC++ )
AddCompilerFlag ( -stdlib=libc++ CXX_FLAGS CMAKE_CXX_FLAGS CXX_RESULT _use_libcxx )
if ( _use_libcxx )
find_library ( LIBC++ABI c++abi )
mark_as_advanced ( LIBC++ABI )
if ( LIBC++ABI )
set ( CMAKE_REQUIRED_LIBRARIES "${LIBC++ABI};supc++" )
CHECK_CXX_SOURCE_COMPILES ( " #include <stdexcept>
#include <iostream>
v o i d foo ( ) {
s t d : : c o u t < < ' h ' < < s t d : : f l u s h < < s t d : : e n d l ;
t h r o w s t d : : exception ( ) ;
}
i n t main ( ) {
t r y { foo ( ) ; }
catch ( int ) { r e t u r n 0 ; }
r e t u r n 1 ;
} " l i b c x x _ c o m p i l e s )
unset ( CMAKE_REQUIRED_LIBRARIES )
if ( libcxx_compiles )
link_libraries ( ${ LIBC++ABI } supc++ )
endif ( )
endif ( )
endif ( )
else ( )
CHECK_CXX_SOURCE_COMPILES ( " #include <tuple>
s t d : : t u p l e < i n t > f ( ) { s t d : : t u p l e < i n t > r ; r e t u r n r ; }
i n t main ( ) { r e t u r n 0 ; }
" t u p l e _ s a n i t y )
if ( NOT tuple_sanity )
message ( FATAL_ERROR "Clang and std::tuple brokenness detected. Please update your compiler." )
endif ( )
endif ( )
endif ( )
add_dependencies ( other Vc )
target_include_directories ( Vc
P U B L I C
$ < B U I L D _ I N T E R F A C E : $ { P R O J E C T _ S O U R C E _ D I R } >
$ < I N S T A L L _ I N T E R F A C E : i n c l u d e >
)
2024-05-13 08:36:58 +00:00
option ( Vc_ENABLE_INSTALL "Whether to install the library." OFF )
2024-05-07 20:02:47 +00:00
if ( Vc_ENABLE_INSTALL )
install ( TARGETS Vc EXPORT VcTargets DESTINATION lib ${ LIB_SUFFIX } )
install ( DIRECTORY Vc/ DESTINATION include/Vc FILES_MATCHING REGEX "/*.(h|tcc|def)$" )
install ( FILES
V c / A l l o c a t o r
V c / I O
V c / M e m o r y
V c / S i m d A r r a y
V c / U t i l s
V c / V c
V c / a l g o r i t h m
V c / a r r a y
V c / i t e r a t o r s
V c / l i m i t s
V c / s i m d i z e
V c / s p a n
V c / t y p e _ t r a i t s
V c / v e c t o r
D E S T I N A T I O N i n c l u d e / V c )
# Generate and install CMake package and modules
include ( CMakePackageConfigHelpers )
set ( PACKAGE_INSTALL_DESTINATION
l i b $ { L I B _ S U F F I X } / c m a k e / $ { P R O J E C T _ N A M E }
)
install ( EXPORT ${ PROJECT_NAME } Targets
N A M E S P A C E $ { P R O J E C T _ N A M E } : :
D E S T I N A T I O N $ { P A C K A G E _ I N S T A L L _ D E S T I N A T I O N }
E X P O R T _ L I N K _ I N T E R F A C E _ L I B R A R I E S
)
write_basic_package_version_file (
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c m a k e / $ { P R O J E C T _ N A M E } C o n f i g V e r s i o n . c m a k e
V E R S I O N $ { P R O J E C T _ V E R S I O N }
C O M P A T I B I L I T Y A n y N e w e r V e r s i o n
)
configure_package_config_file (
$ { P R O J E C T _ S O U R C E _ D I R } / c m a k e / $ { P R O J E C T _ N A M E } C o n f i g . c m a k e . i n
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c m a k e / $ { P R O J E C T _ N A M E } C o n f i g . c m a k e
I N S T A L L _ D E S T I N A T I O N $ { P A C K A G E _ I N S T A L L _ D E S T I N A T I O N }
P A T H _ V A R S C M A K E _ I N S T A L L _ P R E F I X
)
install ( FILES
c m a k e / U s e r W a r n i n g . c m a k e
c m a k e / V c M a c r o s . c m a k e
c m a k e / A d d C o m p i l e r F l a g . c m a k e
c m a k e / C h e c k C C o m p i l e r F l a g . c m a k e
c m a k e / C h e c k C X X C o m p i l e r F l a g . c m a k e
c m a k e / O p t i m i z e F o r A r c h i t e c t u r e . c m a k e
c m a k e / F i n d V c . c m a k e
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c m a k e / $ { P R O J E C T _ N A M E } C o n f i g . c m a k e
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c m a k e / $ { P R O J E C T _ N A M E } C o n f i g V e r s i o n . c m a k e
D E S T I N A T I O N $ { P A C K A G E _ I N S T A L L _ D E S T I N A T I O N }
)
endif ( )
# option(BUILD_TESTING "Build the testing tree." OFF)
# include (CTest)
# configure_file(${PROJECT_SOURCE_DIR}/CTestCustom.cmake ${PROJECT_BINARY_DIR}/CTestCustom.cmake COPYONLY)
# if(BUILD_TESTING)
# add_custom_target(build_tests ALL VERBATIM)
# add_subdirectory(tests)
# endif()
# set(BUILD_EXAMPLES FALSE CACHE BOOL "Build examples.")
# if(BUILD_EXAMPLES)
# add_subdirectory(examples)
# endif(BUILD_EXAMPLES)
# Hide Vc_IMPL as it is only meant for users of Vc
mark_as_advanced ( Vc_IMPL )
# find_program(BIN_CAT cat)
# mark_as_advanced(BIN_CAT)
# if(BIN_CAT)
# file(REMOVE ${PROJECT_BINARY_DIR}/help.txt)
# add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/help.txt
# COMMAND ${CMAKE_MAKE_PROGRAM} help > ${PROJECT_BINARY_DIR}/help.txt
# VERBATIM
# )
# add_custom_target(cached_help
# ${BIN_CAT} ${PROJECT_BINARY_DIR}/help.txt
# DEPENDS ${PROJECT_BINARY_DIR}/help.txt
# VERBATIM
# )
# endif()