From 16eb58d503b55e5758aa791a0e17aed2935f9d37 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 22 Mar 2017 15:15:27 -0400 Subject: InstallRequiredSystemLibraries: Refactor to avoid macros For a given `MSVC_VERSION` our macros were each called at most once. Replace them with a single code path that is parameterized over what was the macro argument. --- Modules/InstallRequiredSystemLibraries.cmake | 112 +++++++++++++-------------- 1 file changed, 54 insertions(+), 58 deletions(-) diff --git a/Modules/InstallRequiredSystemLibraries.cmake b/Modules/InstallRequiredSystemLibraries.cmake index beb41956d3..bded8080f6 100644 --- a/Modules/InstallRequiredSystemLibraries.cmake +++ b/Modules/InstallRequiredSystemLibraries.cmake @@ -160,8 +160,20 @@ if(MSVC) endif() endif() - macro(MSVCRT_FILES_FOR_VERSION version) - set(v "${version}") + if(MSVC_VERSION EQUAL 1900 OR MSVC_VERSION EQUAL 1910) + set(_MSVCRT_VERSION 14) + elseif(MSVC_VERSION EQUAL 1800) + set(_MSVCRT_VERSION 12) + elseif(MSVC_VERSION EQUAL 1700) + set(_MSVCRT_VERSION 11) + elseif(MSVC_VERSION EQUAL 1600) + set(_MSVCRT_VERSION 10) + else() + set(_MSVCRT_VERSION "") + endif() + + if(_MSVCRT_VERSION) + set(v "${_MSVCRT_VERSION}") # Find the runtime library redistribution directory. get_filename_component(msvc_install_dir @@ -232,22 +244,6 @@ if(MSVC) list(APPEND __install__libs ${__ucrt_dlls}) endif() endif() - endmacro() - - if(MSVC_VERSION EQUAL 1600) - MSVCRT_FILES_FOR_VERSION(10) - endif() - - if(MSVC_VERSION EQUAL 1700) - MSVCRT_FILES_FOR_VERSION(11) - endif() - - if(MSVC_VERSION EQUAL 1800) - MSVCRT_FILES_FOR_VERSION(12) - endif() - - if(MSVC_VERSION EQUAL 1900 OR MSVC_VERSION EQUAL 1910) - MSVCRT_FILES_FOR_VERSION(14) endif() if(CMAKE_INSTALL_MFC_LIBRARIES) @@ -351,8 +347,20 @@ if(MSVC) ) endif() - macro(MFC_FILES_FOR_VERSION version) - set(v "${version}") + if(MSVC_VERSION EQUAL 1900 OR MSVC_VERSION EQUAL 1910) + set(_MFC_VERSION 14) + elseif(MSVC_VERSION EQUAL 1800) + set(_MFC_VERSION 12) + elseif(MSVC_VERSION EQUAL 1700) + set(_MFC_VERSION 11) + elseif(MSVC_VERSION EQUAL 1600) + set(_MFC_VERSION 10) + else() + set(_MFC_VERSION "") + endif() + + if(_MFC_VERSION) + set(v "${_MFC_VERSION}") # Multi-Byte Character Set versions of MFC are available as optional # addon since Visual Studio 12. So for version 12 or higher, check @@ -401,56 +409,44 @@ if(MSVC) "${MSVC${v}_MFCLOC_DIR}/mfc${v}0kor.dll" "${MSVC${v}_MFCLOC_DIR}/mfc${v}0rus.dll" ) - endmacro() - - if(MSVC_VERSION EQUAL 1600) - MFC_FILES_FOR_VERSION(10) - endif() - - if(MSVC_VERSION EQUAL 1700) - MFC_FILES_FOR_VERSION(11) - endif() - - if(MSVC_VERSION EQUAL 1800) - MFC_FILES_FOR_VERSION(12) - endif() - - if(MSVC_VERSION EQUAL 1900 OR MSVC_VERSION EQUAL 1910) - MFC_FILES_FOR_VERSION(14) endif() endif() # MSVC 8 was the first version with OpenMP # Furthermore, there is no debug version of this if(CMAKE_INSTALL_OPENMP_LIBRARIES) - macro(OPENMP_FILES_FOR_VERSION version_a version_b) - set(va "${version_a}") - set(vb "${version_b}") + if(MSVC_VERSION EQUAL 1900 OR MSVC_VERSION EQUAL 1910) + set(_MSOMP_VAR_VER 14) + set(_MSOMP_VERSION 140) + elseif(MSVC_VERSION EQUAL 1800) + set(_MSOMP_VAR_VER 12) + set(_MSOMP_VERSION 120) + elseif(MSVC_VERSION EQUAL 1700) + set(_MSOMP_VAR_VER 11) + set(_MSOMP_VERSION 110) + elseif(MSVC_VERSION EQUAL 1600) + set(_MSOMP_VAR_VER 10) + set(_MSOMP_VERSION 100) + elseif(MSVC_VERSION EQUAL 1500) + set(_MSOMP_VAR_VER 90) + set(_MSOMP_VERSION 90) + elseif(MSVC_VERSION EQUAL 1400) + set(_MSOMP_VAR_VER 80) + set(_MSOMP_VERSION 80) + else() + set(_MSOMP_VAR_VER "") + set(_MSOMP_VERSION "") + endif() + + if(_MSOMP_VERSION) + set(va "${_MSOMP_VAR_VER}") + set(vb "${_MSOMP_VERSION}") set(MSVC${va}_OPENMP_DIR "${MSVC${va}_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${vb}.OPENMP") if(NOT CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY) set(__install__libs ${__install__libs} "${MSVC${va}_OPENMP_DIR}/vcomp${vb}.dll") endif() - endmacro() - - if(MSVC_VERSION EQUAL 1400) - OPENMP_FILES_FOR_VERSION(80 80) - endif() - if(MSVC_VERSION EQUAL 1500) - OPENMP_FILES_FOR_VERSION(90 90) - endif() - if(MSVC_VERSION EQUAL 1600) - OPENMP_FILES_FOR_VERSION(10 100) - endif() - if(MSVC_VERSION EQUAL 1700) - OPENMP_FILES_FOR_VERSION(11 110) - endif() - if(MSVC_VERSION EQUAL 1800) - OPENMP_FILES_FOR_VERSION(12 120) - endif() - if(MSVC_VERSION EQUAL 1900 OR MSVC_VERSION EQUAL 1910) - OPENMP_FILES_FOR_VERSION(14 140) endif() endif() -- cgit v1.2.1