Skip to content

Commit c117246

Browse files
committed
cmake: provide empty experimental.h for non-cmake users
Not everybody builds libgit2 using cmake; provide an `experimental.h` with no experiments configured for those that do not. To support this, we also now create compile definitions for experimental functionality, to supplant that empty `experimental.h`. cmake will continue to generate the proper `experimental.h` file for use with `make install`.
1 parent c8d5b43 commit c117246

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

cmake/ExperimentalFeatures.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
# Experimental feature support for libgit2 - developers can opt in to
2+
# experimental functionality, like sha256 support. When experimental
3+
# functionality is enabled, we set both a cmake flag *and* a compile
4+
# definition. The cmake flag is used to generate `experimental.h`,
5+
# which will be installed by a `make install`. But the compile definition
6+
# is used by the libgit2 sources to detect the functionality at library
7+
# build time. This allows us to have an in-tree `experimental.h` with
8+
# *no* experiments enabled. This lets us support users who build without
9+
# cmake and cannot generate the `experimental.h` file.
10+
111
if(EXPERIMENTAL_SHA256)
212
add_feature_info("SHA256 API" ON "experimental SHA256 APIs")
313

414
set(EXPERIMENTAL 1)
515
set(GIT_EXPERIMENTAL_SHA256 1)
16+
add_compile_definitions(GIT_EXPERIMENTAL_SHA256)
617
else()
718
add_feature_info("SHA256 API" OFF "experimental SHA256 APIs")
819
endif()

include/git2/experimental.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
8+
#ifndef INCLUDE_experimental_h__
9+
#define INCLUDE_experimental_h__
10+
11+
/*
12+
* This file exists to support users who build libgit2 with a bespoke
13+
* build system and do not use our cmake configuration. Normally, cmake
14+
* will create `experimental.h` from the `experimental.h.in` file and
15+
* will include the generated file instead of this one. For non-cmake
16+
* users, we bundle this `experimental.h` file which will be used
17+
* instead.
18+
*/
19+
20+
#endif

src/libgit2/experimental.h.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
18
#ifndef INCLUDE_experimental_h__
29
#define INCLUDE_experimental_h__
310

0 commit comments

Comments
 (0)