Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 162 lines (132 sloc) 5.245 kb
583cf16 @drahosp Add optional CMake build script.
drahosp authored
1 # CMake build script for the libgit2 project
73c46d5 @drahosp Add basic testing support and options to specify install paths
drahosp authored
2 #
bfe0658 @drahosp Update install info and test resource path handling
drahosp authored
3 # Building (out of source build):
73c46d5 @drahosp Add basic testing support and options to specify install paths
drahosp authored
4 # > mkdir build && cd build
bfe0658 @drahosp Update install info and test resource path handling
drahosp authored
5 # > cmake .. [-DSETTINGS=VALUE]
6 # > cmake --build .
932d1ba @kiryl cleanup: remove trailing spaces
kiryl authored
7 #
73c46d5 @drahosp Add basic testing support and options to specify install paths
drahosp authored
8 # Testing:
9 # > ctest -V
10 #
11 # Install:
bfe0658 @drahosp Update install info and test resource path handling
drahosp authored
12 # > cmake --build . --target install
73c46d5 @drahosp Add basic testing support and options to specify install paths
drahosp authored
13
583cf16 @drahosp Add optional CMake build script.
drahosp authored
14 PROJECT(libgit2 C)
15 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
16
96fab09 @csware put version information in separate file
csware authored
17 FILE(STRINGS "include/git2/version.h" GIT2_HEADER REGEX "^#define LIBGIT2_VERSION \"[^\"]*\"$")
9d1dcca @vmg Add proper version management
vmg authored
18
19 STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"([0-9]+).*$" "\\1" LIBGIT2_VERSION_MAJOR "${GIT2_HEADER}")
20 STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_MINOR "${GIT2_HEADER}")
21 STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_REV "${GIT2_HEADER}")
22 SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_REV}")
23
7cbdaf7 @drahosp Add option to select sha1 type in CMake build
drahosp authored
24 # Find required dependencies
b8a8191 @carlosmn http: add http-parser
carlosmn authored
25 INCLUDE_DIRECTORIES(src include deps/http-parser)
26
27 FILE(GLOB SRC_HTTP deps/http-parser/*.c)
28
1f4f4d1 @radhermit cmake: Use system zlib if found on non-Windows systems
radhermit authored
29 IF (NOT WIN32)
30 FIND_PACKAGE(ZLIB)
31 ENDIF()
32
33 IF (ZLIB_FOUND)
34 INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS})
35 LINK_LIBRARIES(${ZLIB_LIBRARIES})
36 ELSE (ZLIB_FOUND)
37 INCLUDE_DIRECTORIES(deps/zlib)
38 ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP)
39 FILE(GLOB SRC_ZLIB deps/zlib/*.c)
40 ENDIF()
7cbdaf7 @drahosp Add option to select sha1 type in CMake build
drahosp authored
41
5b8bb8e @drahosp Minor modifications for MinGW/Cygwin compatibility.
drahosp authored
42 # Installation paths
73c46d5 @drahosp Add basic testing support and options to specify install paths
drahosp authored
43 SET(INSTALL_BIN bin CACHE PATH "Where to install binaries to.")
44 SET(INSTALL_LIB lib CACHE PATH "Where to install libraries to.")
032db4d @drahosp Reflect the recent changes in header organization (CMake)
drahosp authored
45 SET(INSTALL_INC include CACHE PATH "Where to install headers to.")
5b8bb8e @drahosp Minor modifications for MinGW/Cygwin compatibility.
drahosp authored
46
47 # Build options
f0890fc @vmg cmake: Build shared library by default
vmg authored
48 OPTION (BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON)
70236ba @vmg Update CMakeLists.txt to support threadsafe
vmg authored
49 OPTION (THREADSAFE "Build libgit2 as threadsafe" OFF)
d3fb6a8 @vmg cmake: Set the old test suite as default for the release
vmg authored
50 OPTION (BUILD_TESTS "Build Tests" ON)
51 OPTION (BUILD_CLAY "Build Tests using the Clay suite" OFF)
5b8bb8e @drahosp Minor modifications for MinGW/Cygwin compatibility.
drahosp authored
52
502dd2d @vmg msvc: Fix resourc embedding
vmg authored
53 # Platform specific compilation flags
dcd62cb @carlosmn CMake: Only add the STDCALL option when using MSVC
carlosmn authored
54 IF (MSVC)
502dd2d @vmg msvc: Fix resourc embedding
vmg authored
55 # Not using __stdcall with the CRT causes problems
dcd62cb @carlosmn CMake: Only add the STDCALL option when using MSVC
carlosmn authored
56 OPTION (STDCALL "Buildl libgit2 with the __stdcall convention" ON)
57
5b216d1 @carlosmn CMake: don't overwrite the user's CFLAGS
carlosmn authored
58 SET(CMAKE_C_FLAGS "/W4 /nologo /Zi ${CMAKE_C_FLAGS}")
1b5078f @carlosmn Use __stdcall by default on Windows
carlosmn authored
59 IF (STDCALL)
60 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gz")
61 ENDIF ()
e01f7f6 @vmg windows: Disable Runtime checks
vmg authored
62 # TODO: bring back /RTC1 /RTCc
63 SET(CMAKE_C_FLAGS_DEBUG "/Od /DEBUG /MTd")
9041250 @nulltoken Port MSVC specific Waf compilation flags to CMake and remove dynamic dep...
nulltoken authored
64 SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
502dd2d @vmg msvc: Fix resourc embedding
vmg authored
65 SET(WIN_RC "src/win32/git2.rc")
e233fa6 @carlosmn Bring back GCC flags
carlosmn authored
66 ELSE ()
5b216d1 @carlosmn CMake: don't overwrite the user's CFLAGS
carlosmn authored
67 SET(CMAKE_C_FLAGS "-O2 -g -Wall -Wextra -Wstrict-aliasing=2 -Wstrict-prototypes -Wmissing-prototypes ${CMAKE_C_FLAGS}")
4ce16ed @carlosmn CMake: use -O0 in debug mode
carlosmn authored
68 SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
39cdf27 @carlosmn Fix network MSYS compilation
carlosmn authored
69 IF (NOT MINGW) # MinGW always does PIC and complains if we tell it to
70 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
71 ENDIF ()
9041250 @nulltoken Port MSVC specific Waf compilation flags to CMake and remove dynamic dep...
nulltoken authored
72 ENDIF()
73
3d96996 @nulltoken Fix misleading comment in CMake build script
nulltoken authored
74 # Build Debug by default
583cf16 @drahosp Add optional CMake build script.
drahosp authored
75 IF (NOT CMAKE_BUILD_TYPE)
1a7b52d @vmg build: Drop waf support
vmg authored
76 SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
583cf16 @drahosp Add optional CMake build script.
drahosp authored
77 ENDIF ()
78
70236ba @vmg Update CMakeLists.txt to support threadsafe
vmg authored
79 IF (THREADSAFE)
80 IF (NOT WIN32)
81 find_package(Threads REQUIRED)
82 ENDIF()
83
84 ADD_DEFINITIONS(-DGIT_THREADS)
85 ENDIF()
86
678e9e0 @vmg build: Move OS-specific compat to their own folders
vmg authored
87 ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64)
88
583cf16 @drahosp Add optional CMake build script.
drahosp authored
89 # Collect sourcefiles
71d3338 @vmg Move the external includes folder from `src` to `include`
vmg authored
90 FILE(GLOB SRC_H include/git2/*.h)
583cf16 @drahosp Add optional CMake build script.
drahosp authored
91
92 # On Windows use specific platform sources
5b8bb8e @drahosp Minor modifications for MinGW/Cygwin compatibility.
drahosp authored
93 IF (WIN32 AND NOT CYGWIN)
da2281c @csware libgit2 doesn't use -LIB define
csware authored
94 ADD_DEFINITIONS(-DWIN32 -D_DEBUG)
dfafb03 @carlosmn Move the transports to their own directory
carlosmn authored
95 FILE(GLOB SRC src/*.c src/transports/*.c src/win32/*.c)
678e9e0 @vmg build: Move OS-specific compat to their own folders
vmg authored
96 ELSE()
dfafb03 @carlosmn Move the transports to their own directory
carlosmn authored
97 FILE(GLOB SRC src/*.c src/transports/*.c src/unix/*.c)
5b8bb8e @drahosp Minor modifications for MinGW/Cygwin compatibility.
drahosp authored
98 ENDIF ()
99
583cf16 @drahosp Add optional CMake build script.
drahosp authored
100 # Compile and link libgit2
502dd2d @vmg msvc: Fix resourc embedding
vmg authored
101 ADD_LIBRARY(git2 ${SRC} ${SRC_ZLIB} ${SRC_HTTP} ${WIN_RC})
39cdf27 @carlosmn Fix network MSYS compilation
carlosmn authored
102
103 IF (WIN32)
104 TARGET_LINK_LIBRARIES(git2 ws2_32)
e944cfa @carlosmn net: link necessary libraries in Solaris
carlosmn authored
105 ELSEIF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
106 TARGET_LINK_LIBRARIES(git2 socket nsl)
39cdf27 @carlosmn Fix network MSYS compilation
carlosmn authored
107 ENDIF ()
108
953e1f9 @vmg build: Cleanup CMake
vmg authored
109 TARGET_LINK_LIBRARIES(git2 ${CMAKE_THREAD_LIBS_INIT})
9d1dcca @vmg Add proper version management
vmg authored
110 SET_TARGET_PROPERTIES(git2 PROPERTIES VERSION ${LIBGIT2_VERSION_STRING})
111 SET_TARGET_PROPERTIES(git2 PROPERTIES SOVERSION ${LIBGIT2_VERSION_MAJOR})
4fd486e @carlosmn Really fix pkg-config
carlosmn authored
112 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libgit2.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libgit2.pc @ONLY)
583cf16 @drahosp Add optional CMake build script.
drahosp authored
113
114 # Install
932d1ba @kiryl cleanup: remove trailing spaces
kiryl authored
115 INSTALL(TARGETS git2
73c46d5 @drahosp Add basic testing support and options to specify install paths
drahosp authored
116 RUNTIME DESTINATION ${INSTALL_BIN}
117 LIBRARY DESTINATION ${INSTALL_LIB}
118 ARCHIVE DESTINATION ${INSTALL_LIB}
583cf16 @drahosp Add optional CMake build script.
drahosp authored
119 )
4fd486e @carlosmn Really fix pkg-config
carlosmn authored
120 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libgit2.pc DESTINATION ${INSTALL_LIB}/pkgconfig )
71d3338 @vmg Move the external includes folder from `src` to `include`
vmg authored
121 INSTALL(DIRECTORY include/git2 DESTINATION ${INSTALL_INC} )
122 INSTALL(FILES include/git2.h DESTINATION ${INSTALL_INC} )
583cf16 @drahosp Add optional CMake build script.
drahosp authored
123
124 # Tests
953e1f9 @vmg build: Cleanup CMake
vmg authored
125 IF (BUILD_TESTS)
11385c3 @vmg Add sample "Status" clay tests
vmg authored
126 SET(TEST_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tests/resources" CACHE PATH "Path to test resources.")
127 ADD_DEFINITIONS(-DTEST_RESOURCES=\"${TEST_RESOURCES}\")
128
953e1f9 @vmg build: Cleanup CMake
vmg authored
129 INCLUDE_DIRECTORIES(tests)
130 FILE(GLOB SRC_TEST tests/t??-*.c)
131
b8a8191 @carlosmn http: add http-parser
carlosmn authored
132 ADD_EXECUTABLE(libgit2_test tests/test_main.c tests/test_lib.c tests/test_helpers.c ${SRC} ${SRC_TEST} ${SRC_ZLIB} ${SRC_HTTP})
953e1f9 @vmg build: Cleanup CMake
vmg authored
133 TARGET_LINK_LIBRARIES(libgit2_test ${CMAKE_THREAD_LIBS_INIT})
e944cfa @carlosmn net: link necessary libraries in Solaris
carlosmn authored
134 IF (WIN32)
135 TARGET_LINK_LIBRARIES(libgit2_test ws2_32)
136 ELSEIF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
137 TARGET_LINK_LIBRARIES(libgit2_test socket nsl)
138 ENDIF ()
f64586f @vmg Add CTest support for CI
vmg authored
139
140 ENABLE_TESTING()
141 ADD_TEST(libgit2_test libgit2_test)
953e1f9 @vmg build: Cleanup CMake
vmg authored
142 ENDIF ()
f1558d9 @vmg Come out and Clay
vmg authored
143
144 IF (BUILD_CLAY)
11385c3 @vmg Add sample "Status" clay tests
vmg authored
145 SET(CLAY_FIXTURES "${CMAKE_CURRENT_SOURCE_DIR}/tests/resources/")
146 ADD_DEFINITIONS(-DCLAY_FIXTURE_PATH=\"${CLAY_FIXTURES}\")
147
f1558d9 @vmg Come out and Clay
vmg authored
148 INCLUDE_DIRECTORIES(tests-clay)
149 FILE(GLOB_RECURSE SRC_TEST tests-clay/*.c)
150
87a26ad @vmg Add HTTP sources to Clay suite
vmg authored
151 ADD_EXECUTABLE(libgit2_clay ${SRC} ${SRC_TEST} ${SRC_ZLIB} ${SRC_HTTP})
48e97ed @vmg Rename Clay target in CMakeLists
vmg authored
152 TARGET_LINK_LIBRARIES(libgit2_clay ${CMAKE_THREAD_LIBS_INIT})
f1558d9 @vmg Come out and Clay
vmg authored
153 IF (WIN32)
48e97ed @vmg Rename Clay target in CMakeLists
vmg authored
154 TARGET_LINK_LIBRARIES(libgit2_clay ws2_32)
f1558d9 @vmg Come out and Clay
vmg authored
155 ELSEIF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
48e97ed @vmg Rename Clay target in CMakeLists
vmg authored
156 TARGET_LINK_LIBRARIES(libgit2_clay socket nsl)
f1558d9 @vmg Come out and Clay
vmg authored
157 ENDIF ()
158
159 ENABLE_TESTING()
48e97ed @vmg Rename Clay target in CMakeLists
vmg authored
160 ADD_TEST(libgit2_clay libgit2_clay)
f1558d9 @vmg Come out and Clay
vmg authored
161 ENDIF ()
Something went wrong with that request. Please try again.