Skip to content

Commit

Permalink
Update "fetch" branch with working implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Jul 20, 2023
1 parent a69b66b commit ef913ae
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.14..3.22)

project(secp256k1-example LANGUAGES C)

include(FetchContent)
set(SECP256K1_DISABLE_SHARED ON CACHE INTERNAL "")
set(SECP256K1_BUILD_BENCHMARK OFF CACHE INTERNAL "")
set(SECP256K1_BUILD_TESTS OFF CACHE INTERNAL "")
set(SECP256K1_BUILD_EXHAUSTIVE_TESTS OFF CACHE INTERNAL "")
set(SECP256K1_BUILD_CTIME_TESTS OFF CACHE INTERNAL "")

include(FetchContent)
FetchContent_Declare(
libsecp256k1
GIT_REPOSITORY https://github.com/bitcoin-core/secp256k1
GIT_TAG c545fdc374964424683d9dac31a828adedabe860
)

FetchContent_MakeAvailable(libsecp256k1)

add_executable(${PROJECT_NAME} src/ecdsa.c)
Expand Down
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
This is a DEMO repository with examples of using an installed [`secp256k1`](https://github.com/bitcoin-core/secp256k1)
library with [CMake](https://github.com/bitcoin-core/secp256k1/pull/1113).
This is a DEMO repository with examples of using the [`libsecp256k1`](https://github.com/bitcoin-core/secp256k1)
library in downstream projects with CMake.

Source code is borrowed from https://github.com/bitcoin-core/secp256k1/tree/master/examples directly.

---

There are two options to use the `secp256k1` library in a your project:
- install it into your system
- have its source code as a subtree in your project's source tree
There are multiple options to use the `libsecp256k1` library in your project:
- install it into your system,
- have its source code as a subtree in your project's source tree,
- use the `FetchContent` module.


## Installed library
Expand All @@ -16,14 +18,14 @@ Switch to the ["main"](https://github.com/hebasto/secp256k1-CMake-example/tree/m

To build a binary, use commands as follows:
```sh
cmake -S . -B build
cmake -B build
cmake --build build
```

If the `secp256k1` library has been installed in a non-standard path, add its installation prefix to `CMAKE_PREFIX_PATH`.
For example:
```sh
cmake -S . -B build -DCMAKE_PREFIX_PATH=/home/username/custom_lib
cmake -B build -DCMAKE_PREFIX_PATH=/home/username/custom_lib
cmake --build build
```

Expand All @@ -33,8 +35,20 @@ Switch to the ["subtree"](https://github.com/hebasto/secp256k1-CMake-example/tre

```sh
dir=$(mktemp -d)
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=$dir
cmake -B build -DCMAKE_INSTALL_PREFIX=$dir
cmake --build build --target install
tree $dir
$dir/bin/secp256k1-example
```
```

## Using `FetchContent` module

Switch to the ["fetch"](https://github.com/hebasto/secp256k1-CMake-example/tree/fetch) branch of this repository.

```sh
dir=$(mktemp -d)
cmake -B build -DCMAKE_INSTALL_PREFIX=$dir
cmake --build build --target install
tree $dir
$dir/bin/secp256k1-example
```

0 comments on commit ef913ae

Please sign in to comment.