mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-12-04 15:39:34 +01:00
Support building with clang on Windows
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -27,6 +27,7 @@ CMakePresets.json
|
|||||||
CMakeUserPresets.json
|
CMakeUserPresets.json
|
||||||
.vs/
|
.vs/
|
||||||
out/
|
out/
|
||||||
|
\.clangd
|
||||||
|
|
||||||
# vcpkg
|
# vcpkg
|
||||||
vcpkg_installed*/
|
vcpkg_installed*/
|
||||||
|
|||||||
@@ -229,17 +229,23 @@ if("${CMAKE_SIZEOF_VOID_P}" EQUAL "4")
|
|||||||
set(IS_32BIT TRUE)
|
set(IS_32BIT TRUE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CLANG_COMPILER_ID_REGEX "^(Apple)?[Cc]lang$")
|
if("${CMAKE_CXX_COMPILER}" MATCHES "clang-cl(.exe)?$")
|
||||||
if("${CMAKE_C_COMPILER}" MATCHES "clang$"
|
# clang-cl uses MSVC compiler flags
|
||||||
OR "${CMAKE_EXTRA_GENERATOR_C_SYSTEM_DEFINED_MACROS}" MATCHES "__clang__"
|
set(MSVC 1)
|
||||||
OR "${CMAKE_C_COMPILER_ID}" MATCHES ${CLANG_COMPILER_ID_REGEX})
|
set(CMAKE_COMPILER_IS_CLANG_MSVC 1)
|
||||||
set(CMAKE_COMPILER_IS_CLANG 1)
|
else()
|
||||||
endif()
|
set(CLANG_COMPILER_ID_REGEX "^(Apple)?[Cc]lang$")
|
||||||
|
if("${CMAKE_C_COMPILER}" MATCHES "clang$"
|
||||||
|
OR "${CMAKE_EXTRA_GENERATOR_C_SYSTEM_DEFINED_MACROS}" MATCHES "__clang__"
|
||||||
|
OR "${CMAKE_C_COMPILER_ID}" MATCHES ${CLANG_COMPILER_ID_REGEX})
|
||||||
|
set(CMAKE_COMPILER_IS_CLANG 1)
|
||||||
|
endif()
|
||||||
|
|
||||||
if("${CMAKE_CXX_COMPILER}" MATCHES "clang(\\+\\+)?$"
|
if("${CMAKE_CXX_COMPILER}" MATCHES "clang(\\+\\+)?$"
|
||||||
OR "${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS}" MATCHES "__clang__"
|
OR "${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS}" MATCHES "__clang__"
|
||||||
OR "${CMAKE_CXX_COMPILER_ID}" MATCHES ${CLANG_COMPILER_ID_REGEX})
|
OR "${CMAKE_CXX_COMPILER_ID}" MATCHES ${CLANG_COMPILER_ID_REGEX})
|
||||||
set(CMAKE_COMPILER_IS_CLANGXX 1)
|
set(CMAKE_COMPILER_IS_CLANGXX 1)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
macro(add_gcc_compiler_cxxflags FLAGS)
|
macro(add_gcc_compiler_cxxflags FLAGS)
|
||||||
@@ -402,11 +408,15 @@ if (MSVC)
|
|||||||
if(MSVC_TOOLSET_VERSION LESS 141)
|
if(MSVC_TOOLSET_VERSION LESS 141)
|
||||||
message(FATAL_ERROR "Only Microsoft Visual Studio 17 and newer are supported!")
|
message(FATAL_ERROR "Only Microsoft Visual Studio 17 and newer are supported!")
|
||||||
endif()
|
endif()
|
||||||
add_compile_options(/permissive- /utf-8 /MP)
|
add_compile_options(/permissive- /utf-8)
|
||||||
if(IS_DEBUG_BUILD)
|
# Clang-cl does not support /MP, /Zf, or /fsanitize=address
|
||||||
add_compile_options(/Zf)
|
if (NOT CMAKE_COMPILER_IS_CLANG_MSVC)
|
||||||
if(MSVC_TOOLSET_VERSION GREATER 141)
|
add_compile_options(/MP)
|
||||||
add_compile_definitions(/fsanitize=address)
|
if(IS_DEBUG_BUILD)
|
||||||
|
add_compile_options(/Zf)
|
||||||
|
if(MSVC_TOOLSET_VERSION GREATER 141)
|
||||||
|
add_compile_definitions(/fsanitize=address)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
@@ -422,7 +432,7 @@ if(WIN32)
|
|||||||
# By default MSVC enables NXCOMPAT
|
# By default MSVC enables NXCOMPAT
|
||||||
add_compile_options(/guard:cf)
|
add_compile_options(/guard:cf)
|
||||||
add_link_options(/DYNAMICBASE /HIGHENTROPYVA /GUARD:CF)
|
add_link_options(/DYNAMICBASE /HIGHENTROPYVA /GUARD:CF)
|
||||||
else(MINGW)
|
else()
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--nxcompat -Wl,--dynamicbase")
|
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")
|
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--nxcompat -Wl,--dynamicbase")
|
||||||
# Enable high entropy ASLR for 64-bit builds
|
# Enable high entropy ASLR for 64-bit builds
|
||||||
@@ -432,6 +442,8 @@ if(WIN32)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
# Determine if we can link against the Windows SDK, used for Windows Hello support
|
||||||
|
find_library(WINSDK WindowsApp.lib)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(APPLE AND WITH_APP_BUNDLE OR WIN32)
|
if(APPLE AND WITH_APP_BUNDLE OR WIN32)
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ if(WIN32)
|
|||||||
list(APPEND gui_SOURCES
|
list(APPEND gui_SOURCES
|
||||||
gui/osutils/winutils/ScreenLockListenerWin.cpp
|
gui/osutils/winutils/ScreenLockListenerWin.cpp
|
||||||
gui/osutils/winutils/WinUtils.cpp)
|
gui/osutils/winutils/WinUtils.cpp)
|
||||||
if (MSVC)
|
if (WINSDK)
|
||||||
list(APPEND gui_SOURCES quickunlock/WindowsHello.cpp)
|
list(APPEND gui_SOURCES quickunlock/WindowsHello.cpp)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
@@ -415,7 +415,7 @@ if(UNIX AND NOT APPLE)
|
|||||||
endif()
|
endif()
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_link_libraries(keepassxc_gui Wtsapi32.lib Ws2_32.lib)
|
target_link_libraries(keepassxc_gui Wtsapi32.lib Ws2_32.lib)
|
||||||
if (MSVC)
|
if (WINSDK)
|
||||||
target_link_libraries(keepassxc_gui WindowsApp.lib)
|
target_link_libraries(keepassxc_gui WindowsApp.lib)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ namespace Bootstrap
|
|||||||
|
|
||||||
if (!CreateWellKnownSid(WinCreatorOwnerRightsSid, nullptr, pOwnerRightsSid, &pOwnerRightsSidSize)) {
|
if (!CreateWellKnownSid(WinCreatorOwnerRightsSid, nullptr, pOwnerRightsSid, &pOwnerRightsSidSize)) {
|
||||||
auto error = GetLastError();
|
auto error = GetLastError();
|
||||||
|
Q_UNUSED(error)
|
||||||
goto Cleanup;
|
goto Cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user