diff --git a/cmake/vecmem-compiler-options-cpp.cmake b/cmake/vecmem-compiler-options-cpp.cmake index 4373c3d6..6a0432be 100644 --- a/cmake/vecmem-compiler-options-cpp.cmake +++ b/cmake/vecmem-compiler-options-cpp.cmake @@ -10,6 +10,11 @@ include( vecmem-functions ) # Set up the used C++ standard(s). set( CMAKE_CXX_STANDARD 17 CACHE STRING "The (host) C++ standard to use" ) +# Turn on the correct setting for the __cplusplus macro with MSVC. +if( "${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC" ) + vecmem_add_flag( CMAKE_CXX_FLAGS "/Zc:__cplusplus" ) +endif() + # Turn on a number of warnings for the "known compilers". if( ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" ) OR ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ) diff --git a/cmake/vecmem-functions.cmake b/cmake/vecmem-functions.cmake index 6f88cc56..6f13d470 100644 --- a/cmake/vecmem-functions.cmake +++ b/cmake/vecmem-functions.cmake @@ -12,13 +12,17 @@ include( CMakeParseArguments ) # Helper function for setting up the VecMem libraries. # -# Usage: vecmem_add_library( vecmem_core core SHARED +# Usage: vecmem_add_library( vecmem_core core +# [TYPE SHARED/STATIC] # include/source1.hpp source2.cpp ) # -function( vecmem_add_library fullname basename type ) +function( vecmem_add_library fullname basename ) + + # Parse the function's options. + cmake_parse_arguments( ARG "" "TYPE" "" ${ARGN} ) # Create the library. - add_library( ${fullname} ${type} ${ARGN} ) + add_library( ${fullname} ${ARG_TYPE} ${ARG_UNPARSED_ARGUMENTS} ) # Set up how clients should find its headers. target_include_directories( ${fullname} PUBLIC diff --git a/cmake/vecmem-googletest.cmake b/cmake/vecmem-googletest.cmake index 61f9ba65..673568c9 100644 --- a/cmake/vecmem-googletest.cmake +++ b/cmake/vecmem-googletest.cmake @@ -30,6 +30,10 @@ FetchContent_Declare( GoogleTest # Options used in the build of GoogleTest. set( BUILD_GMOCK FALSE CACHE BOOL "Turn off the build of GMock" ) set( INSTALL_GTEST FALSE CACHE BOOL "Turn off the installation of GoogleTest" ) +if( WIN32 ) + set( gtest_force_shared_crt TRUE CACHE BOOL + "Use shared (DLL) run-time library, even with static libraries" ) +endif() # Get it into the current directory. FetchContent_Populate( GoogleTest ) diff --git a/cmake/vecmem-options.cmake b/cmake/vecmem-options.cmake index 522cb65f..2304249b 100644 --- a/cmake/vecmem-options.cmake +++ b/cmake/vecmem-options.cmake @@ -39,3 +39,12 @@ vecmem_lib_option( SYCL "Build the vecmem::sycl library" ) # Debug message output level in the code. set( VECMEM_DEBUG_MSG_LVL 0 CACHE STRING "Debug message output level" ) + +# Set the default library type, based on the platform. +set( _sharedLibDefault TRUE ) +if( WIN32 ) + set( _sharedLibDefault FALSE ) +endif() +set( BUILD_SHARED_LIBS ${_sharedLibDefault} CACHE BOOL + "Flag for building shared/static libraries" ) +unset( _sharedLibDefault ) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 4f8380f0..5db2874d 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -8,7 +8,7 @@ include( vecmem-compiler-options-cpp ) # Set up the build of the VecMem core library. -vecmem_add_library( vecmem_core core SHARED +vecmem_add_library( vecmem_core core # STL mimicking containers. "include/vecmem/containers/array.hpp" "include/vecmem/containers/impl/array.ipp" diff --git a/cuda/CMakeLists.txt b/cuda/CMakeLists.txt index 0c7ccd6e..1ca16179 100644 --- a/cuda/CMakeLists.txt +++ b/cuda/CMakeLists.txt @@ -18,7 +18,7 @@ include( vecmem-compiler-options-cuda ) find_package( CUDAToolkit REQUIRED ) # Set up the build of the VecMem CUDA library. -vecmem_add_library( vecmem_cuda cuda SHARED +vecmem_add_library( vecmem_cuda cuda # Memory resources. "include/vecmem/memory/cuda/device_memory_resource.hpp" "src/memory/cuda/device_memory_resource.cpp" diff --git a/hip/CMakeLists.txt b/hip/CMakeLists.txt index 88b67dba..8d83215d 100644 --- a/hip/CMakeLists.txt +++ b/hip/CMakeLists.txt @@ -15,7 +15,7 @@ include( vecmem-compiler-options-hip ) find_package( HIPToolkit REQUIRED ) # Set up the build of the VecMem HIP library. -vecmem_add_library( vecmem_hip hip SHARED +vecmem_add_library( vecmem_hip hip # Memory management. "include/vecmem/memory/hip/device_memory_resource.hpp" "src/memory/hip/device_memory_resource.cpp" diff --git a/sycl/CMakeLists.txt b/sycl/CMakeLists.txt index ed80f913..94753203 100644 --- a/sycl/CMakeLists.txt +++ b/sycl/CMakeLists.txt @@ -12,7 +12,7 @@ include( vecmem-compiler-options-cpp ) include( vecmem-compiler-options-sycl ) # Set up the build of the VecMem SYCL library. -vecmem_add_library( vecmem_sycl sycl SHARED +vecmem_add_library( vecmem_sycl sycl # Memory management. "include/vecmem/memory/sycl/details/memory_resource_base.hpp" "src/memory/sycl/details/memory_resource_base.sycl"