I am on Visual Studio 2017, Windows 10, CMake 3.16.
I have a situation where I have a project that consists of cuda .cu
files that links to a c++ based upstream library via cmake. For that upstream library, the target consists of a macro, WINDOWS_DISABLE_ALL_WARNING=__pragma(warning(push,0))
, that is stored in its cmake target via INTERFACE_COMPILE_DEFINITIONS
. The main problem is nvcc is unable parse this because of the comma, I actually need to modify it to WINDOWS_DISABLE_ALL_WARNING=__pragma(warning(push\,0))
in order for it to compile, otherwise the below error message will show up
nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified
but I couldn't find a proper way to do this in cmake. Please see below minimal examples of my failed attempts
cmake_minimum_required(VERSION 3.16)
project(sample)
add_library(aaatarget aaa.cpp)
target_compile_definitions(aaatarget PUBLIC MYMACRO="aaa")
add_executable(bbbtarget bbb.cpp)
target_link_libraries(bbbtarget aaatarget)
# this works but it will mess up other targets that links to aaatarget that actually wants
# MYMACRO to be it's original aaa
set_target_properties(aaatarget PROPERTIES INTERFACE_COMPILE_DEFINITIONS MYMACRO="bbb")
# ideally I want to just change bbbtarget to make it work but none of the below works
set_target_properties(bbbtarget PROPERTIES INTERFACE_COMPILE_DEFINITIONS MYMACRO="bbb")
set_target_properties(bbbtarget PROPERTIES INTERFACE_COMPILE_OPTIONS MYMACRO="bbb")
set_target_properties(bbbtarget PROPERTIES COMPILE_DEFINITIONS MYMACRO="bbb")
set_target_properties(bbbtarget PROPERTIES COMPILE_OPTIONS MYMACRO="bbb")
# this has the potential to solve it for my specific use case but unfortunately COMPILE_LANGUAGE
# doesn't work on visual studio... otherwise, I could request the upstream vendor to make this change
target_compile_definitions(aaatarget PUBLIC "$<$<COMPILE_LANGUAGE:CXX>:MYMACRO=\"aaa\"")
Can someone tell me how to link to a target in CMake but partially modify some properties locally? Best solution is NVIDIA fix nvcc so it can parse the comma correctly just like cl but it will be great to have a workaround now before that happen.