Skip to content

Commit

Permalink
build: create Depends build type for depends and use it by default
Browse files Browse the repository at this point in the history
Rather than modifying the existing build types and adding flags for each,
create a new type specifically for depends.

This allows the forwarding of optional flags into the CMake build for the
"Depends" build type, but the user can now optionally use an existing
(Debug/RelWitDebInfo/etc.) type to ignore the optimization flags set by depends
and use the ones from that type instead.

As an example, a user may do:
make -C depends
cmake --toolchain depends/arm64-apple-darwin/toolchain.cmake -DCMAKE_BUILD_TYPE=Debug

This would compile depends with the default optimization flags for depends
(-O2) but build Core with the default optimization flags from CMake.
  • Loading branch information
theuni committed Jan 14, 2025
1 parent b446774 commit dc41d78
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 36 deletions.
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ unset(check_pie_output)
# It is a usage requirement for all targets except for secp256k1, which
# gets its flags by other means.
add_library(core_interface INTERFACE)
add_library(core_interface_relwithdebinfo INTERFACE)
add_library(core_interface_depends INTERFACE)
add_library(core_interface_debug INTERFACE)
target_link_libraries(core_interface INTERFACE
$<$<CONFIG:RelWithDebInfo>:core_interface_relwithdebinfo>
$<$<CONFIG:Debug>:core_interface_debug>
$<$<CONFIG:Depends>:core_interface_depends>
)

if(BUILD_FOR_FUZZING)
Expand Down Expand Up @@ -553,8 +553,7 @@ else()
endif()

target_compile_definitions(core_interface INTERFACE ${DEPENDS_COMPILE_DEFINITIONS})
target_compile_definitions(core_interface_relwithdebinfo INTERFACE ${DEPENDS_COMPILE_DEFINITIONS_RELWITHDEBINFO})
target_compile_definitions(core_interface_debug INTERFACE ${DEPENDS_COMPILE_DEFINITIONS_DEBUG})
target_compile_definitions(core_interface_depends INTERFACE ${DEPENDS_CONFIG_COMPILE_DEFINITIONS})

# If the {CXX,LD}FLAGS environment variables are defined during building depends
# and configuring this build system, their content might be duplicated.
Expand Down
12 changes: 4 additions & 8 deletions depends/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,13 @@ $(host_prefix)/toolchain.cmake : toolchain.cmake.in $(host_prefix)/.stamp_$(fina
-e 's|@OBJDUMP@|$(host_OBJDUMP)|' \
-e 's|@depends_prefix@|$(host_prefix)|' \
-e 's|@CFLAGS@|$(strip $(host_CFLAGS))|' \
-e 's|@CFLAGS_RELEASE@|$(strip $(host_release_CFLAGS))|' \
-e 's|@CFLAGS_DEBUG@|$(strip $(host_debug_CFLAGS))|' \
-e 's|@CFLAGS_DEPENDS_CONFIG@|$(strip $(host_$(release_type)_CFLAGS))|' \
-e 's|@CXXFLAGS@|$(strip $(host_CXXFLAGS))|' \
-e 's|@CXXFLAGS_RELEASE@|$(strip $(host_release_CXXFLAGS))|' \
-e 's|@CXXFLAGS_DEBUG@|$(strip $(host_debug_CXXFLAGS))|' \
-e 's|@CXXFLAGS_DEPENDS_CONFIG@|$(strip $(host_$(release_type)_CXXFLAGS))|' \
-e 's|@CPPFLAGS@|$(strip $(host_CPPFLAGS))|' \
-e 's|@CPPFLAGS_RELEASE@|$(strip $(host_release_CPPFLAGS))|' \
-e 's|@CPPFLAGS_DEBUG@|$(strip $(host_debug_CPPFLAGS))|' \
-e 's|@CPPFLAGS_DEPENDS_CONFIG@|$(strip $(host_$(release_type)_CPPFLAGS))|' \
-e 's|@LDFLAGS@|$(strip $(host_LDFLAGS))|' \
-e 's|@LDFLAGS_RELEASE@|$(strip $(host_release_LDFLAGS))|' \
-e 's|@LDFLAGS_DEBUG@|$(strip $(host_debug_LDFLAGS))|' \
-e 's|@LDFLAGS_DEPENDS_CONFIG@|$(strip $(host_$(release_type)_LDFLAGS))|' \
-e 's|@qt_packages@|$(qt_packages_)|' \
-e 's|@qrencode_packages@|$(qrencode_packages_)|' \
-e 's|@zmq_packages@|$(zmq_packages_)|' \
Expand Down
43 changes: 19 additions & 24 deletions depends/toolchain.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ if(@depends_crosscompiling@)
set(CMAKE_SYSTEM_PROCESSOR @host_arch@)
endif()

if(NOT SET_UP_CONFIGURATIONS_DONE)
set(SET_UP_CONFIGURATIONS_DONE TRUE)
list(APPEND CMAKE_CONFIGURATION_TYPES "Depends")
if(NOT CMAKE_BUILD_TYPE)
message("Defaulting to depends build.")
set(CMAKE_BUILD_TYPE Depends)
endif()
endif()

if(NOT DEFINED CMAKE_C_FLAGS_INIT)
set(CMAKE_C_FLAGS_INIT "@CFLAGS@")
endif()
if(NOT DEFINED CMAKE_C_FLAGS_RELWITHDEBINFO_INIT)
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "@CFLAGS_RELEASE@")
endif()
if(NOT DEFINED CMAKE_C_FLAGS_DEBUG_INIT)
set(CMAKE_C_FLAGS_DEBUG_INIT "@CFLAGS_DEBUG@")
if(NOT DEFINED CMAKE_C_FLAGS_DEPENDS_INIT)
set(CMAKE_C_FLAGS_DEPENDS_INIT "@CFLAGS_DEPENDS_CONFIG@")
endif()

