Skip to content

build: Introduce CMake-based build system#75

Merged
sipa merged 3 commits into
bitcoin-core:masterfrom
hebasto:221019-ci-msvc
Jul 1, 2025
Merged

build: Introduce CMake-based build system#75
sipa merged 3 commits into
bitcoin-core:masterfrom
hebasto:221019-ci-msvc

Conversation

@hebasto

@hebasto hebasto commented Oct 20, 2022

Copy link
Copy Markdown
Member

This PR introduces a new CMake-based build system, which can be reused in downstream projects, including Bitcoin Core.

Additionally, a GitHub Actions CI task for MSVC and clang-cl has been added, following this feedback.

Autotools vs CMake configuration option parity

Autotools CMake
--disable-ccache N/A
--enable-tests -DMINISKETCH_BUILD_TESTS
--enable-benchmark -DMINISKETCH_BUILD_BENCHMARK
--enable-fields=,-separated list -DMINISKETCH_FIELDS=;-separated list
-DMINISKETCH_INSTALL

Notes on the implementation

  1. The default CMAKE_BUILD_TYPE is left unset.

  2. CMake's per-configuration compiler flags are not modified. As a result, they may include -DNDEBUG.

  3. The target name test is reserved. Therefore, the testing binary has been renamed to test-noverify. Alternatively, following the naming used in the libsecp256k1 repo, the test binaries could be renamed as:

    • test --> noverify_tests
    • test-verify --> verify_tests

@hebasto

hebasto commented Oct 20, 2022

Copy link
Copy Markdown
Member Author

Chasing for Concept (N)ACKs...

@hebasto
hebasto marked this pull request as ready for review October 23, 2022 08:02
@hebasto

hebasto commented Oct 23, 2022

Copy link
Copy Markdown
Member Author

The currently suggesting minimal CMake-based build system implementation is enough for:

add_subdirectory(minisketch EXCLUDE_FROM_ALL)
target_compile_definitions(minisketch
  PRIVATE
    DISABLE_DEFAULT_FIELDS
    ENABLE_FIELD_32
)

To became a full fledged one, the current minimal CMake-based build system requires some additional features:

  • more robustness (e.g., checking compiler/linker flags before applying them)
  • ability to install the built artifacts
  • ability to export the built artifacts and, probably, packaging of them
  • documentation

Although, those features are not required for this PR goal, i.e., providing a native Windows CI task.

@hebasto

hebasto commented Oct 31, 2022

Copy link
Copy Markdown
Member Author

Updated 5851544 -> d2408e0 (pr75.03 -> pr75.04, diff):

  • policy CMP0063 set explicitly to avoid CMake warnings
  • the default CMake build directory added to the .gitignore file

@theuni

theuni commented Mar 17, 2023

Copy link
Copy Markdown
Contributor

Imo this should be renamed "Add CMake buildsystem". I looked for this a while back and didn't find it because CMake isn't mentioned in the title.

Concept ACK. Will review next week.

@theuni

theuni commented Mar 31, 2023

Copy link
Copy Markdown
Contributor

@sipa Are you interested in CMake for this project?

@sipa

sipa commented Mar 31, 2023

Copy link
Copy Markdown
Collaborator

@theuni Yeah, will look soon.

@theuni

theuni commented Mar 31, 2023

Copy link
Copy Markdown
Contributor

@sipa No rush. I was just looking for a concept ACK.

I worked up a CMake impl as well before seeing this PR. I think we'd benefit from parts of each, so I'll get with @hebasto on creating a combined version for review.

@hebasto hebasto changed the title ci: Add "x86_64: Windows (VS 2022)" task build: Add CMake buildsystem Apr 16, 2023
@hebasto

hebasto commented Apr 16, 2023

Copy link
Copy Markdown
Member Author

Imo this should be renamed "Add CMake buildsystem".

Done.

@sipa

sipa commented Apr 11, 2024

Copy link
Copy Markdown
Collaborator

I'm happy to add a CMake build system for minisketch. I will need review from people more experienced with build systems, though.

@hebasto

hebasto commented Apr 11, 2024

Copy link
Copy Markdown
Member Author

I'm happy to add a CMake build system for minisketch. I will need review from people more experienced with build systems, though.

I'm going to update this PR shortly.

@hebasto
hebasto force-pushed the 221019-ci-msvc branch 2 times, most recently from 66b4133 to b486457 Compare April 16, 2024 16:44
@hebasto

hebasto commented Apr 16, 2024

Copy link
Copy Markdown
Member Author

Reworked.

The PR description has been updated.

The approach from hebasto/bitcoin#93 was used for printing summary.

Comment thread CMakeLists.txt
endif()

if(MINGW)
add_link_options(-static)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should port this functionality. Instead we should use the CMake shared/static selection machinery.

@hebasto hebasto Apr 26, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This affects only benchmark/test binaries and allows to run them on the build system via Wine when building either a static library or a shared one.

