From 9f0bd78860e4ea32c570b1ffdbfca8845948a2b7 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Thu, 29 Sep 2016 14:06:07 -0400 Subject: [PATCH] Add C++11 flags to sub-projects Recently VTK-m was changed to require C++11. The internal builds set properties to require C++11, but these never make it to the configuration for projects that use the VTK-m package (i.e. not declared in VTKmConfig.cmake). This change adds a new CMake target, vtkm, which is an interface. It does not point to an actual library, but it allows code that links it in to have the appropriate compile flags. --- CMake/VTKmConfigureComponents.cmake | 8 +++++- CMake/VTKmMacros.cmake | 2 -- CMakeLists.txt | 44 ++++++++++++++--------------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/CMake/VTKmConfigureComponents.cmake b/CMake/VTKmConfigureComponents.cmake index a93d3ff1b..1be321042 100644 --- a/CMake/VTKmConfigureComponents.cmake +++ b/CMake/VTKmConfigureComponents.cmake @@ -107,9 +107,15 @@ macro(vtkm_configure_component_Base) include(VTKmCompilerOptimizations) endif() + # Check for the existance of the base vtkm target + if (TARGET vtkm) + set(VTKm_base_vtkm_target_FOUND True) + endif() + vtkm_finish_configure_component(Base - DEPENDENT_VARIABLES Boost_FOUND + DEPENDENT_VARIABLES Boost_FOUND VTKm_base_vtkm_target_FOUND ADD_INCLUDES ${Boost_INCLUDE_DIRS} + ADD_LIBRARIES vtkm ) endmacro() diff --git a/CMake/VTKmMacros.cmake b/CMake/VTKmMacros.cmake index 95dbabbd5..22e77dd80 100755 --- a/CMake/VTKmMacros.cmake +++ b/CMake/VTKmMacros.cmake @@ -584,7 +584,6 @@ function(vtkm_wrap_sources_for_cuda cuda_source_list_var) set(${cuda_source_list_var} ${cuda_sources} PARENT_SCOPE) endfunction(vtkm_wrap_sources_for_cuda) -set(VTKM_HAS_AT_LEAST_ONE_LIBRARY FALSE CACHE INTERNAL "" FORCE) # Add a VTK-m library. The name of the library will match the "kit" name # (e.g. vtkm_rendering) unless the NAME argument is given. # @@ -676,7 +675,6 @@ function(vtkm_library) vtkm_install_headers("${dir_prefix}" ${CMAKE_BINARY_DIR}/${VTKm_INSTALL_INCLUDE_DIR}/${dir_prefix}/${lib_name}_export.h ) - set(VTKM_HAS_AT_LEAST_ONE_LIBRARY TRUE CACHE INTERNAL "" FORCE) endfunction(vtkm_library) # The Thrust project is not as careful as the VTKm project in avoiding warnings diff --git a/CMakeLists.txt b/CMakeLists.txt index a8e4b921c..bb372b3b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,17 @@ set(VTKm_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} ) +# Create an "interface" target library. This is not a real library but rather +# holds CMake configuration that is required for CXX targets that use VTK-m +# headers. In particular, it makes sure the appropriate C++11 version is being +# used. (The cxx_constexpr and cxx_auto_type features happen to force C++11. +# Directly asking for C++11 with this interface is not supported in CMake 3.3.) +# This is also exported so that dependent CMake projects can load the same +# configuration. +add_library(vtkm INTERFACE) +target_compile_features(vtkm INTERFACE cxx_constexpr cxx_auto_type) +install(TARGETS vtkm EXPORT ${VTKm_EXPORT_NAME}) + # Load the base VTK-m configuration, which is required for some of the later # config. vtkm_configure_component_Base() @@ -61,13 +72,9 @@ if(NOT VTKm_Base_FOUND) endif() #----------------------------------------------------------------------------- -# Add flag to enable C++11 support. -# Unless the user has explicitly stated to compile with a different standard -if (NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 11) - set(CMAKE_CXX_STANDARD_REQUIRED True) - set(CMAKE_CXX_EXTENSIONS False) -endif() +# When using C++11 suport make sure you use the standard C++ extensions rather +# than compiler-specific versions of the extensions (to preserve portability). +set(CMAKE_CXX_EXTENSIONS False) #----------------------------------------------------------------------------- # Add supplemental compiler warnings, and GCC visibility support. @@ -318,22 +325,13 @@ install( ) # Create and install exports for external projects -if(${VTKM_HAS_AT_LEAST_ONE_LIBRARY}) - export(EXPORT ${VTKm_EXPORT_NAME} - FILE ${CMAKE_BINARY_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmTargets.cmake - ) - install(EXPORT ${VTKm_EXPORT_NAME} - DESTINATION ${VTKm_INSTALL_LIB_DIR} - FILE VTKmTargets.cmake - ) -else() # No libraries built - file(WRITE ${CMAKE_BINARY_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmTargets.cmake - "# This build of VTK-m has no libraries to export targets for" - ) - install(FILES ${CMAKE_BINARY_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmTargets.cmake - DESTINATION ${VTKm_INSTALL_LIB_DIR} - ) -endif() +export(EXPORT ${VTKm_EXPORT_NAME} + FILE ${CMAKE_BINARY_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmTargets.cmake + ) +install(EXPORT ${VTKm_EXPORT_NAME} + DESTINATION ${VTKm_INSTALL_LIB_DIR} + FILE VTKmTargets.cmake + ) # Enable CPack packaging set(CPACK_PACKAGE_DESCRIPTION_FILE ${VTKm_SOURCE_DIR}/README.md)