Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cuda_add_library and cuda_add_executable if cuda is found #576

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions Common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ include(CommonCompiler)
include(CommonCoverage)
include(CommonCPackUtils)
include(CommonSmokeTest)
if (NOT ${PROJECT_NAME}_IGNORE_GIT)
include(GitInfo)
include(GitTargets)
include(GitHooks)
include(ProjectInfo)
endif()

if(INSTALL_PACKAGES)
include(InstallDependencies)
Expand Down
11 changes: 9 additions & 2 deletions CommonApplication.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,15 @@ function(common_application Name)
endif()
endif()

add_executable(${Name} ${_options} ${_icon} ${_desktop} ${_headers}
${_sources})
source_group(TREE ${PROJECT_SOURCE_DIR} FILES ${_sources} ${_headers})

if (CUDA_FOUND AND ${NAME}_USE_CUDA)
cuda_add_executable(${Name} ${_options} ${_icon} ${_desktop} ${_headers}
${_sources})
else()
add_executable(${Name} ${_options} ${_icon} ${_desktop} ${_headers}
${_sources})
endif()
set_target_properties(${Name} PROPERTIES FOLDER ${PROJECT_NAME})
common_compile_options(${Name})
add_dependencies(${PROJECT_NAME}-all ${Name})
Expand Down
10 changes: 6 additions & 4 deletions CommonCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# CMake options:
# * COMMON_WARN_DEPRECATED: Enable compiler deprecation warnings, default ON
# * COMMON_ENABLE_CXX11_STDLIB: Enable C++11 stdlib, default OFF
# * COMMON_DISABLE_WERROR: Disable -Werror flags, default OFF
# * COMMON_DISABLE_WERROR: Disable -Werror flags, default ON
# * COMMON_ENABLE_CXX11_ABI: Enable C++11 ABI for gcc 5 or later, default ON,
# can be set to OFF with env variable CMAKE_COMMON_USE_CXX03_ABI
#
Expand Down Expand Up @@ -46,7 +46,7 @@ endif()

option(COMMON_WARN_DEPRECATED "Enable compiler deprecation warnings" ON)
option(COMMON_ENABLE_CXX11_STDLIB "Enable C++11 stdlib" OFF)
option(COMMON_DISABLE_WERROR "Disable -Werror flag" OFF)
option(COMMON_DISABLE_WERROR "Disable -Werror flag" ON)
if($ENV{CMAKE_COMMON_USE_CXX03_ABI}) # set by viz/env module
option(COMMON_ENABLE_CXX11_ABI "Enable C++11 ABI for gcc 5 or later" OFF)
else()
Expand Down Expand Up @@ -162,9 +162,11 @@ elseif(MSVC)
# http://www.ogre3d.org/forums/viewtopic.php?f=2&t=60015&start=0
set(COMMON_CXX_FLAGS /DWIN32 /D_WINDOWS /W3 /Zm500 /EHsc /GR
/D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS
/W0
)
set(COMMON_CXX_FLAGS_DEBUG /WX)

if (NOT COMMON_DISABLE_WERROR)
set(COMMON_CXX_FLAGS /WX)
endif()
else()
message(FATAL_ERROR "Unknown/unsupported compiler ${CMAKE_CXX_COMPILER_ID}")
endif()
Expand Down
18 changes: 11 additions & 7 deletions CommonLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
include(CommonCheckTargets)
include(InstallFiles)

set(COMMON_LIBRARY_TYPE SHARED CACHE STRING
set(COMMON_LIBRARY_TYPE STATIC CACHE STRING
"Library type {any combination of SHARED, STATIC}")
set_property(CACHE COMMON_LIBRARY_TYPE PROPERTY STRINGS SHARED STATIC)

Expand Down Expand Up @@ -87,8 +87,7 @@ function(common_library Name)
list(SORT PUBLIC_HEADERS)
endif()

source_group(\\ FILES CMakeLists.txt)
source_group(${INCLUDE_NAME} FILES ${SOURCES} ${HEADERS} ${PUBLIC_HEADERS})
source_group(TREE ${PROJECT_SOURCE_DIR} FILES ${SOURCES} ${HEADERS} ${PUBLIC_HEADERS})

if(NOT ${NAME}_LIBRARY_TYPE)
set(${NAME}_LIBRARY_TYPE ${COMMON_LIBRARY_TYPE})
Expand All @@ -103,14 +102,19 @@ function(common_library Name)
endif()

if(NOT ${NAME}_SOURCES)
add_library(${LibName} INTERFACE)
add_library(${LibName} INTERFACE)
_target_include_directories(INTERFACE)
else()
# append a debug suffix to library name on windows or if user requests it
common_set_lib_name_postfix()

add_library(${LibName} ${LIBRARY_TYPE}
${SOURCES} ${HEADERS} ${PUBLIC_HEADERS})
if (CUDA_FOUND AND ${NAME}_USE_CUDA)
cuda_add_library(${LibName} ${LIBRARY_TYPE}
${SOURCES} ${HEADERS} ${PUBLIC_HEADERS})
else()
add_library(${LibName} ${LIBRARY_TYPE}
${SOURCES} ${HEADERS} ${PUBLIC_HEADERS})
endif()
set_target_properties(${LibName} PROPERTIES
VERSION ${${PROJECT_NAME}_VERSION}
SOVERSION ${${PROJECT_NAME}_VERSION_ABI}
Expand All @@ -132,7 +136,7 @@ function(common_library Name)
# add an alias with PROJECT_NAME to the target to ease detection of
# subproject inclusion in CommonConfig.cmake
if(NOT TARGET ${PROJECT_NAME}_ALIAS)
add_library(${PROJECT_NAME}_ALIAS ALIAS ${LibName})
add_library(${PROJECT_NAME}_ALIAS ALIAS ${LibName})
endif()

if(NOT ${NAME}_OMIT_INSTALL)
Expand Down