tags:

views:

290

answers:

2

I'm using cmake 2.8.1 on Mac OSX 10.6 with CUDA 3.0.

So I added a CUDA target which needs BLOCK_SIZE set to some number in order to compile.

cuda_add_executable(SimpleTestsCUDA
                    SimpleTests.cu
                    BlockMatrix.cpp 
                    Matrix.cpp
)

set_target_properties(SimpleTestsCUDA PROPERTIES COMPILE_FLAGS -DBLOCK_SIZE=3)

When running make VERBOSE=1 I noticed that nvcc is invoked w/o -DBLOCK_SIZE=3, which results in an error, because BLOCK_SIZE is used in the code, but defined nowhere. Now I used the same definition for a CPU target (using add_executable(...)) and there it worked.

So now the questions: How do I figure out what cmake does with the set_target_properties line if it points to a CUDA target? Googling around didn't help so far and a workaround would be cool..

+1  A: 

I think the best way to do this is by adding "OPTIONS -DBLOCK_SIZE=3" to cuda_add_executable. So your line would look like this:

cuda_add_executable(SimpleTestsCUDA
                SimpleTests.cu
                BlockMatrix.cpp 
                Matrix.cpp
                OPTIONS -DBLOCK_SIZE=3
)

Or you can set it before cuda_add_executable:

SET(CUDA_NVCC_FLAGS -DBLOCK_SIZE=3)
Maurice Gilden
thank you, seems to work for now. Maybe I should report this as a bug?
Nils
SET(CUDA_NVCC_FLAGS -DBLOCK_SIZE=3) This is then the same for all targets, you cannot reset it using set; it will take the latest for all targets.OPTIONS -DBLOCK_SIZE=3 seems to work with cuda targets but not with normal ones..I think I get a headache.. :(
Nils
OPTIONS is only available with cuda_add_executable, for add_executable you should probably use set_target_properties.
Maurice Gilden
A: 

The only workaround I found so far is using remove_definitions:

remove_definitions(-DBLOCK_SIZE=3)
add_definitions(-DBLOCK_SIZE=32)

Doing this before a target seems to help.

Nils