if(NOT DEFINED CMAKE_C_COMPILER)
Expand All @@ -33,13 +39,9 @@ if(NOT DEFINED CMAKE_CXX_FLAGS_INIT)
set(CMAKE_CXX_FLAGS_INIT "@CXXFLAGS@")
set(CMAKE_OBJCXX_FLAGS_INIT "@CXXFLAGS@")
endif()
if(NOT DEFINED CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "@CXXFLAGS_RELEASE@")
set(CMAKE_OBJCXX_FLAGS_RELWITHDEBINFO_INIT "@CXXFLAGS_RELEASE@")
endif()
if(NOT DEFINED CMAKE_CXX_FLAGS_DEBUG_INIT)
set(CMAKE_CXX_FLAGS_DEBUG_INIT "@CXXFLAGS_DEBUG@")
set(CMAKE_OBJCXX_FLAGS_DEBUG_INIT "@CXXFLAGS_DEBUG@")
if(NOT DEFINED CMAKE_CXX_FLAGS_DEPENDS_INIT)
set(CMAKE_CXX_FLAGS_DEPENDS_INIT "@CXXFLAGS_DEPENDS_CONFIG@")
set(CMAKE_OBJCXX_FLAGS_DEPENDS_INIT "@CXXFLAGS_DEPENDS_CONFIG@")
endif()

if(NOT DEFINED CMAKE_CXX_COMPILER)
Expand All @@ -49,26 +51,19 @@ endif()

# The DEPENDS_COMPILE_DEFINITIONS* variables are to be treated as lists.
set(DEPENDS_COMPILE_DEFINITIONS @CPPFLAGS@)
set(DEPENDS_COMPILE_DEFINITIONS_RELWITHDEBINFO @CPPFLAGS_RELEASE@)
set(DEPENDS_COMPILE_DEFINITIONS_DEBUG @CPPFLAGS_DEBUG@)
set(DEPENDS_CONFIG_COMPILE_DEFINITIONS @CPPFLAGS_DEPENDS_CONFIG@)

if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_INIT)
set(CMAKE_EXE_LINKER_FLAGS_INIT "@LDFLAGS@")
endif()
if(NOT DEFINED CMAKE_SHARED_LINKER_FLAGS_INIT)
set(CMAKE_SHARED_LINKER_FLAGS_INIT "@LDFLAGS@")
endif()
if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT)
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "@LDFLAGS_RELEASE@")
endif()
if(NOT DEFINED CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT)
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT "@LDFLAGS_RELEASE@")
endif()
if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "@LDFLAGS_DEBUG@")
if(NOT DEFINED CMAKE_SHARED_LINKER_FLAGS_DEPENDS_INIT)
set(CMAKE_SHARED_LINKER_FLAGS_DEPENDS_INIT "@LDFLAGS_DEPENDS_CONFIG@")
endif()
if(NOT DEFINED CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT)
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT "@LDFLAGS_DEBUG@")
if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_DEPENDS_INIT)
set(CMAKE_EXE_LINKER_FLAGS_DEPENDS_INIT "@LDFLAGS_DEPENDS_CONFIG@")
endif()

set(CMAKE_AR "@AR@")
Expand Down

0 comments on commit dc41d78

Please sign in to comment.