[CMake] Setting compile defs with: Cuda, add_subdirectory, and set_target_properties (COMPILE_DEFINITIONS)
Brian Davis
bitminer at gmail.com
Wed Jul 14 11:55:24 EDT 2010
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:
-- snip - the macro --
macro( add_gpu_matlab_mex_library LIB_NAME )
PARSE_CMAKE_ARGUMENTS(ARG
"SRCDIRS;CPP_SOURCES;CU_SOURCES;LINK_LIBS;DEFINES" ""
${ARGN}
)
foreach( DEFINE_STR ${ARG_DEFINES} )
message( "DEFINE_STR = ${DEFINE_STR}" )
add_definitions( -D${DEFINE_STR} )
endforeach()
...
...
if(DEFINED ARG_CU_SOURCES )
message( "ARG_CU_SOURCES is defined as = ${ARG_CU_SOURCES}" )
CUDA_ADD_LIBRARY( ${MATLAB_CUDA_MEX_NAME} SHARED
${MATLAB_CUDA_FILES} )
else()
message( "ARG_CU_SOURCES is not defined" )
ADD_LIBRARY( ${MATLAB_CUDA_MEX_NAME} SHARED ${MATLAB_CUDA_FILES} )
endif()
...
...
SET_TARGET_PROPERTIES( ${MATLAB_CUDA_MEX_NAME} PROPERTIES
SUFFIX .mexw64
LINKER_LANGUAGE CXX
COMPILE_DEFINITIONS -DMY_DEFINE=DEFINE_THIS_GOOP
LINK_FLAGS /export:mexFunction
)
...
...
endmacro()
--end snip--
An example of using this macro in my CMakeLists.txt file
--snip--
add_gpu_matlab_mex_library(
gpuPMatrixRecon
CPP_SOURCES
gpuPMatrixRecon.cpp
CUDADeviceProperties.cpp
# LINK_LIBS dvipGPUCUDAUtil
CU_SOURCES gpuPMatrixRecon.cu
DEFINES CUDADeviceProperties_DLLExport=yes GPU_RECON=yes
)
add_gpu_matlab_mex_library(
cpuPMatrixRecon
CPP_SOURCES
gpuPMatrixRecon.cpp
CUDADeviceProperties.cpp
# LINK_LIBS dvipGPUCUDAUtil
CU_SOURCES gpuPMatrixRecon.cu
DEFINES CUDADeviceProperties_DLLExport=yes CPU_RECON=yes
# DEFINES CUDADeviceProperties_DLLExport=yes
--end snip--
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'ed out ... at least it
should be if I could get this to work.
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.
--snip cpu version compile output--
2>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 "c:/Program
--end snip --
--snip gpu version compile output--
2>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 "c:/Program
--end snip--
These are strangely... the same.
set_target_properties should work for a cuda library right?
add_definitions is directory global, but I can'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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100714/010331ca/attachment-0001.htm>
More information about the CMake
mailing list