Skip to content

Commit

Permalink
AppVeyor: build with both MSBuild and NMake generators, to compare
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
qris committed Aug 16, 2018
1 parent 312e025 commit a177efe
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 20 deletions.
19 changes: 19 additions & 0 deletions appveyor.yml
Expand Up @@ -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'

Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
57 changes: 45 additions & 12 deletions infrastructure/cmake/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
$<$<CONFIG:Release>:BOX_RELEASE_BUILD>
$<$<CONFIG:RelWithDebInfo>:BOX_RELEASE_BUILD>
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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)
Expand Down
41 changes: 33 additions & 8 deletions infrastructure/cmake/windows/CMakeLists.txt
Expand Up @@ -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.
Expand Down Expand Up @@ -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 <BINARY_DIR> --target install --config Debug
COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target install --config Release
)
else()
set(zlib_install_command
INSTALL_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --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 <BINARY_DIR> --target install --config Debug
COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target install --config Release
${zlib_install_command}
COMMAND ${CMAKE_COMMAND} -E tar czvf ${zlib_package_file}
${zlib_install_dir}
STEP_TARGETS configure install
Expand Down Expand Up @@ -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 <BINARY_DIR> --target install --config Debug
COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target install --config Release
)
else()
set(pcre_install_command
INSTALL_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --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}
Expand All @@ -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 <BINARY_DIR> --target install --config Debug
COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target install --config Release
${pcre_install_command}
COMMAND ${CMAKE_COMMAND} -E tar czvf ${pcre_package_file}
${pcre_install_dir}
)
Expand Down

0 comments on commit a177efe

Please sign in to comment.