[CMake] add_definitions: if option contains space and using FindCUDA, it won't get added to compiler call
xyzdragon at fastmail.fm
xyzdragon at fastmail.fm
Thu Mar 24 07:59:48 EDT 2016
Here is a minimal working-example without FindCUDA:
main.cpp:
int main(void){ return 0; }
CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
add_definitions( "-D USE_FEATURE" )
add_library( mimi main.cpp )
target_link_libraries( mimi )
the output will be:
/usr/bin/g++-4.9 -D USE_FEATURE -o CMakeFiles/mimi.dir/main.cpp.o -c
~/cmakeBug/main.cpp
Meaning the option has been correctly added. Note that the space after
`-D` is allowed and completely fine.
Now the CMakeLists.txt with FindCUDA:
cmake_minimum_required(VERSION 3.5)
find_package( CUDA )
add_definitions( "-D USE_FEATURE" )
add_definitions( "-DUSE_FEATURE2" )
SET_SOURCE_FILES_PROPERTIES( main.cpp PROPERTIES
CUDA_SOURCE_PROPERTY_FORMAT OBJ )
cuda_add_library( mimi main.cpp )
target_link_libraries( mimi )
The compile command produced now is:
/usr/bin/nvcc ~/cmakeBug/main.cpp -x=cu -c -o
~/cmakeBug/build/CMakeFiles/mimi.dir//./mimi_generated_main.cpp.o
-ccbin /usr/bin/gcc-4.9 -m64 -DUSE_FEATURE2 -Xcompiler ,\"-g\"
-DNVCC -I/usr/include -I/usr/include
Meaning `-D USE_FEATURE` was silently ignored (resulting in me wondering
for many hours why it just won't work), but `-DUSE_FEATURE2` has been
added correctly.
Note that I also had a similar problem when trying to (admittedly rather
clumsily) adding multiple options:
add_definitions( "-DUSE_FEATURE ${FFTW_DEFINITIONS}" )
add_definitions( "-DUSE_FEATURE" ${FFTW_DEFINITIONS} )
The first version will be completely ignored, but the second version
works fine. I highly think that this is because of the space in the
middle.
I found this bug, because I want to do `add_definitions( "-isystem
/user_system_library" )` in order to implement a workaround for this
bug: https://cmake.org/Bug/view.php?id=14415
Another problem is, that findCUDA ignores all definitions which don't
begin with `-D` I think. at least `add_definition("-isystem/mimi")` will
be ignored. This means I can't test, what happens with paths containing
spaces.
--
http://www.fastmail.com - Or how I learned to stop worrying and
love email again
More information about the CMake
mailing list