UPD. It also links libstdc++-6 to libminisketch.dll statically when cross-compiling for Windows and -DBUILD_SHARED_LIBS=YES is provided.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider

cmake -B build \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_SYSTEM_NAME=Windows \
  -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++-posix
cmake --build build --target test
wine ./build/src/test.exe

or

cmake -B build \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_SYSTEM_NAME=Windows \
  -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++-posix \
  -DBUILD_SHARED_LIBS=YES
cmake --build build --target test
wine ./build/src/test.exe

Comment thread src/CMakeLists.txt Outdated
Comment thread CMakeLists.txt Outdated
Comment thread CMakeLists.txt Outdated
Comment thread CMakeLists.txt
)

if(DEFINED CMAKE_CXX_STANDARD)
if(CMAKE_CXX_STANDARD EQUAL 98 OR CMAKE_CXX_STANDARD LESS 11)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah! Stupid CMake :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y2K problem :)

@hebasto

hebasto commented Apr 26, 2024

Copy link
Copy Markdown
Member Author

Addressed @theuni's comments.

@hebasto
hebasto marked this pull request as draft March 5, 2025 14:14
@sipa

sipa commented May 13, 2025

Copy link
Copy Markdown
Collaborator

What is the status here?

@hebasto

hebasto commented May 13, 2025

Copy link
Copy Markdown
Member Author

What is the status here?

I'll push an update shortly.

@hebasto
hebasto marked this pull request as ready for review June 1, 2025 01:09
@hebasto

hebasto commented Jun 18, 2025

Copy link
Copy Markdown
Member Author

The PR has been updated to improve integration with downstream projects and now makes use of PUBLIC_HEADER (see bitcoin-core/secp256k1#1679).

The corresponding Bitcoin Core branch that integrates the new build system is available here.

Please note that the current approach does not involve using a project-specific variable to override CMake's BUILD_SHARED_LIBS (this is done via SECP256K1_DISABLE_SHARED in the libsecp256k1 project):

function(add_minisketch subdir)
  message("")
  message("Configuring minisketch subtree...")
  set(BUILD_SHARED_LIBS OFF)
  set(CMAKE_EXPORT_COMPILE_COMMANDS OFF)
  # Hard-code subtree's options.
  set(MINISKETCH_INSTALL OFF)
  set(MINISKETCH_BUILD_TESTS OFF)
  set(MINISKETCH_BUILD_BENCHMARK OFF)
  set(MINISKETCH_FIELDS 32)
  add_subdirectory(${subdir} EXCLUDE_FROM_ALL)
  target_link_libraries(minisketch
    PRIVATE
      core_interface
  )
endfunction()

In integration scenarios similar to bitcoin-core/secp256k1#1678, the $<TARGET_OBJECTS:minisketch> generator expression expands to all associated object files.

cc @theuni

Comment thread CMakeLists.txt
Comment on lines +31 to +32
# Prevent include directories from parent project from leaking into this one.
set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES "")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See similar code in the libmultiprocess project:

# Prevent include directories from parent project from leaking into this one.
set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES "")

@hebasto

hebasto commented Jun 27, 2025

Copy link
Copy Markdown
Member Author

Pushed some improvements basing on @ryanofsky's bitcoin-core/libmultiprocess@6adbb1d and offline discussions with @purpleKarrot.

The corresponding Bitcoin Core branch that integrates the new build system is available here.

Comment thread src/CMakeLists.txt Outdated
Comment thread src/CMakeLists.txt Outdated
@hebasto
hebasto force-pushed the 221019-ci-msvc branch 2 times, most recently from 85d6f32 to 0d6e8ac Compare June 27, 2025 19:24
@hebasto

hebasto commented Jun 27, 2025

Copy link
Copy Markdown
Member Author

The feedback from @purpleKarrot has been addressed.

The corresponding Bitcoin Core branch that integrates the new build system is available here.

@purpleKarrot

Copy link
Copy Markdown

@hebasto, I think you accidentally based your latest change on an older revision. A few changes got reverted.

Comment thread CMakeLists.txt
#=============================
# Build Options
#=============================
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature actually requires a bit more work to get right. It is currently not working correctly in the autotools build either, so it can be done in a separate PR.

@hebasto

hebasto commented Jun 27, 2025

Copy link
Copy Markdown
Member Author

Further feedback from @purpleKarrot has been addressed.

The corresponding Bitcoin Core branch that integrates the new build system is available here.

I think you accidentally based your latest change on an older revision. A few changes got reverted.

Should be OK now.

@purpleKarrot

Copy link
Copy Markdown

ACK 850cc86

@theuni theuni left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 850cc86.

Once integrated into Core, I propose that we nuke the old buildsystem. I doubt sipa has much interest in supporting both here.

@sipa

sipa commented Jul 1, 2025

Copy link
Copy Markdown
Collaborator

Weakly-tested ACK 850cc86

