<br>I have a macro which gets called to create cuda and matlab mex enabled libraries and apps.  I call this macro **twice from within a single directory** to create 2 libraries.  Problem is that I desire to set compiler defines -DWHATEVER=goop etc differently for each lib (for each of the two in question).  For instance -DCPU_RECON=yes for cpu library and -DGPU_RECON=yes for gpu library which rely on the same source code in the same directory:<br>
<br><br>-- snip - the macro --<br>macro( add_gpu_matlab_mex_library LIB_NAME )<br><br>    PARSE_CMAKE_ARGUMENTS(ARG<br>        &quot;SRCDIRS;CPP_SOURCES;CU_SOURCES;LINK_LIBS;DEFINES&quot; &quot;&quot;<br>        ${ARGN}<br>
    )<br><br>        foreach( DEFINE_STR ${ARG_DEFINES} )<br>            message( &quot;DEFINE_STR = ${DEFINE_STR}&quot; )<br>            add_definitions( -D${DEFINE_STR} )<br>        endforeach()<br>...<br>...<br><br>    if(DEFINED ARG_CU_SOURCES )<br>
        message( &quot;ARG_CU_SOURCES is defined as = ${ARG_CU_SOURCES}&quot; )<br>        CUDA_ADD_LIBRARY( ${MATLAB_CUDA_MEX_NAME} SHARED ${MATLAB_CUDA_FILES} )<br>    else()<br>        message( &quot;ARG_CU_SOURCES is not defined&quot; )<br>
       ADD_LIBRARY( ${MATLAB_CUDA_MEX_NAME} SHARED ${MATLAB_CUDA_FILES} )<br>    endif()<br>...<br>...<br>    SET_TARGET_PROPERTIES( ${MATLAB_CUDA_MEX_NAME} PROPERTIES<br>      SUFFIX .mexw64<br>       LINKER_LANGUAGE CXX <br>
       COMPILE_DEFINITIONS -DMY_DEFINE=DEFINE_THIS_GOOP<br>      LINK_FLAGS /export:mexFunction<br>      )<br>...<br>...<br>endmacro()<br><br>--end snip--<br><br>An example of using this macro in my CMakeLists.txt file<br>
<br><br>--snip--<br>add_gpu_matlab_mex_library( <br>    gpuPMatrixRecon<br>    CPP_SOURCES <br>        gpuPMatrixRecon.cpp <br>        CUDADeviceProperties.cpp<br>#    LINK_LIBS dvipGPUCUDAUtil<br>    CU_SOURCES  gpuPMatrixRecon.cu<br>
    DEFINES CUDADeviceProperties_DLLExport=yes GPU_RECON=yes<br>)<br><br>add_gpu_matlab_mex_library( <br>    cpuPMatrixRecon<br>    CPP_SOURCES <br>        gpuPMatrixRecon.cpp <br>        CUDADeviceProperties.cpp<br>#    LINK_LIBS dvipGPUCUDAUtil<br>
    CU_SOURCES  gpuPMatrixRecon.cu<br>    DEFINES CUDADeviceProperties_DLLExport=yes CPU_RECON=yes<br>#    DEFINES CUDADeviceProperties_DLLExport=yes<br><br><br>--end snip--<br><br>Both are being compiled as a cuda library as each contains the .cu file even though in the cpu version the cuda code is #ifdef&#39;ed out ... at least it should be if I could get this to work.<br>
<br>Problem comes is that using add_definitions causes the defines to be the same for each library and using set_target_properties seems to have no effect.<br><br>--snip cpu version compile output--<br>2&gt;C:/CUDA/bin64/nvcc.exe C:/projects/NIH2009/source/branches/trunk/source/Matlab/lib/3rdParty/Siemens/gpu/PMatrixRecon/gpuPMatrixRecon.cu -arch sm_11 --ptxas-options=-v -maxrregcount=32 -Xcompiler /EHsc,/W3,/nologo,/Od,/Zi,/MTd -m64 -DCUDADeviceProperties_DLLExport=yes -DGPU_RECON=yes -DgpuPMatrixRecon_EXPORTS -ccbin &quot;c:/Program<br>
--end snip --<br><br>--snip gpu version compile output--<br>2&gt;C:/CUDA/bin64/nvcc.exe C:/projects/NIH2009/source/branches/trunk/source/Matlab/lib/3rdParty/Siemens/gpu/PMatrixRecon/gpuPMatrixRecon.cu -arch sm_11 --ptxas-options=-v -maxrregcount=32 -Xcompiler /EHsc,/W3,/nologo,/Od,/Zi,/MTd -m64 -DCUDADeviceProperties_DLLExport=yes -DGPU_RECON=yes -DgpuPMatrixRecon_EXPORTS -ccbin &quot;c:/Program<br>
--end snip--<br><br>These are strangely... the same.<br><br>set_target_properties should work for a cuda library right?<br><br>add_definitions is directory global, but I can&#39;t figure out why I do not see both definitions (-DGPU_RECON=yes and -DCPU_RECON=yes) in each library.  I only see the first in the VS project for cpu version and gpu 
versions.  I also do not understand why I do not see  -DMY_DEFINE=DEFINE_THIS_GOOP from set_target_properties in either project.  <br><br><br><br>