@@ -114,6 +114,12 @@ add_library(core_interface INTERFACE)
114
114
# include the warn_interface as subtree's warnings are not fixable
115
115
# in our tree.
116
116
add_library (core_base_interface INTERFACE )
117
+ add_library (core_depends_release_interface INTERFACE )
118
+ add_library (core_depends_debug_interface INTERFACE )
119
+ target_link_libraries (core_base_interface INTERFACE
120
+ $<$<CONFIG:RelWithDebInfo>:${core_depends_release_interface} >
121
+ $<$<CONFIG:Debug>:${core_depends_debug_interface} >
122
+ )
117
123
target_link_libraries (core_interface INTERFACE core_base_interface)
118
124
119
125
if (FUZZ)
@@ -223,12 +229,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
223
229
try_append_linker_flag("-Wl,-headerpad_max_install_names" TARGET core_base_interface)
224
230
endif ()
225
231
226
- if (CMAKE_CROSSCOMPILING )
227
- target_compile_definitions (core_base_interface INTERFACE ${DEPENDS_COMPILE_DEFINITIONS} )
228
- target_compile_options (core_base_interface INTERFACE "$<$<COMPILE_LANGUAGE:C>:${DEPENDS_C_COMPILER_FLAGS} >" )
229
- target_compile_options (core_base_interface INTERFACE "$<$<COMPILE_LANGUAGE:CXX>:${DEPENDS_CXX_COMPILER_FLAGS} >" )
230
- endif ()
231
-
232
232
include (AddThreadsIfNeeded)
233
233
add_threads_if_needed()
234
234
@@ -280,10 +280,10 @@ include(cmake/leveldb.cmake)
280
280
include (cmake/minisketch.cmake)
281
281
include (cmake/secp256k1.cmake)
282
282
283
- string (STRIP " ${CMAKE_CXX_FLAGS} " cxx_flags )
284
- string (STRIP " ${CMAKE_CXX_FLAGS_INIT} " cxx_flags_init )
285
- if ( cxx_flags STREQUAL cxx_flags_init)
286
- # CMAKE_CXX_FLAGS are not overridden.
283
+ include (ProcessConfigurations )
284
+ are_flags_overridden( CMAKE_CXX_FLAGS cxx_flags_overridden )
285
+ # TODO: Rework after https://github.com/bitcoin/bitcoin/pull/25972.
286
+ if ( NOT cxx_flags_overridden AND NOT CMAKE_CROSSCOMPILING )
287
287
add_library (warn_interface INTERFACE )
288
288
target_link_libraries (core_interface INTERFACE warn_interface)
289
289
if (MSVC )
@@ -331,19 +331,17 @@ if(cxx_flags STREQUAL cxx_flags_init)
331
331
)
332
332
endif ()
333
333
endif ()
334
- unset (cxx_flags )
335
- unset (cxx_flags_init)
334
+ unset (cxx_flags_overridden)
336
335
337
- include (ProcessConfigurations)
338
336
set_default_config(RelWithDebInfo)
339
337
340
- # Redefine configuration flags.
341
- target_compile_definitions (core_base_interface INTERFACE
342
- $<$<CONFIG:Debug>: DEBUG>
343
- $<$<CONFIG:Debug>: DEBUG_LOCKORDER>
344
- $<$<CONFIG:Debug>: DEBUG_LOCKCONTENTION>
345
- $<$<CONFIG:Debug>: RPC_DOC_CHECK>
346
- $<$<CONFIG:Debug>: ABORT_ON_FAILED_ASSUME>
338
+ # Redefine/adjust per- configuration flags.
339
+ target_compile_definitions (core_depends_debug_interface INTERFACE
340
+ DEBUG
341
+ DEBUG_LOCKORDER
342
+ DEBUG_LOCKCONTENTION
343
+ RPC_DOC_CHECK
344
+ ABORT_ON_FAILED_ASSUME
347
345
)
348
346
# We leave assertions on.
349
347
if (MSVC )
@@ -353,20 +351,52 @@ else()
353
351
remove_c_flag_from_all_configs(-DNDEBUG)
354
352
remove_cxx_flag_from_all_configs(-DNDEBUG)
355
353
354
+ # Adjust flags used by the C/CXX compiler during RELEASE builds.
356
355
# Prefer -O2 optimization level. (-O3 is CMake's default for Release for many compilers.)
357
356
replace_c_flag_in_config(Release -O3 -O2)
358
357
replace_cxx_flag_in_config(Release -O3 -O2)
359
358
360
- set (debug_flags)
361
- try_append_cxx_flags("-O0" VAR debug_flags)
362
- try_append_cxx_flags("-g3" VAR debug_flags RESULT_VAR compiler_supports_g3)
363
- if (NOT compiler_supports_g3)
364
- try_append_cxx_flags("-g" VAR debug_flags)
359
+ are_flags_overridden(CMAKE_CXX_FLAGS_DEBUG cxx_flags_debug_overridden)
360
+ if (NOT cxx_flags_debug_overridden)
361
+ # Redefine flags used by the CXX compiler during DEBUG builds.
362
+ try_append_cxx_flags("-g3" RESULT_VAR compiler_supports_g3)
363
+ if (compiler_supports_g3)
364
+ replace_cxx_flag_in_config(Debug -g -g3)
365
+ endif ()
366
+
367
+ try_append_cxx_flags("-ftrapv" RESULT_VAR compiler_supports_ftrapv)
368
+ if (compiler_supports_ftrapv)
369
+ string (PREPEND CMAKE_CXX_FLAGS_DEBUG "-ftrapv " )
370
+ endif ()
371
+ unset (compiler_supports_ftrapv)
372
+
373
+ string (PREPEND CMAKE_CXX_FLAGS_DEBUG "-O0 " )
374
+
375
+ set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} "
376
+ CACHE STRING
377
+ "Flags used by the CXX compiler during DEBUG builds."
378
+ FORCE
379
+ )
365
380
endif ()
366
- set (CMAKE_C_FLAGS_DEBUG "${debug_flags} " )
367
- try_append_cxx_flags("-ftrapv" VAR debug_flags)
368
- set (CMAKE_CXX_FLAGS_DEBUG "${debug_flags} " )
369
- unset (debug_flags)
381
+ unset (cxx_flags_debug_overridden)
382
+
383
+ are_flags_overridden(CMAKE_C_FLAGS_DEBUG c_flags_debug_overridden)
384
+ if (NOT c_flags_debug_overridden)
385
+ # Redefine flags used by the C compiler during DEBUG builds.
386
+ if (compiler_supports_g3)
387
+ replace_c_flag_in_config(Debug -g -g3)
388
+ endif ()
389
+
390
+ string (PREPEND CMAKE_C_FLAGS_DEBUG "-O0 " )
391
+
392
+ set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} "
393
+ CACHE STRING
394
+ "Flags used by the C compiler during DEBUG builds."
395
+ FORCE
396
+ )
397
+ endif ()
398
+ unset (compiler_supports_g3)
399
+ unset (c_flags_debug_overridden)
370
400
endif ()
371
401
372
402
include (cmake/optional_qt.cmake)
@@ -452,6 +482,21 @@ else()
452
482
)
453
483
endif ()
454
484
485
+ if (CMAKE_CROSSCOMPILING )
486
+ target_compile_definitions (core_base_interface INTERFACE ${DEPENDS_COMPILE_DEFINITIONS} )
487
+ target_compile_definitions (core_depends_release_interface INTERFACE ${DEPENDS_COMPILE_DEFINITIONS_RELWITHDEBINFO} )
488
+ target_compile_definitions (core_depends_debug_interface INTERFACE ${DEPENDS_COMPILE_DEFINITIONS_DEBUG} )
489
+
490
+ # If {C,CXX}FLAGS variables are defined during building depends and
491
+ # configuring this build system, their content might be duplicated.
492
+ if (DEFINED ENV{CFLAGS})
493
+ deduplicate_flags(CMAKE_C_FLAGS)
494
+ endif ()
495
+ if (DEFINED ENV{CXXFLAGS})
496
+ deduplicate_flags(CMAKE_CXX_FLAGS )
497
+ endif ()
498
+ endif ()
499
+
455
500
add_subdirectory (src)
456
501
add_subdirectory (test )
457
502
@@ -462,9 +507,11 @@ setup_split_debug_script()
462
507
add_maintenance_targets()
463
508
add_windows_deploy_target()
464
509
510
+
465
511
include (GetTargetInterface)
466
512
get_target_interface(definitions core_interface COMPILE_DEFINITIONS )
467
- separate_by_configs(definitions )
513
+ get_target_interface(definitions_RELWITHDEBINFO core_depends_release_interface COMPILE_DEFINITIONS )
514
+ get_target_interface(definitions_DEBUG core_depends_debug_interface COMPILE_DEFINITIONS )
468
515
469
516
message ("\n " )
470
517
message ("Configure summary" )
@@ -500,15 +547,11 @@ else()
500
547
set (cross_status "FALSE" )
501
548
endif ()
502
549
message ("Cross compiling ....................... ${cross_status} " )
503
- message ("Preprocessor defined macros ........... ${definitions_ALL } " )
550
+ message ("Preprocessor defined macros ........... ${definitions } " )
504
551
message ("C compiler ............................ ${CMAKE_C_COMPILER} " )
505
- list (JOIN DEPENDS_C_COMPILER_FLAGS " " depends_c_flags)
506
- string (STRIP "${CMAKE_C_FLAGS} ${depends_c_flags} " combined_c_flags)
507
- message ("CFLAGS ................................ ${combined_c_flags} " )
552
+ message ("CFLAGS ................................ ${CMAKE_C_FLAGS} " )
508
553
message ("C++ compiler .......................... ${CMAKE_CXX_COMPILER} " )
509
- list (JOIN DEPENDS_CXX_COMPILER_FLAGS " " depends_cxx_flags)
510
- string (STRIP "${CMAKE_CXX_FLAGS} ${depends_cxx_flags} " combined_cxx_flags)
511
- message ("CXXFLAGS .............................. ${combined_cxx_flags} " )
554
+ message ("CXXFLAGS .............................. ${CMAKE_CXX_FLAGS} " )
512
555
get_target_interface(common_compile_options core_interface COMPILE_OPTIONS)
513
556
message ("Common compile options ................ ${common_compile_options} " )
514
557
get_target_interface(common_link_options core_interface LINK_OPTIONS)
0 commit comments