3

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?

Royi
  • 4,640
  • 6
  • 46
  • 64
JodiTheTigger
  • 415
  • 5
  • 7
  • What is wrong with [add_custom_command](https://cmake.org/cmake/help/v3.7/command/add_custom_command.html)? – Tsyvarev Feb 14 '17 at 21:52
  • I cannot find an example that shows how to use it for this case. 1) how do I use custom command to build any ispc file to a .o file? 2) how do I then make the executable depend and use those .o files when linking? – JodiTheTigger Feb 14 '17 at 22:58

2 Answers2

5

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)
Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • Yup, that works. Just need to change the command line to: `COMMAND ispc --target=sse2 ${CMAKE_SOURCE_DIR}\kernel.ispc -o kernel.o` as it doesn't find the file otherwise. – JodiTheTigger Feb 15 '17 at 20:18
  • Yes, the COMMAND is executed in binary directory, that is why it cannot find file in source directory. I have fixed the answer. – Tsyvarev Feb 15 '17 at 21:09
0

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

pbrubaker
  • 51
  • 5
  • 1
    Is there any example? – Jinesi Yelizati Jun 27 '22 at 06:58
  • This is probably the best resource - He points out some issues with 3.19's support for ISPC. I don't use CMAKE, I use Premake. But I will ask if anyone else has used the cmake support. I think we may use it for building the examples in the compiler. https://risaksson.com/post/1/2022-04-15/ISPC-and-Integrating-ISPC-Into-CMake-Projects – pbrubaker Jun 28 '22 at 13:16
  • BTW a faster wat to get ahold of us is to message us on Twitter @ pbruabker or @ ispc_updates. – pbrubaker Jun 28 '22 at 13:18