@sipa
sipa merged commit f74b7e2 into bitcoin-core:master Jul 1, 2025
21 checks passed
@hebasto
hebasto deleted the 221019-ci-msvc branch July 2, 2025 08:30
hebasto added a commit to hebasto/bitcoin that referenced this pull request Jul 2, 2025
f74b7e2bc2 Merge bitcoin-core/minisketch#75: build: Introduce CMake-based build system
850cc868d5 ci: Add GHA workflow with native Windows job
40d56708c8 doc: Add "Building with CMake" section to `README.md`
a0c86c79a7 build: Add CMake-based build system

git-subtree-dir: src/minisketch
git-subtree-split: f74b7e2bc2e5e1a1360927934521216bee5f345c
real-or-random added a commit to bitcoin-core/secp256k1 that referenced this pull request Jul 30, 2025
…BUILD_SHARED_LIBS`

7b07b22 cmake: Avoid contaminating parent project's cache with BUILD_SHARED_LIBS (Hennadii Stepanov)

Pull request description:

  The CMake cache is global in scope. Therefore, setting the standard cache variable `BUILD_SHARED_LIBS` can inadvertently affect the behavior of a parent project.

  Consider configuring Bitcoin Core without explicit setting `BUILD_SHARED_LIBS`:
  ```
  $ cmake -B build -DBUILD_KERNEL_LIB=ON
  ```

  According to CMake’s documentation, this should configure `libbitcoinkernel` as `STATIC`.
  However, that's not the case:
  ```
  $ cmake --build build -t libbitcoinkernel
  [143/143] Linking CXX shared library lib/libbitcoinkernel.so
  ```

  This PR:
  1. Sets the `BUILD_SHARED_LIBS` cache variable only when `libsecp256k1` is the top-level project.
  2. Removes the `SECP256K1_DISABLE_SHARED` cache variable. This enables parent projects that include libsecp256k1 as a subproject to rely solely on standard CMake variables for configuring the library type.  During integration into a parent project, the static library can be forced as demonstrated [here](bitcoin-core/minisketch#75 (comment)).

ACKs for top commit:
  purpleKarrot:
    ACK 7b07b22
  theuni:
    utACK 7b07b22

Tree-SHA512: 399a02e86093656ce70d9a0292a1f30834bcc5b9cf0f77d6465adc5e8a4d8e779684adedc40942eb931fed857399e4176a23fdbdf45f277184b28159fbc932d2
hebasto added a commit to hebasto/bitcoin that referenced this pull request Oct 13, 2025
d1bd01e189 Merge bitcoin-core/minisketch#98: misc: drop trailing whitespace
fe2c88a4fd misc: drop trailing whitespace
f74b7e2bc2 Merge bitcoin-core/minisketch#75: build: Introduce CMake-based build system
850cc868d5 ci: Add GHA workflow with native Windows job
40d56708c8 doc: Add "Building with CMake" section to `README.md`
a0c86c79a7 build: Add CMake-based build system

git-subtree-dir: src/minisketch
git-subtree-split: d1bd01e189e745cd1828707e0a7004b6a6909650
fanquake added a commit to bitcoin/bitcoin that referenced this pull request Nov 10, 2025
4543a3b Squashed 'src/minisketch/' changes from ea8f66b1ea..d1bd01e189 (Hennadii Stepanov)

Pull request description:

  This PR updates the `minisketch` subtree to latest upstream, which includes:
      - bitcoin-core/minisketch#75
      - bitcoin-core/minisketch#98

ACKs for top commit:
  fanquake:
    ACK c235aa4

Tree-SHA512: 856fb8b7dc2e743c9c67164023bf53faf8766079aeccc82a30c8b90c85920b31977b6a8b26e51e5485b20e445a3ca6ff806e701a53e95f70181ea30055e3528c
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Jun 28, 2026
4543a3b Squashed 'src/minisketch/' changes from ea8f66b1ea..d1bd01e189 (Hennadii Stepanov)

Pull request description:

  This PR updates the `minisketch` subtree to latest upstream, which includes:
      - bitcoin-core/minisketch#75
      - bitcoin-core/minisketch#98

ACKs for top commit:
  fanquake:
    ACK 9b05507

Tree-SHA512: 856fb8b7dc2e743c9c67164023bf53faf8766079aeccc82a30c8b90c85920b31977b6a8b26e51e5485b20e445a3ca6ff806e701a53e95f70181ea30055e3528c
BigcoinBGC pushed a commit to BigcoinBGC/bigcoin that referenced this pull request Jun 30, 2026
4543a3b Squashed 'src/minisketch/' changes from ea8f66b1ea..d1bd01e189 (Hennadii Stepanov)

Pull request description:

  This PR updates the `minisketch` subtree to latest upstream, which includes:
      - bitcoin-core/minisketch#75
      - bitcoin-core/minisketch#98

ACKs for top commit:
  fanquake:
    ACK b10f193

Tree-SHA512: 856fb8b7dc2e743c9c67164023bf53faf8766079aeccc82a30c8b90c85920b31977b6a8b26e51e5485b20e445a3ca6ff806e701a53e95f70181ea30055e3528c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants