cmake: Target-specific preprocessor definitions for CUDA targets seems not to work
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 defi开发者_Python百科nition 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..
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)
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.
精彩评论