From 9f0e31b3362082ac7026fa348f895aecf852880e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Casafranca?= Date: Sat, 13 Jan 2018 17:29:23 +0100 Subject: [PATCH 1/9] Use cuda_add_library and cuda_add_executable if cuda is found --- CommonApplication.cmake | 11 ++++++++--- CommonLibrary.cmake | 21 +++++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/CommonApplication.cmake b/CommonApplication.cmake index 5442802..c81f8d6 100644 --- a/CommonApplication.cmake +++ b/CommonApplication.cmake @@ -76,9 +76,14 @@ function(common_application Name) set(_icon ${_icon_file_candidate}) endif() endif() - - add_executable(${Name} ${_options} ${_icon} ${_desktop} ${_headers} - ${_sources}) + + if (${CUDA_FOUND}) + 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}) diff --git a/CommonLibrary.cmake b/CommonLibrary.cmake index f21ccc4..c4801e0 100644 --- a/CommonLibrary.cmake +++ b/CommonLibrary.cmake @@ -103,14 +103,23 @@ function(common_library Name) endif() if(NOT ${NAME}_SOURCES) - add_library(${LibName} INTERFACE) + if (${CUDA_FOUND}) + cuda_add_library(${LibName} INTERFACE) + else() + add_library(${LibName} INTERFACE) + endif() _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}) + 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} @@ -132,7 +141,11 @@ 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}) + if (${CUDA_FOUND}) + cuda_add_library(${PROJECT_NAME}_ALIAS ALIAS ${LibName}) + else() + add_library(${PROJECT_NAME}_ALIAS ALIAS ${LibName}) + endif() endif() if(NOT ${NAME}_OMIT_INSTALL) From 70dae973a3903f03bb287c333ad5ae53c4802455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Casafranca?= Date: Mon, 15 Jan 2018 19:09:24 +0100 Subject: [PATCH 2/9] Fix CommonLibrary removing cuda_add_library for the alias --- CommonLibrary.cmake | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CommonLibrary.cmake b/CommonLibrary.cmake index c4801e0..96e8b01 100644 --- a/CommonLibrary.cmake +++ b/CommonLibrary.cmake @@ -141,11 +141,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) - if (${CUDA_FOUND}) - cuda_add_library(${PROJECT_NAME}_ALIAS ALIAS ${LibName}) - else() add_library(${PROJECT_NAME}_ALIAS ALIAS ${LibName}) - endif() endif() if(NOT ${NAME}_OMIT_INSTALL) From e701e28eced9bfdf8ac42796c3ad50a5458b318b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Casafranca?= Date: Tue, 16 Jan 2018 15:10:57 +0100 Subject: [PATCH 3/9] Change library default type to static and disable werror --- CommonCompiler.cmake | 4 ++-- CommonLibrary.cmake | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CommonCompiler.cmake b/CommonCompiler.cmake index fec016b..439a728 100644 --- a/CommonCompiler.cmake +++ b/CommonCompiler.cmake @@ -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 # @@ -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() diff --git a/CommonLibrary.cmake b/CommonLibrary.cmake index 96e8b01..541e67c 100644 --- a/CommonLibrary.cmake +++ b/CommonLibrary.cmake @@ -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) From bb1164c678f0f796f39ae526e1b5b8441c7aa583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Casafranca?= Date: Tue, 16 Jan 2018 18:11:25 +0100 Subject: [PATCH 4/9] Targets now can decide to compile with CUDA or not --- CommonApplication.cmake | 2 +- CommonLibrary.cmake | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CommonApplication.cmake b/CommonApplication.cmake index c81f8d6..e216b36 100644 --- a/CommonApplication.cmake +++ b/CommonApplication.cmake @@ -77,7 +77,7 @@ function(common_application Name) endif() endif() - if (${CUDA_FOUND}) + if (${CUDA_FOUND} AND ${NAME}_USE_CUDA) cuda_add_executable(${Name} ${_options} ${_icon} ${_desktop} ${_headers} ${_sources}) else() diff --git a/CommonLibrary.cmake b/CommonLibrary.cmake index 541e67c..355b1bc 100644 --- a/CommonLibrary.cmake +++ b/CommonLibrary.cmake @@ -103,7 +103,7 @@ function(common_library Name) endif() if(NOT ${NAME}_SOURCES) - if (${CUDA_FOUND}) + if (${CUDA_FOUND} AND ${NAME}_USE_CUDA) cuda_add_library(${LibName} INTERFACE) else() add_library(${LibName} INTERFACE) @@ -113,7 +113,7 @@ function(common_library Name) # append a debug suffix to library name on windows or if user requests it common_set_lib_name_postfix() - if (${CUDA_FOUND}) + if (${CUDA_FOUND} AND ${NAME}_USE_CUDA) cuda_add_library(${LibName} ${LIBRARY_TYPE} ${SOURCES} ${HEADERS} ${PUBLIC_HEADERS}) else() From 95c058bc3f7dd6db37b207ad9fa2b0ff0a4c774b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Casafranca?= Date: Wed, 17 Jan 2018 00:16:06 +0100 Subject: [PATCH 5/9] Enable COMMON_DISABLE_WERROR MSVC handle --- CommonCompiler.cmake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CommonCompiler.cmake b/CommonCompiler.cmake index 439a728..995fa8e 100644 --- a/CommonCompiler.cmake +++ b/CommonCompiler.cmake @@ -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() From d072eff34dacd35ebb9016a925f9730f3096b99b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Casafranca?= Date: Wed, 17 Jan 2018 21:03:03 +0100 Subject: [PATCH 6/9] Fix check of cuda in application and library --- CommonApplication.cmake | 2 +- CommonLibrary.cmake | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CommonApplication.cmake b/CommonApplication.cmake index e216b36..a474c7f 100644 --- a/CommonApplication.cmake +++ b/CommonApplication.cmake @@ -77,7 +77,7 @@ function(common_application Name) endif() endif() - if (${CUDA_FOUND} AND ${NAME}_USE_CUDA) + if (CUDA_FOUND AND ${NAME}_USE_CUDA) cuda_add_executable(${Name} ${_options} ${_icon} ${_desktop} ${_headers} ${_sources}) else() diff --git a/CommonLibrary.cmake b/CommonLibrary.cmake index 355b1bc..133fac0 100644 --- a/CommonLibrary.cmake +++ b/CommonLibrary.cmake @@ -103,7 +103,7 @@ function(common_library Name) endif() if(NOT ${NAME}_SOURCES) - if (${CUDA_FOUND} AND ${NAME}_USE_CUDA) + if (CUDA_FOUND AND ${NAME}_USE_CUDA) cuda_add_library(${LibName} INTERFACE) else() add_library(${LibName} INTERFACE) @@ -113,7 +113,7 @@ function(common_library Name) # append a debug suffix to library name on windows or if user requests it common_set_lib_name_postfix() - if (${CUDA_FOUND} AND ${NAME}_USE_CUDA) + if (CUDA_FOUND AND ${NAME}_USE_CUDA) cuda_add_library(${LibName} ${LIBRARY_TYPE} ${SOURCES} ${HEADERS} ${PUBLIC_HEADERS}) else() From b7cb0bb1c884048b190a26990ea9ce0dbcdd6580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Casafranca?= Date: Thu, 18 Jan 2018 12:19:03 +0100 Subject: [PATCH 7/9] Source group for application and library Disable git targets on option --- Common.cmake | 2 ++ CommonApplication.cmake | 2 ++ CommonLibrary.cmake | 1 + 3 files changed, 5 insertions(+) diff --git a/Common.cmake b/Common.cmake index 6e8d39d..cdcf07a 100644 --- a/Common.cmake +++ b/Common.cmake @@ -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) diff --git a/CommonApplication.cmake b/CommonApplication.cmake index a474c7f..73894d5 100644 --- a/CommonApplication.cmake +++ b/CommonApplication.cmake @@ -76,6 +76,8 @@ function(common_application Name) set(_icon ${_icon_file_candidate}) endif() endif() + + source_group(TREE ${PROJECT_SOURCE_DIR} FILES ${_sources} ${_headers}) if (CUDA_FOUND AND ${NAME}_USE_CUDA) cuda_add_executable(${Name} ${_options} ${_icon} ${_desktop} ${_headers} diff --git a/CommonLibrary.cmake b/CommonLibrary.cmake index 133fac0..04b8e48 100644 --- a/CommonLibrary.cmake +++ b/CommonLibrary.cmake @@ -89,6 +89,7 @@ function(common_library Name) 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}) From 06e05ab0ec941b1d5aa627fff204b321ff2bb446 Mon Sep 17 00:00:00 2001 From: Juan Jose Casafranca Date: Mon, 22 Jan 2018 13:20:06 +0100 Subject: [PATCH 8/9] set source tree for commonlibrary --- CommonLibrary.cmake | 2 -- 1 file changed, 2 deletions(-) diff --git a/CommonLibrary.cmake b/CommonLibrary.cmake index 04b8e48..b6d4abb 100644 --- a/CommonLibrary.cmake +++ b/CommonLibrary.cmake @@ -87,8 +87,6 @@ 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) From 7e1271692ac0740e75b4a0c4d838fc1ba58b5e21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Casafranca?= Date: Mon, 22 Jan 2018 18:39:16 +0100 Subject: [PATCH 9/9] source group for visual. Remove cuda for interfaces targets --- CommonLibrary.cmake | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CommonLibrary.cmake b/CommonLibrary.cmake index 04b8e48..f7df7c9 100644 --- a/CommonLibrary.cmake +++ b/CommonLibrary.cmake @@ -87,8 +87,6 @@ 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) @@ -104,11 +102,7 @@ function(common_library Name) endif() if(NOT ${NAME}_SOURCES) - if (CUDA_FOUND AND ${NAME}_USE_CUDA) - cuda_add_library(${LibName} INTERFACE) - else() add_library(${LibName} INTERFACE) - endif() _target_include_directories(INTERFACE) else() # append a debug suffix to library name on windows or if user requests it