Skip to content

Commit

Permalink
use more target based cmake commands
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Mar 22, 2022
1 parent 543aea2 commit be16847
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
30 changes: 14 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ if(USE_CCACHE)
endif()
endif()

add_library(Vc STATIC)
target_compile_features(Vc PUBLIC cxx_std_11)

if(Vc_COMPILER_IS_GCC)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5.0.0" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0.0")
Expand All @@ -60,16 +62,15 @@ endif()

vc_set_preferred_compiler_flags(WARNING_FLAGS BUILDTYPE_FLAGS)

add_definitions(${Vc_DEFINITIONS})
add_compile_options(${Vc_COMPILE_FLAGS})
target_compile_definitions(Vc PUBLIC ${Vc_DEFINITIONS})
target_compile_definitions(Vc PRIVATE Vc_COMPILE_LIB)
target_compile_options(Vc PUBLIC ${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()

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)
Expand All @@ -78,26 +79,23 @@ 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")
set(libvc_compile_flags)
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)
target_sources(Vc PRIVATE 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 SSE+XOP+FMA4 AVX+XOP+FMA4 AVX+XOP+FMA AVX+FMA AVX2+FMA+BMI2)
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)
target_sources(Vc PRIVATE src/cpuid.cpp src/support_x86.cpp)
vc_compile_for_all_implementations(src/trigonometric.cpp ONLY SSE2 SSE3 SSSE3 SSE4_1 AVX SSE+XOP+FMA4 AVX+XOP+FMA4 AVX+XOP+FMA AVX+FMA AVX2+FMA+BMI2)
vc_compile_for_all_implementations(src/sse_sorthelper.cpp ONLY SSE2 SSE4_1 AVX AVX2+FMA+BMI2)
vc_compile_for_all_implementations(src/avx_sorthelper.cpp ONLY AVX AVX2+FMA+BMI2)
else()
list(APPEND _srcs src/support_dummy.cpp)
target_sources(Vc PRIVATE src/support_dummy.cpp)
endif()
add_library(Vc STATIC ${_srcs})
target_compile_features(Vc PUBLIC cxx_std_11)
set_property(TARGET Vc APPEND PROPERTY COMPILE_OPTIONS ${libvc_compile_flags})

target_compile_options(Vc PRIVATE ${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
Expand Down
42 changes: 21 additions & 21 deletions cmake/VcMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#=============================================================================

cmake_minimum_required(VERSION 2.8.3...3.13)
cmake_minimum_required(VERSION 3.13)

include ("${CMAKE_CURRENT_LIST_DIR}/UserWarning.cmake")
include ("${CMAKE_CURRENT_LIST_DIR}/AddCompilerFlag.cmake")
Expand Down Expand Up @@ -323,7 +323,7 @@ int main() { return 0; }
endmacro()

# helper macro for vc_compile_for_all_implementations
macro(_vc_compile_one_implementation _srcs _impl)
macro(_vc_compile_one_implementation _impl)
list(FIND _disabled_targets "${_impl}" _disabled_index)
list(FIND _only_targets "${_impl}" _only_index)
if(${_disabled_index} GREATER -1)
Expand Down Expand Up @@ -379,7 +379,7 @@ macro(_vc_compile_one_implementation _srcs _impl)
COMPILE_DEFINITIONS "Vc_IMPL=${_impl}"
COMPILE_FLAGS "${_flags} ${_extra_flags}"
)
list(APPEND ${_srcs} "${_out}")
target_sources(Vc PRIVATE "${_out}")
endif()
endif()
endmacro()
Expand All @@ -390,7 +390,7 @@ endmacro()
# 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)
macro(vc_compile_for_all_implementations _src)
set(_flags)
unset(_disabled_targets)
unset(_only_targets)
Expand All @@ -415,34 +415,34 @@ macro(vc_compile_for_all_implementations _srcs _src)

set(_vc_compile_src "${_src}")

_vc_compile_one_implementation(${_srcs} Scalar NO_FLAG)
_vc_compile_one_implementation(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")
_vc_compile_one_implementation(SSE2 "-xSSE2" "-msse2" "/arch:SSE2")
_vc_compile_one_implementation(SSE3 "-xSSE3" "-msse3" "/arch:SSE2")
_vc_compile_one_implementation(SSSE3 "-xSSSE3" "-mssse3" "/arch:SSE2")
_vc_compile_one_implementation(SSE4_1 "-xSSE4.1" "-msse4.1" "/arch:SSE2")
_vc_compile_one_implementation(SSE4_2 "-xSSE4.2" "-msse4.2" "/arch:SSE2")
_vc_compile_one_implementation(SSE3+SSE4a "-msse4a")
endif()
if(NOT Vc_AVX_INTRINSICS_BROKEN)
_vc_compile_one_implementation(${_srcs} AVX "-xAVX" "-mavx" "/arch:AVX")
_vc_compile_one_implementation(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" "" "")
_vc_compile_one_implementation(SSE+XOP+FMA4 "-mxop -mfma4" "" "")
_vc_compile_one_implementation(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" "" "")
_vc_compile_one_implementation(SSE+XOP+FMA "-mxop -mfma" "" "")
_vc_compile_one_implementation(AVX+XOP+FMA "-mavx -mxop -mfma" "" "")
endif()
_vc_compile_one_implementation(${_srcs} AVX+FMA "-mavx -mfma" "" "")
_vc_compile_one_implementation(AVX+FMA "-mavx -mfma" "" "")
endif()
if(NOT Vc_AVX2_INTRINSICS_BROKEN)
# The necessary list is not clear to me yet. At this point I'll only consider Intel CPUs, in
# which case AVX2 implies the availability of FMA and BMI2
#_vc_compile_one_implementation(${_srcs} AVX2 "-mavx2")
#_vc_compile_one_implementation(${_srcs} AVX2+BMI2 "-mavx2 -mbmi2")
_vc_compile_one_implementation(${_srcs} AVX2+FMA+BMI2 "-xCORE-AVX2" "-mavx2 -mfma -mbmi2" "/arch:AVX2")
#_vc_compile_one_implementation(${_srcs} AVX2+FMA "-mavx2 -mfma")
#_vc_compile_one_implementation(AVX2 "-mavx2")
#_vc_compile_one_implementation(AVX2+BMI2 "-mavx2 -mbmi2")
_vc_compile_one_implementation(AVX2+FMA+BMI2 "-xCORE-AVX2" "-mavx2 -mfma -mbmi2" "/arch:AVX2")
#_vc_compile_one_implementation(AVX2+FMA "-mavx2 -mfma")
endif()
list(LENGTH _only_targets _len)
if(_len GREATER 0)
Expand Down

0 comments on commit be16847

Please sign in to comment.