diff options
author | Philip Kelley <phkelley@microsoft.com> | 2020-04-25 15:37:45 -0700 |
---|---|---|
committer | Philip Kelley <phkelley@microsoft.com> | 2020-04-25 15:44:42 -0700 |
commit | 63f9fbeea52787b41110157310aa1e1aebc364d1 (patch) | |
tree | 561b1a078c0816cda60ab1a778683a0b787e39a4 /CMakeLists.txt | |
parent | 66137ff6ea9e516e0fa840134393d5a81d5b86e9 (diff) | |
download | libgit2-63f9fbeea52787b41110157310aa1e1aebc364d1.tar.gz |
MSVC: Enable Control Flow Guard (CFG)
This feature requires Visual Studio 2015 (MSVC_VERSION = 1900) or later. As the
minimum required CMake version is currently less than 3.7, GREATER_EQUAL is not
available to us and we must invert the result of the LESS operator.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 826415893..381954790 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,6 +137,11 @@ IF (MSVC) # /Gd - explicitly set cdecl calling convention SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gd") + IF (NOT (MSVC_VERSION LESS 1900)) + # /guard:cf - Enable Control Flow Guard + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /guard:cf") + ENDIF() + IF (STATIC_CRT) SET(CRT_FLAG_DEBUG "/MTd") SET(CRT_FLAG_RELEASE "/MT") @@ -183,6 +188,11 @@ IF (MSVC) # /VERSION - Embed version information in PE header SET(CMAKE_EXE_LINKER_FLAGS "/DYNAMICBASE /NXCOMPAT /LARGEADDRESSAWARE /VERSION:${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}") + IF (NOT (MSVC_VERSION LESS 1900)) + # /GUARD:CF - Enable Control Flow Guard + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /GUARD:CF") + ENDIF() + # /DEBUG - Create a PDB # /LTCG - Link time code generation (whole program optimization) # /OPT:REF /OPT:ICF - Fold out duplicate code at link step |