From a177efe3e25acd2e7d02d0fc78ea29d8954a3c67 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 15 Aug 2018 22:47:48 +0100 Subject: [PATCH] AppVeyor: build with both MSBuild and NMake generators, to compare Add support for building with single-config generators (such as NMake) on Windows, to complement existing support for multi-config generators (GENERATOR_IS_MULTI_CONFIG). --- appveyor.yml | 19 +++++++ infrastructure/cmake/CMakeLists.txt | 57 ++++++++++++++++----- infrastructure/cmake/windows/CMakeLists.txt | 41 ++++++++++++--- 3 files changed, 97 insertions(+), 20 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 856523008..e5031239a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -23,6 +23,10 @@ environment: CMAKE_UNIBUILD_DIR: '%APPVEYOR_BUILD_FOLDER%\..\cmake' BOXBACKUP_VERSION_BASE: 0.12 + matrix: + - build_tool: msbuild + - build_tool: nmake + cache: - '%CMAKE_UNIBUILD_DIR%\cache -> infrastructure\cmake\windows\CMakeLists.txt' @@ -40,6 +44,7 @@ init: # The only way to switch between 32-bit and 64-bit compilers appears to be to append " Win64" # to the generator name if you want a 64-bit build (x64 platform): - ps: $env:generator_name="$($env:Generator_Base)$(if ($env:PLATFORM.equals('x64')) {' Win64'})" + - ps: $env:vsdevcmd_platform_name="$(if ($env:PLATFORM.equals('x64')) {'amd64'} else {'x86'})" # scripts that run after cloning repository (before the build step, not after!) install: @@ -87,6 +92,20 @@ build: project: ..\cmake\BoxBackup_Windows.sln verbosity: minimal +# Override $generator_name and the build: section (replaced by build_script) when building with nmake: +for: +- + matrix: + only: + - build_tool: nmake + + init: + - ps: $env:generator_name="NMake Makefiles" + - cmd: '"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat" -host_arch=amd64 -arch=%vsdevcmd_platform_name%' + + build_script: + - cmd: nmake + test_script: # Check the results of the build (cmake directory), and the contents of the cache - cd %CMAKE_UNIBUILD_DIR%\Build\boxbackup diff --git a/infrastructure/cmake/CMakeLists.txt b/infrastructure/cmake/CMakeLists.txt index 14f008eaa..45fcbf401 100644 --- a/infrastructure/cmake/CMakeLists.txt +++ b/infrastructure/cmake/CMakeLists.txt @@ -11,6 +11,8 @@ enable_testing() set(base_dir ${CMAKE_SOURCE_DIR}/../..) +get_property(generator_is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + set(files_to_configure bin/bbackupd/bbackupd-config bin/bbstored/bbstored-certs @@ -363,8 +365,9 @@ else() DESTINATION "." COMPONENT Extras) endif() -# We can't do anything conditional on CMAKE_BUILD_TYPE because that's not valid for multi-configuration -# generators such as MSVC. We need to use a generator expression instead. +# We can't do anything conditional on CMAKE_BUILD_TYPE because that's not valid for +# multi-configuration generators such as MSVC. We need to use a generator expression +# instead. https://cmake.org/cmake/help/v3.9/prop_gbl/GENERATOR_IS_MULTI_CONFIG.html target_compile_definitions(lib_common PUBLIC $<$:BOX_RELEASE_BUILD> $<$:BOX_RELEASE_BUILD> @@ -404,14 +407,33 @@ if(WIN32) # We must link against zlibstaticD if this is a debug build, otherwise # we have a C runtime mismatch (/MD versus /MDd) and the application # crashes at runtime. - find_library(ZLIB_LIBRARY_STATIC_DEBUG NAMES zlibstaticd - PATHS ${ZLIB_ROOT}/lib NO_DEFAULT_PATH) - find_library(ZLIB_LIBRARY_STATIC_RELEASE NAMES zlibstatic - PATHS ${ZLIB_ROOT}/lib NO_DEFAULT_PATH) - - target_link_libraries(lib_compress PUBLIC - debug ${ZLIB_LIBRARY_STATIC_DEBUG} - optimized ${ZLIB_LIBRARY_STATIC_RELEASE}) + if(generator_is_multi_config) + find_library(ZLIB_LIBRARY_STATIC_DEBUG NAMES zlibstaticd + PATHS ${ZLIB_ROOT}/lib NO_DEFAULT_PATH) + find_library(ZLIB_LIBRARY_STATIC_RELEASE NAMES zlibstatic + PATHS ${ZLIB_ROOT}/lib NO_DEFAULT_PATH) + target_link_libraries(lib_compress PUBLIC + debug ${ZLIB_LIBRARY_STATIC_DEBUG} + optimized ${ZLIB_LIBRARY_STATIC_RELEASE}) + message(STATUS "Using ZLIB for ${generator_is_multi_config} ${CMAKE_BUILD_TYPE}: \ + both ${ZLIB_LIBRARY_STATIC_DEBUG} ${ZLIB_LIBRARY_STATIC_RELEASE NAMES}") + elseif(CMAKE_BUILD_TYPE STREQUAL Debug) + find_library(ZLIB_LIBRARY_STATIC_DEBUG NAMES zlibstaticd + PATHS ${ZLIB_ROOT}/lib NO_DEFAULT_PATH) + target_link_libraries(lib_compress PUBLIC + debug ${ZLIB_LIBRARY_STATIC_DEBUG}) + message(STATUS "Using ZLIB for ${generator_is_multi_config} ${CMAKE_BUILD_TYPE}: \ + debug-only ${ZLIB_LIBRARY_STATIC_DEBUG}") + else() + find_library(ZLIB_LIBRARY_STATIC_RELEASE NAMES zlibstatic + PATHS ${ZLIB_ROOT}/lib NO_DEFAULT_PATH) + target_link_libraries(lib_compress PUBLIC + optimized ${ZLIB_LIBRARY_STATIC_RELEASE}) + message(STATUS "Using ZLIB for ${generator_is_multi_config} ${CMAKE_BUILD_TYPE}: \ + release-only ${ZLIB_LIBRARY_STATIC_RELEASE NAMES}") + endif() + message(STATUS "Using ZLIB for ${generator_is_multi_config} ${CMAKE_BUILD_TYPE}") + else() find_package(ZLIB REQUIRED) include_directories(${ZLIB_INCLUDE_DIRS}) @@ -453,8 +475,19 @@ if (WIN32) find_library(pcreposixd_lib_path pcreposixd ${PCRE_ROOT}/lib) find_library(pcre_lib_path pcre ${PCRE_ROOT}/lib) find_library(pcred_lib_path pcred ${PCRE_ROOT}/lib) - target_link_libraries(lib_common PUBLIC debug "${pcreposixd_lib_path}" optimized "${pcreposix_lib_path}") - target_link_libraries(lib_common PUBLIC debug "${pcred_lib_path}" optimized "${pcre_lib_path}") + if(generator_is_multi_config) + target_link_libraries(lib_common PUBLIC debug "${pcreposixd_lib_path}" + optimized "${pcreposix_lib_path}") + target_link_libraries(lib_common PUBLIC debug "${pcred_lib_path}" + optimized "${pcre_lib_path}") + elseif(CMAKE_BUILD_TYPE STREQUAL Debug) + target_link_libraries(lib_common PUBLIC debug "${pcreposixd_lib_path}") + target_link_libraries(lib_common PUBLIC debug "${pcred_lib_path}") + else() + target_link_libraries(lib_common PUBLIC optimized "${pcreposix_lib_path}") + target_link_libraries(lib_common PUBLIC optimized "${pcre_lib_path}") + endif() + include_directories(${PCRE_ROOT}/include) else() find_package(PkgConfig REQUIRED) diff --git a/infrastructure/cmake/windows/CMakeLists.txt b/infrastructure/cmake/windows/CMakeLists.txt index e0c66d44a..1f6888bb8 100644 --- a/infrastructure/cmake/windows/CMakeLists.txt +++ b/infrastructure/cmake/windows/CMakeLists.txt @@ -7,6 +7,7 @@ set_property(DIRECTORY PROPERTY EP_BASE .) set(install_dir ${CMAKE_BINARY_DIR}/install) set(cache_dir ${CMAKE_BINARY_DIR}/cache) file(MAKE_DIRECTORY ${cache_dir}) +get_property(generator_is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) # Automate the process of downloading, building and "installing" dependencies on Windows, # as used by AppVeyor. @@ -54,15 +55,27 @@ endfunction() if(EXISTS ${zlib_package_file}) ExternalProject_Cached(zlib ${zlib_package_file} ${zlib_install_dir}) else() + if(generator_is_multi_config) + set(zlib_install_command + # We need to build both versions, debug and release, because cmake requires + # both to be present to generate its multi-configuration project files for + # Visual Studio/MSBuild. + INSTALL_COMMAND ${CMAKE_COMMAND} --build --target install --config Debug + COMMAND ${CMAKE_COMMAND} --build --target install --config Release + ) + else() + set(zlib_install_command + INSTALL_COMMAND ${CMAKE_COMMAND} --build --target install + --config ${CMAKE_BUILD_TYPE} + ) + endif() + ExternalProject_Add(zlib URL "http://zlib.net/zlib-${ZLIB_VERSION}.tar.gz" URL_HASH ${ZLIB_HASH} DOWNLOAD_NO_PROGRESS 1 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${zlib_install_dir} ${SUB_CMAKE_EXTRA_ARGS} - # We need to build both versions, debug and release, because cmake requires both to be - # present to generate its multi-configuration project files for Visual Studio/MSBuild. - INSTALL_COMMAND ${CMAKE_COMMAND} --build --target install --config Debug - COMMAND ${CMAKE_COMMAND} --build --target install --config Release + ${zlib_install_command} COMMAND ${CMAKE_COMMAND} -E tar czvf ${zlib_package_file} ${zlib_install_dir} STEP_TARGETS configure install @@ -146,6 +159,21 @@ set(pcre_package_file "${cache_dir}/pcre_${cmake_lists_hash}.tgz") if(EXISTS ${pcre_package_file}) ExternalProject_Cached(pcre ${pcre_package_file} ${pcre_install_dir}) else() + if(generator_is_multi_config) + set(pcre_install_command + # We need to build both versions, debug and release, because cmake requires + # both to be present to generate its multi-configuration project files for + # Visual Studio/MSBuild. + INSTALL_COMMAND ${CMAKE_COMMAND} --build --target install --config Debug + COMMAND ${CMAKE_COMMAND} --build --target install --config Release + ) + else() + set(pcre_install_command + INSTALL_COMMAND ${CMAKE_COMMAND} --build --target install + --config ${CMAKE_BUILD_TYPE} + ) + endif() + ExternalProject_Add(pcre URL "https://ftp.pcre.org/pub/pcre/pcre-${PCRE_VERSION}.tar.bz2" URL_HASH ${PCRE_HASH} @@ -156,10 +184,7 @@ else() -DPCRE_BUILD_PCRECPP=OFF -DPCRE_BUILD_PCREGREP=OFF -DPCRE_BUILD_TESTS=OFF - # We need to build both versions, debug and release, because cmake requires both to be - # present to generate its multi-configuration project files for Visual Studio/MSBuild. - INSTALL_COMMAND ${CMAKE_COMMAND} --build --target install --config Debug - COMMAND ${CMAKE_COMMAND} --build --target install --config Release + ${pcre_install_command} COMMAND ${CMAKE_COMMAND} -E tar czvf ${pcre_package_file} ${pcre_install_dir} )