forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #10: build: Add CMake-based build system (4 of N)
b0351e3 [FIXUP] cmake: Rework PIC/PIE logic (Hennadii Stepanov) a8917ab cmake: Add cross-compiling support (Hennadii Stepanov) e5e6bd3 build: Generate `share/toolchain.cmake` in depends (Hennadii Stepanov) d37c9a2 [FIXUP] cmake: Ensure C language is disabled for FindThreads (Hennadii Stepanov) 3bb3448 [FIXUP] cmake: Enable C language for libsecp256k1 (Hennadii Stepanov) 75b9b6c [FIXUP] cmake: Drop C language from the global project (Hennadii Stepanov) Pull request description: #7 (comment): > So.. requesting a hookup to depends in the next PR please :) Delivered :) --- The parent PR: bitcoin#25797. The previous PRs in the staging branch: #5, #6, #7. --- EXAMPLES: Cross-compiling for Windows: ``` make -C depends HOST=x86_64-w64-mingw32 NO_QT=1 NO_WALLET=1 NO_ZMQ=1 NO_UPNP=1 NO_NATPMP=1 NO_USDT=1 cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=depends/x86_64-w64-mingw32/share/toolchain.cmake cmake --build build ``` Cross-compiling for macOS, arm64: ``` make -C depends HOST=arm64-apple-darwin NO_QT=1 NO_WALLET=1 NO_ZMQ=1 NO_UPNP=1 NO_NATPMP=1 NO_USDT=1 cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=depends/arm64-apple-darwin/share/toolchain.cmake cmake --build build ``` ACKs for top commit: theuni: ACK b0351e3, with the caveat that I hope we can make _significant_ changes to the `toolchain.cmake.in`. But I'm ok calling that a work-in-progress while the rest of the work is introduced to keep it from holding up review further. Tree-SHA512: 41e9925fb30766c61eca3506eed4b8a75701d0ba84c3077317266f73771eca50b14b40102e473b15d5f3f8eac7d87a19c5b27889cb6f350d089b3231b57c0991
- Loading branch information
Showing
7 changed files
with
224 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright (c) 2023 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
find_package(PkgConfig REQUIRED) | ||
|
||
macro(cross_pkg_check_modules) | ||
if(CMAKE_CROSSCOMPILING) | ||
set(pkg_config_path_saved "$ENV{PKG_CONFIG_PATH}") | ||
set(pkg_config_libdir_saved "$ENV{PKG_CONFIG_LIBDIR}") | ||
set(ENV{PKG_CONFIG_PATH} ${PKG_CONFIG_PATH}) | ||
set(ENV{PKG_CONFIG_LIBDIR} ${PKG_CONFIG_LIBDIR}) | ||
pkg_check_modules(${ARGV}) | ||
set(ENV{PKG_CONFIG_PATH} ${pkg_config_path_saved}) | ||
set(ENV{PKG_CONFIG_LIBDIR} ${pkg_config_libdir_saved}) | ||
else() | ||
pkg_check_modules(${ARGV}) | ||
endif() | ||
endmacro() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# This file is expected to be highly volatile and may still change substantially. | ||
|
||
set(CMAKE_SYSTEM_NAME @host_system@) | ||
set(CMAKE_SYSTEM_PROCESSOR @host_arch@) | ||
|
||
function(split_compiler_launcher env_compiler launcher compiler) | ||
set(${launcher}) | ||
list(GET ${env_compiler} 0 start_token) | ||
if(start_token STREQUAL "env") | ||
set(${compiler}) | ||
set(env_arg_parsing TRUE) | ||
foreach(token IN LISTS ${env_compiler}) | ||
if(env_arg_parsing) | ||
list(APPEND ${launcher} ${token}) | ||
set(env_arg_parsing FALSE) | ||
continue() | ||
elseif(token STREQUAL "-u") | ||
list(APPEND ${launcher} ${token}) | ||
set(env_arg_parsing TRUE) | ||
continue() | ||
endif() | ||
list(APPEND ${compiler} ${token}) | ||
endforeach() | ||
else() | ||
set(${compiler} ${${env_compiler}}) | ||
endif() | ||
set(${launcher} ${${launcher}} PARENT_SCOPE) | ||
set(${compiler} ${${compiler}} PARENT_SCOPE) | ||
endfunction() | ||
|
||
if(NOT CMAKE_C_COMPILER) | ||
set(DEPENDS_C_COMPILER_WITH_LAUNCHER @CC@) | ||
split_compiler_launcher(DEPENDS_C_COMPILER_WITH_LAUNCHER CMAKE_C_COMPILER_LAUNCHER CMAKE_C_COMPILER) | ||
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.21) | ||
set(CMAKE_C_LINKER_LAUNCHER ${CMAKE_C_COMPILER_LAUNCHER}) | ||
endif() | ||
if(CMAKE_VERSION VERSION_LESS 3.19) | ||
set(DEPENDS_C_COMPILER_FLAGS ${CMAKE_C_COMPILER}) | ||
list(REMOVE_AT DEPENDS_C_COMPILER_FLAGS 0) | ||
string(REPLACE ";" " " DEPENDS_C_COMPILER_FLAGS "${DEPENDS_C_COMPILER_FLAGS}") | ||
list(GET CMAKE_C_COMPILER 0 CMAKE_C_COMPILER) | ||
endif() | ||
endif() | ||
set(CMAKE_C_FLAGS_INIT "${DEPENDS_C_COMPILER_FLAGS} @CPPFLAGS@ @CFLAGS@") | ||
|
||
if(NOT CMAKE_CXX_COMPILER) | ||
set(DEPENDS_CXX_COMPILER_WITH_LAUNCHER @CXX@) | ||
split_compiler_launcher(DEPENDS_CXX_COMPILER_WITH_LAUNCHER CMAKE_CXX_COMPILER_LAUNCHER CMAKE_CXX_COMPILER) | ||
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.21) | ||
set(CMAKE_CXX_LINKER_LAUNCHER ${CMAKE_CXX_COMPILER_LAUNCHER}) | ||
endif() | ||
if(CMAKE_VERSION VERSION_LESS 3.19) | ||
set(DEPENDS_CXX_COMPILER_FLAGS ${CMAKE_CXX_COMPILER}) | ||
list(REMOVE_AT DEPENDS_CXX_COMPILER_FLAGS 0) | ||
string(REPLACE ";" " " DEPENDS_CXX_COMPILER_FLAGS "${DEPENDS_CXX_COMPILER_FLAGS}") | ||
list(GET CMAKE_CXX_COMPILER 0 CMAKE_CXX_COMPILER) | ||
endif() | ||
endif() | ||
set(CMAKE_CXX_FLAGS_INIT "${DEPENDS_CXX_COMPILER_FLAGS} @CPPFLAGS@ @CXXFLAGS@") | ||
|
||
if(NOT CMAKE_OBJCXX_COMPILER) | ||
set(DEPENDS_OBJCXX_COMPILER_WITH_LAUNCHER @CXX@) | ||
split_compiler_launcher(DEPENDS_OBJCXX_COMPILER_WITH_LAUNCHER CMAKE_OBJCXX_COMPILER_LAUNCHER CMAKE_OBJCXX_COMPILER) | ||
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.21) | ||
set(CMAKE_OBJCXX_LINKER_LAUNCHER ${CMAKE_OBJCXX_COMPILER_LAUNCHER}) | ||
endif() | ||
if(CMAKE_VERSION VERSION_LESS 3.19) | ||
set(DEPENDS_OBJCXX_COMPILER_FLAGS ${CMAKE_OBJCXX_COMPILER}) | ||
list(REMOVE_AT DEPENDS_OBJCXX_COMPILER_FLAGS 0) | ||
string(REPLACE ";" " " DEPENDS_OBJCXX_COMPILER_FLAGS "${DEPENDS_OBJCXX_COMPILER_FLAGS}") | ||
list(GET CMAKE_OBJCXX_COMPILER 0 CMAKE_OBJCXX_COMPILER) | ||
endif() | ||
endif() | ||
set(CMAKE_OBJCXX_FLAGS_INIT "${DEPENDS_OBJCXX_COMPILER_FLAGS} @CPPFLAGS@ @CXXFLAGS@") | ||
|
||
set(CMAKE_AR "@AR@") | ||
set(CMAKE_RANLIB "@RANLIB@") | ||
set(CMAKE_STRIP "@STRIP@") | ||
set(CMAKE_OBJCOPY "@OBJCOPY@") | ||
set(CMAKE_INSTALL_NAME_TOOL "@INSTALL_NAME_TOOL@") | ||
set(OTOOL "@OTOOL@") | ||
|
||
set(CMAKE_FIND_ROOT_PATH "@depends_prefix@") | ||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) | ||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) | ||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) | ||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) | ||
set(PKG_CONFIG_PATH "@depends_prefix@/lib/pkgconfig") | ||
if("@allow_host_packages@" STREQUAL "1") | ||
set(DEPENDS_ALLOW_HOST_PACKAGES TRUE) | ||
else() | ||
set(DEPENDS_ALLOW_HOST_PACKAGES FALSE) | ||
set(PKG_CONFIG_LIBDIR "${PKG_CONFIG_PATH}") | ||
endif() | ||
set(QT_TRANSLATIONS_DIR "@depends_prefix@/translations") | ||
|
||
if(NOT WITH_GUI AND "@no_qt@" STREQUAL "1") | ||
set(WITH_GUI "no" CACHE STRING "") | ||
endif() | ||
|
||
if(NOT WITH_QRENCODE AND "@no_qr@" STREQUAL "1") | ||
set(WITH_QRENCODE OFF CACHE STRING "") | ||
endif() | ||
|
||
if(NOT WITH_ZMQ AND "@no_zmq@" STREQUAL "1") | ||
set(WITH_ZMQ OFF CACHE STRING "") | ||
endif() | ||
|
||
if(NOT ENABLE_WALLET AND "@no_wallet@" STREQUAL "1") | ||
set(ENABLE_WALLET OFF CACHE BOOL "") | ||
endif() | ||
|
||
if(NOT WITH_BDB AND "@no_bdb@" STREQUAL "1") | ||
set(WITH_BDB OFF CACHE STRING "") | ||
endif() | ||
|
||
if(NOT WITH_SQLITE AND "@no_sqlite@" STREQUAL "1") | ||
set(WITH_SQLITE OFF CACHE STRING "") | ||
endif() | ||
|
||
if(NOT WITH_MINIUPNPC AND "@no_upnp@" STREQUAL "1") | ||
set(WITH_MINIUPNPC OFF CACHE STRING "") | ||
endif() | ||
|
||
if(NOT WITH_NATPMP AND "@no_natpmp@" STREQUAL "1") | ||
set(WITH_NATPMP OFF CACHE STRING "") | ||
endif() | ||
|
||
if(NOT WITH_USDT AND "@no_usdt@" STREQUAL "1") | ||
set(WITH_USDT OFF CACHE STRING "") | ||
endif() | ||
|
||
if(DEFINED ENV{PYTHONPATH}) | ||
set(PYTHONPATH "@depends_prefix@/native/lib/python3/dist-packages:$ENV{PYTHONPATH}") | ||
else() | ||
set(PYTHONPATH "@depends_prefix@/native/lib/python3/dist-packages") | ||
endif() |