Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Add CMake buildsystem #75

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

hebasto
Copy link
Contributor

@hebasto hebasto commented Oct 20, 2022

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

Also an MSVC CI task has been added per feedback.

Autotools vs CMake configuration option parity:

Autotools CMake
--disable-ccache N/A
--enable-tests -DMINISKETCH_TESTS
--enable-benchmark -DMINISKETCH_BENCHMARK
--enable-fields -DMINISKETCH_FIELDS

Here is a examples of output when configuring:

  • for the "Ninja Multi-Config" generator:
$ cmake -B build -G "Ninja Multi-Config" -DMINISKETCH_BENCHMARK=ON -DMINISKETCH_FIELDS=42
-- The CXX compiler identification is GNU 13.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test HAVE_CLMUL
-- Performing Test HAVE_CLMUL - Success
-- Performing Test HAVE_CLZ
-- Performing Test HAVE_CLZ - Success


minisketch configure summary
============================
Library type .......................... Static
Build options:
  clmul fields ........................ ENABLED
  clz implementation .................. compiler builtin
Optional binaries:
  benchmark ........................... ON
  tests ............................... ON

Cross compiling ....................... FALSE
C++ compiler .......................... GNU 13.2.0, /usr/bin/c++
Available build configurations ........ Debug, Release, RelWithDebInfo
Default build configuration ........... Debug
'Debug' build configuration:
  C++ flags ........................... -g -Wall
'Release' build configuration:
  C++ flags ........................... -O3 -DNDEBUG -Wall
'RelWithDebInfo' build configuration:
  C++ flags ........................... -O2 -g -DNDEBUG -Wall

CMake Warning at CMakeLists.txt:117 (message):
  Only compiling in support for field sizes: 42

  This means the library will lack support for other field sizes entirely.



-- Configuring done (0.5s)
-- Generating done (0.0s)
-- Build files have been written to: /home/hebasto/git/minisketch/build
  • for the "Unix Makefiles" generator (the default on Linux):
$ cmake -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DMINISKETCH_BENCHMARK=ON -DMINISKETCH_FIELDS=42
-- The CXX compiler identification is GNU 13.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test HAVE_CLMUL
-- Performing Test HAVE_CLMUL - Success
-- Performing Test HAVE_CLZ
-- Performing Test HAVE_CLZ - Success


minisketch configure summary
============================
Library type .......................... Static
Build options:
  clmul fields ........................ ENABLED
  clz implementation .................. compiler builtin
Optional binaries:
  benchmark ........................... ON
  tests ............................... ON

Cross compiling ....................... FALSE
C++ compiler .......................... GNU 13.2.0, /usr/bin/c++
Build configuration ................... RelWithDebInfo
C++ flags ............................. -O2 -g -DNDEBUG -Wall

CMake Warning at CMakeLists.txt:117 (message):
  Only compiling in support for field sizes: 42

  This means the library will lack support for other field sizes entirely.



-- Configuring done (0.6s)
-- Generating done (0.0s)
-- Build files have been written to: /home/hebasto/git/minisketch/build

@hebasto
Copy link
Contributor Author

hebasto commented Oct 20, 2022

Chasing for Concept (N)ACKs...

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

hebasto commented Oct 23, 2022

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
Copy link
Contributor Author

hebasto commented Oct 31, 2022

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
Copy link
Contributor

theuni commented Mar 17, 2023

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
Copy link
Contributor

theuni commented Mar 31, 2023

@sipa Are you interested in CMake for this project?

@sipa
Copy link
Owner

sipa commented Mar 31, 2023

@theuni Yeah, will look soon.

@theuni
Copy link
Contributor

theuni commented Mar 31, 2023

@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
Copy link
Contributor Author

hebasto commented Apr 16, 2023

Imo this should be renamed "Add CMake buildsystem".

Done.

@sipa
Copy link
Owner

sipa commented Apr 11, 2024

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

@hebasto
Copy link
Contributor Author

hebasto commented Apr 11, 2024

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
Copy link
Contributor Author

hebasto commented Apr 16, 2024

Reworked.

The PR description has been updated.

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

endif()

if(MINGW)
add_link_options(-static)
Copy link
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.

Copy link
Contributor Author

@hebasto hebasto Apr 26, 2024

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
Contributor 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

src/CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
)

if(DEFINED CMAKE_CXX_STANDARD)
if(CMAKE_CXX_STANDARD EQUAL 98 OR CMAKE_CXX_STANDARD LESS 11)
Copy link
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
Contributor Author

Choose a reason for hiding this comment

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

Y2K problem :)

@hebasto
Copy link
Contributor Author

hebasto commented Apr 26, 2024

Addressed @theuni's comments.

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.

3 participants