Add support for Microsoft Visual Studio buildchain

* Use C++17 when using MSVC compiler
* Remove unneeded header files and macros
* Removed unnecessary Yubikey cmake file
* Enhance release tool
* Updated INSTALL.md
This commit is contained in:
smlu 2021-09-06 22:26:00 -04:00 committed by Jonathan White
parent 24a23ce66e
commit 0c6587b5b7
19 changed files with 174 additions and 145 deletions

View file

@ -324,29 +324,46 @@ else()
add_gcc_compiler_cxxflags("-Wno-deprecated-declarations")
endif()
if(MINGW)
if (MSVC)
if(MSVC_VERSION LESS 1910)
message(FATAL_ERROR "Only Microsoft Visual Studio 17 and newer are supported!")
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_compile_options(/permissive- /utf-8)
endif()
if(WIN32)
set(CMAKE_RC_COMPILER_INIT windres)
enable_language(RC)
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
if(MINGW)
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
endif()
if(NOT (CMAKE_BUILD_TYPE_LOWER STREQUAL "debug" OR CMAKE_BUILD_TYPE_LOWER STREQUAL "relwithdebinfo"))
# Enable DEP and ASLR
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--nxcompat -Wl,--dynamicbase")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--nxcompat -Wl,--dynamicbase")
# Enable high entropy ASLR for 64-bit builds
if(NOT IS_32BIT)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--high-entropy-va")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--high-entropy-va")
# Enable DEP, ASLR and on VS additional enable
# control flow guard and buffer security check
if(MSVC)
add_compile_options(/DYNAMICBASE:YES /guard:cf /GS)
add_link_options(/NXCOMPAT /guard:cf)
else(MINGW)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--nxcompat -Wl,--dynamicbase")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--nxcompat -Wl,--dynamicbase")
# Enable high entropy ASLR for 64-bit builds
if(NOT IS_32BIT)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--high-entropy-va")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--high-entropy-va")
endif()
endif()
endif()
endif()
if(APPLE AND WITH_APP_BUNDLE OR MINGW)
if(APPLE AND WITH_APP_BUNDLE OR WIN32)
set(PROGNAME KeePassXC)
else()
set(PROGNAME keepassxc)
endif()
if(MINGW)
if(WIN32)
set(CLI_INSTALL_DIR ".")
set(PROXY_INSTALL_DIR ".")
set(BIN_INSTALL_DIR ".")
@ -429,8 +446,8 @@ if(APPLE)
message(FATAL_ERROR "macdeployqt is required to build on macOS")
endif()
message(STATUS "Using macdeployqt: ${MACDEPLOYQT_EXE}")
elseif(MINGW)
find_program(WINDEPLOYQT_EXE windeployqt HINTS ${Qt5_PREFIX}/bin ENV PATH)
elseif(WIN32)
find_program(WINDEPLOYQT_EXE windeployqt HINTS ${Qt5_PREFIX}/bin ${Qt5_PREFIX}/tools/qt5/debug/bin ENV PATH)
if(NOT WINDEPLOYQT_EXE)
message(FATAL_ERROR "windeployqt is required to build on Windows")
endif()
@ -455,9 +472,6 @@ if(ZLIB_VERSION_STRING VERSION_LESS "1.2.0")
endif()
include_directories(SYSTEM ${ZLIB_INCLUDE_DIR})
# QREncode required for TOTP
find_package(QREncode REQUIRED)
if(UNIX)
check_cxx_source_compiles("#include <sys/prctl.h>
int main() { prctl(PR_SET_DUMPABLE, 0); return 0; }"