How do I use CMake to build an ispc file?

1.7k views Asked by At

I have a simple project. It contains two files:

main.c
kernel.ispc

(ispc files are source for https://ispc.github.io/)

To manually compile the file I would just use:

ispc --target=sse2 kernel.ispc -o kernel.o
gcc -c main.c -o main.o
gcc main.o kernel.o -o my_program

So for my cmake file it would look intially look like

project(my_program)
add_executable(my_program main.c)

but of course it wont link as it's missing symbols that are in kernel.o

So the question is: How do I get cmake to compile kernel.ispc using the ispc compiler, and how do I get cmake to then link it into my_program?

2

There are 2 answers

2
Tsyvarev On BEST ANSWER

How do I get cmake to compile kernel.ispc using the ispc compiler?

Just use add_custom_command:

add_custom_command(OUTPUT kernel.o
                   COMMAND ispc --target=sse2 ${CMAKE_SOURCE_DIR}/kernel.ispc -o kernel.o
                   DEPENDS kernel.ispc)

How do I get cmake to then link it into my_program?

From CMake view, .o files are just another sources for executable:

add_executable(my_program main.c kernel.o)
3
pbrubaker On

I know this is an old question, but CMAKE 3.19 now has built in support for ISPC.