-
Notifications
You must be signed in to change notification settings - Fork 57
build: Introduce CMake-based build system #75
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
Conversation
Chasing for Concept (N)ACKs... |
bd57926
to
14503b1
Compare
14503b1
to
30fdfb3
Compare
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:
Although, those features are not required for this PR goal, i.e., providing a native Windows CI task. |
30fdfb3
to
5851544
Compare
5851544
to
d2408e0
Compare
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. |
@sipa Are you interested in CMake for this project? |
@theuni Yeah, will look soon. |
Done. |
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. |
66b4133
to
b486457
Compare
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
) | ||
|
||
if(DEFINED CMAKE_CXX_STANDARD) | ||
if(CMAKE_CXX_STANDARD EQUAL 98 OR CMAKE_CXX_STANDARD LESS 11) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah! Stupid CMake :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Y2K problem :)
Addressed @theuni's comments. |
What is the status here? |
I'll push an update shortly. |
.github/workflows/ci.yml
Outdated
# TODO: Resolve the issue and re-enable benchmark. | ||
skip_benchmark: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue has been fixed in #96.
|
||
add_subdirectory(fields) | ||
|
||
add_compile_definitions($<$<BOOL:${HAVE_CLZ}>:HAVE_CLZ>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of attaching CLMUL to the fields interface, how about handling it here?
set_source_files_properties(minisketch.cpp PROPERTIES COMPILE_DEFINITIONS $<$<BOOL:${HAVE_CLMUL}>:HAVE_CLMUL>)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was to keep all HAVE_CLMUL
-related code local.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it seems a good bit more straightforward to me to drop the fields/
subdir and just include that logic here:
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d8e4fde..cae8228 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,13 +1,42 @@
include(GNUInstallDirs)
-add_subdirectory(fields)
-
add_compile_definitions($<$<BOOL:${HAVE_CLZ}>:HAVE_CLZ>)
add_library(minisketch minisketch.cpp)
target_include_directories(minisketch INTERFACE
$<BUILD_INTERFACE:$<$<NOT:$<BOOL:${PROJECT_IS_TOP_LEVEL}>>:${PROJECT_SOURCE_DIR}/include>>
)
+
+add_library(minisketch_field_sources INTERFACE)
+target_sources(minisketch_field_sources
+ INTERFACE
+ fields/generic_1byte.cpp
+ fields/generic_2bytes.cpp
+ fields/generic_3bytes.cpp
+ fields/generic_4bytes.cpp
+ fields/generic_5bytes.cpp
+ fields/generic_6bytes.cpp
+ fields/generic_7bytes.cpp
+ fields/generic_8bytes.cpp
+)
+
+set(clmul_sources
+ fields/clmul_1byte.cpp
+ fields/clmul_2bytes.cpp
+ fields/clmul_3bytes.cpp
+ fields/clmul_4bytes.cpp
+ fields/clmul_5bytes.cpp
+ fields/clmul_6bytes.cpp
+ fields/clmul_7bytes.cpp
+ fields/clmul_8bytes.cpp
+)
+
+if(HAVE_CLMUL)
+ set_source_files_properties(minisketch.cpp PROPERTIES COMPILE_DEFINITIONS HAVE_CLMUL)
+ set_source_files_properties(${clmul_sources} PROPERTIES COMPILE_OPTIONS ${CLMUL_CXXFLAGS})
+ target_sources(minisketch_field_sources INTERFACE ${clmul_sources})
+endif()
+
target_link_libraries(minisketch PRIVATE minisketch_field_sources)
add_library(minisketch_verify EXCLUDE_FROM_ALL minisketch.cpp)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Your suggestion has been taken with reordering to keep code specific to each target as local as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced set_source_files_properties
back with set_property(SOURCE ...)
as the latter accepts empty property value, which is the case for CLMUL_CXXFLAGS
on Windows.
Otherwise, see https://github.com/hebasto/minisketch/actions/runs/15404712059.
3170353
to
77bfe3b
Compare
The PR has been updated to improve integration with downstream projects and now makes use of 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 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 cc @theuni |
# Prevent include directories from parent project from leaking into this one. | ||
set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES "") |
There was a problem hiding this comment.
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 "")
Pushed some improvements basing on @ryanofsky's bitcoin-core/libmultiprocess@6adbb1d and offline discussions with @purpleKarrot.
|
85d6f32
to
0d6e8ac
Compare
The feedback from @purpleKarrot has been addressed.
|
@hebasto, I think you accidentally based your latest change on an older revision. A few changes got reverted. |
#============================= | ||
# Build Options | ||
#============================= | ||
set(CMAKE_CXX_VISIBILITY_PRESET hidden) |
There was a problem hiding this comment.
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.
Further feedback from @purpleKarrot has been addressed. The corresponding Bitcoin Core branch that integrates the new build system is available here.
Should be OK now. |
ACK 850cc86 |
There was a problem hiding this comment.
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.
Weakly-tested ACK 850cc86 |
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
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
--disable-ccache
--enable-tests
-DMINISKETCH_BUILD_TESTS
--enable-benchmark
-DMINISKETCH_BUILD_BENCHMARK
--enable-fields=,-separated list
-DMINISKETCH_FIELDS=;-separated list
-DMINISKETCH_INSTALL
Notes on the implementation
The default
CMAKE_BUILD_TYPE
is left unset.CMake's per-configuration compiler flags are not modified. As a result, they may include
-DNDEBUG
.The target name
test
is reserved. Therefore, the testing binary has been renamed totest-noverify
. Alternatively, following the naming used in thelibsecp256k1
repo, the test binaries could be renamed as:test
-->noverify_tests
test-verify
-->verify_tests