Commit cedcaaf9 authored by Jan Möbius's avatar Jan Möbius
Browse files

Cuda support in plugins

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@11711 383ad7c9-94d9-4d36-a494-682f7c89f535
parent e23185bb
......@@ -34,6 +34,17 @@
# unneeded headers, sources and ui files from the autogenerated
# build sources lists (see common.cmake drop_templates macro)
#
# Translations
# Create a subdirectory called translations in your Plugin directory
# The *.ts files there will be used for the translations
#
# Special DEPS:
# CUDA:
# If your plugin requires cuda, add "CUDA" to the list of dependencies
# and create a subdir called Cuda in your plugin directory
# The files in this directory will be compiled by nvcc and linked
# into the plugin
#
include (ACGCommon)
......@@ -331,62 +342,13 @@ function (_build_openflipper_plugin plugin)
acg_qt4_autoqrc (qrc_targets ${qrc})
add_library (Plugin-${plugin} MODULE ${uic_targets} ${sources} ${headers} ${moc_targets} ${qrc_targets} ${${_PLUGIN}_ADDSRC})
# Check if cuda is in the list of dependencies:
list(FIND ${_PLUGIN}_DEPS "CUDA" FIND_RESULT)
if ( NOT FIND_RESULT EQUAL -1 )
message(status " CUDA REQUIRED!")
# Required but maybe it is not found
# finder is automatically called before this
if ( CUDA_FOUND )
#Setup options
CUDA_ADD_CUDA_INCLUDE_ONCE()
# Clear out the directory defines to prevent nvcc from getting them
# TODO : Create an additional flag variable for CUDA
get_directory_property( CURRENT_DEFINITIONS COMPILE_DEFINITIONS )
set_directory_properties( PROPERTIES COMPILE_DEFINITIONS "" )
get_directory_property( CURRENT_DEFINITIONS_A COMPILE_DEFINITIONS )
# Get all cuda sources
file(GLOB_RECURSE ${_PLUGIN}_CUDA_SRCS Cuda/*.cu Cuda/*.c Cuda/*.cc Cuda/*.cpp Cuda/*.h Cuda/*.hh)
CUDA_COMPILE(${_PLUGIN}_CUDA_GENERATED_FILES ${${_PLUGIN}_CUDA_SRCS})
CUDA_ADD_LIBRARY(${_PLUGIN}_cuda_lib ${${_PLUGIN}_CUDA_GENERATED_FILES})
target_link_libraries(Plugin-${plugin} ${_PLUGIN}_cuda_lib)
endif( CUDA_FOUND )
endif()
# Add the library.
#add_library(${cuda_target} ${_cmake_options}
# ${_generated_files}
# ${_sources}
# )
#target_link_libraries(${cuda_target}
# ${CUDA_LIBRARIES}
# )
# We need to set the linker language based on what the expected generated file
# would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP.
#set_target_properties(${cuda_target}
# PROPERTIES
# LINKER_LANGUAGE ${CUDA_C_OR_CXX}
# )
add_library (Plugin-${plugin} MODULE ${uic_targets} ${sources} ${headers} ${moc_targets} ${qrc_targets} ${${_PLUGIN}_ADDSRC})
# add this plugin to build plugin list for dependency tracking
acg_set (OPENFLIPPER_PLUGINS "${OPENFLIPPER_PLUGINS};Plugin-${plugin}")
acg_set (OPENFLIPPER_${_PLUGIN}_BUILD "1")
#
# append compiler and linker flags from plugin dependencies
set_target_properties (
Plugin-${plugin} PROPERTIES
......@@ -465,6 +427,57 @@ function (_build_openflipper_plugin plugin)
endif ()
endforeach ()
#============================================================================================
# CUDA Integration
# This block takes all cuda files from a plugins subdirectory called "Cuda"
# The files will be compiled by nvcc and linked to one library containing all cuda parts of
# the plugin. This static library is than linked into the plugin
#============================================================================================
# Check if cuda is in the list of dependencies:
list(FIND ${_PLUGIN}_DEPS "CUDA" FIND_RESULT)
if ( NOT FIND_RESULT EQUAL -1 )
message(status " CUDA REQUIRED!")
# Required but maybe it is not found
# finder is automatically called before this
if ( CUDA_FOUND )
#Setup options
CUDA_ADD_CUDA_INCLUDE_ONCE()
# Clear out the directory defines to prevent nvcc from getting them
# TODO : Create an additional flag variable for CUDA
get_directory_property( CURRENT_DEFINITIONS COMPILE_DEFINITIONS )
set_directory_properties( PROPERTIES COMPILE_DEFINITIONS "" )
get_directory_property( CURRENT_DEFINITIONS_A COMPILE_DEFINITIONS )
# Get all cuda sources
file(GLOB_RECURSE ${_PLUGIN}_CUDA_SRCS Cuda/*.cu Cuda/*.c Cuda/*.cc Cuda/*.cpp Cuda/*.h Cuda/*.hh)
# Force to -fPIC such that we can correctly link against the lib lateron in the plugin
list ( APPEND CMAKE_CXX_FLAGS "-fPIC" )
list ( APPEND CMAKE_CC_FLAGS "-fPIC" )
# Prepare the files
CUDA_COMPILE(${_PLUGIN}_CUDA_GENERATED_FILES ${${_PLUGIN}_CUDA_SRCS})
# Create the library containing all cuda files
CUDA_ADD_LIBRARY(${_PLUGIN}_cuda_lib STATIC ${${_PLUGIN}_CUDA_GENERATED_FILES} )
# Link the cuda plugin library to the plugin itself
target_link_libraries(Plugin-${plugin} ${_PLUGIN}_cuda_lib)
# reset to original compile definitions
set_directory_properties( PROPERTIES COMPILE_DEFINITIONS ${CURRENT_DEFINITIONS} )
endif( CUDA_FOUND )
endif()
#============================================================================================
# Translations
#============================================================================================
if ( ${_PLUGIN}_TRANSLATION_LANGUAGES)
set (trans_files ${sources} )
list (APPEND trans_files ${ui})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment