Sebastian Graf
Sebastian Graf

Reputation: 3740

Including libsimdpp in a CMake project

I decided to use libsimdpp for vectorization of my C++ code. Problem is, there is next to no documentation on how to get started.

Í assumed inclusion would be simple given that it's also CMake based like the project I'm doing, so I just tried to copy over the directory and set the include path. Well, turns out this is not enough: You need to define the appropriate flags to specify which SIMD flavor you want to compile for. libsimdpp includes a CMake macro just for that and it works wonders. I'm not sure however how to get going from here and it feels like I'm working against CMake rather than with it by copying things around and deleting stuff.

Would anyone with a firm understanding of CMake set out to explain what to do in a step-by-step fashion? Thanks!

Upvotes: 2

Views: 306

Answers (1)

p12
p12

Reputation: 1191

You should check out the simdpp/test/CMakeLists.txt file where the tests of libsimdpp are compiled. The relevant parts are these:

foreach(SRC ${TEST1_ARCH_SOURCES})
    simdpp_multiarch(TEST1_ARCH_GEN_SOURCES ${SRC} ${COMPILABLE_ARCHS})
endforeach()

add_executable(test1 EXCLUDE_FROM_ALL
    ${TEST1_SOURCES}
    ${TEST1_ARCH_GEN_SOURCES}
)

Basically, TEST1_ARCH_SOURCES contains the code that uses libsimdpp. simdpp_multiarch copies the sources around and sets appropriate compile flags for them, so that implementations for e.g. SSE2 and AVX2 can be linked into the same executable. Then these generated sources (TEST1_ARCH_GEN_SOURCES) are added into the executable.

Upvotes: 2

Related Questions