Collect configuration options at the top of the file - Also document the -DSTDCALL even better.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6287879..f39a1d0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,6 +14,33 @@
PROJECT(libgit2 C)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+# Build options
+#
+OPTION( BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON )
+OPTION( THREADSAFE "Build libgit2 as threadsafe" OFF )
+OPTION( BUILD_CLAR "Build Tests using the Clar suite" ON )
+OPTION( BUILD_EXAMPLES "Build library usage example apps" OFF )
+OPTION( TAGS "Generate tags" OFF )
+OPTION( PROFILE "Generate profiling information" OFF )
+IF(MSVC)
+ # This option is only availalbe when building with MSVC. By default, libgit2 is
+ # build using the stdcall calling convention, as that's what the CLR expects by
+ # default and how the Windows API is built.
+ #
+ # If you are writing a C or C++ program and want to link to libgit2, you have to
+ # either:
+ # - Add /Gz to the compiler options of _your_ program / library.
+ # - Turn this option off by invoking CMake with the "-DSTDCALL=Off" argument.
+ #
+ OPTION( STDCALL "Build libgit2 with the __stdcall convention" ON )
+ENDIF()
+
+# Installation paths
+#
+SET(BIN_INSTALL_DIR bin CACHE PATH "Where to install binaries to.")
+SET(LIB_INSTALL_DIR lib CACHE PATH "Where to install libraries to.")
+SET(INCLUDE_INSTALL_DIR include CACHE PATH "Where to install headers to.")
+
FILE(STRINGS "include/git2/version.h" GIT2_HEADER REGEX "^#define LIBGIT2_VERSION \"[^\"]*\"$")
STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"([0-9]+).*$" "\\1" LIBGIT2_VERSION_MAJOR "${GIT2_HEADER}")
@@ -71,23 +98,8 @@ ELSE()
FILE(GLOB SRC_ZLIB deps/zlib/*.c)
ENDIF()
-# Installation paths
-SET(BIN_INSTALL_DIR bin CACHE PATH "Where to install binaries to.")
-SET(LIB_INSTALL_DIR lib CACHE PATH "Where to install libraries to.")
-SET(INCLUDE_INSTALL_DIR include CACHE PATH "Where to install headers to.")
-
-# Build options
-OPTION (BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON)
-OPTION (THREADSAFE "Build libgit2 as threadsafe" OFF)
-OPTION (BUILD_CLAR "Build Tests using the Clar suite" ON)
-OPTION (BUILD_EXAMPLES "Build library usage example apps" OFF)
-OPTION (TAGS "Generate tags" OFF)
-OPTION (PROFILE "Generate profiling information" OFF)
-
# Platform specific compilation flags
IF (MSVC)
- # Default to stdcall, as that's what the CLR expects and how the Windows API is built
- OPTION (STDCALL "Buildl libgit2 with the __stdcall convention" ON)
STRING(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")