@@ -442,68 +442,46 @@ add_library(Halide
442
442
443
443
# Build serialization, enabled by default
444
444
option (WITH_SERIALIZATION "Include experimental Serialization/Deserialization code" ON )
445
-
446
- # flatbuffers is small and compiles quickly, but if you want/need to use
447
- # a local version (via find_package), configure with FLATBUFFERS_USE_FETCHCONTENT=OFF
448
- option (FLATBUFFERS_USE_FETCHCONTENT "Enable to download the Flatbuffers library via FetchContent" ON )
449
- set (FLATBUFFERS_VER 23.5.26 CACHE STRING "The Flatbuffers version to use (or download)" )
450
-
451
445
if (WITH_SERIALIZATION )
446
+ # flatbuffers is small and compiles quickly, but if you want/need to use
447
+ # a local version (via find_package), configure with FLATBUFFERS_USE_FETCHCONTENT=OFF
448
+ option (FLATBUFFERS_USE_FETCHCONTENT "Enable to download the Flatbuffers library via FetchContent" ON )
449
+ set (FLATBUFFERS_VER 23.5.26 CACHE STRING "The Flatbuffers version to use (or download) " )
450
+
452
451
if (FLATBUFFERS_USE_FETCHCONTENT )
453
452
include (FetchContent )
454
- message (STATUS "Fetching flatbuffers ${FLATBUFFERS_VER} ..." )
455
453
FetchContent_Declare (
456
454
flatbuffers
457
455
GIT_REPOSITORY https://github.com/google/flatbuffers.git
458
456
GIT_TAG v${FLATBUFFERS_VER}
459
457
GIT_SHALLOW TRUE
458
+ SYSTEM
460
459
)
461
460
# configuration for flatbuffers
462
461
set (FLATBUFFERS_BUILD_TESTS OFF )
463
462
set (FLATBUFFERS_INSTALL OFF )
464
463
FetchContent_MakeAvailable (flatbuffers )
465
464
set_target_properties (flatbuffers PROPERTIES POSITION_INDEPENDENT_CODE ON )
466
465
467
- add_library (Halide_flatbuffers INTERFACE )
468
- target_sources (Halide_flatbuffers INTERFACE $< BUILD_INTERFACE:$< TARGET_OBJECTS:flatbuffers> > )
469
- target_include_directories (Halide_flatbuffers
470
- SYSTEM # Use -isystem instead of -I; this is a trick so that clang-tidy won't analyze these includes
471
- INTERFACE
472
- $< BUILD_INTERFACE:${flatbuffers_SOURCE_DIR} > /include
473
- $< BUILD_INTERFACE:${flatbuffers_BINARY_DIR} > /include )
474
- set_target_properties (Halide_flatbuffers PROPERTIES EXPORT_NAME flatbuffers )
475
-
466
+ add_library (flatbuffers::flatbuffers ALIAS flatbuffers )
476
467
add_executable (flatbuffers::flatc ALIAS flatc )
468
+
477
469
message (STATUS "Using fetched-and-built flatbuffers, version ${FLATBUFFERS_VER} " )
470
+ set (flatbuffers_target "$<BUILD_LOCAL_INTERFACE:flatbuffers::flatbuffers>" )
478
471
else ()
479
- # Sadly, there seem to be at least three variations of the Flatbuffer package
480
- # in terms of the case of the relevant CMake files; if we guess wrong, we
481
- # fail on case-sensitive file systems. We'll try this as a hack workaround:
482
- # just try all three. (Note that the internal CMake library name appears to be
483
- # `flatbuffers` in all cases.)
484
- set (FB_NAME "" )
485
- foreach (N IN ITEMS flatbuffers Flatbuffers FlatBuffers )
486
- # TODO: should we check the version here?
487
- find_package (${N} QUIET )
488
- if (${N} _FOUND )
489
- set (FB_NAME ${N} )
490
- message (STATUS "Using installed flatbuffers, version ${${N} _VERSION}" )
491
- break ()
492
- endif ()
493
- endforeach ()
494
-
495
- if (NOT FB_NAME )
496
- message (FATAL_ERROR "WITH_SERIALIZATION is ON and FLATBUFFERS_USE_FETCHCONTENT is OFF, "
497
- "but could not find flatbuffers installed locally. "
498
- "Either install flatbuffers or build with WITH_SERIALIZATION=OFF." )
499
- endif ()
500
-
501
- add_library (Halide_flatbuffers ALIAS flatbuffers::flatbuffers )
472
+ # Sadly, there seem to be at least three variations of the Flatbuffer
473
+ # package in terms of the case of the relevant CMake files. Fortunately,
474
+ # the IMPORTED targets appear to be consistently named `flatbuffers`.
475
+ find_package (
476
+ flatbuffers ${FLATBUFFERS_VER}
477
+ NAMES flatbuffers Flatbuffers FlatBuffers
478
+ REQUIRED
479
+ )
480
+ set (flatbuffers_target flatbuffers::flatbuffers )
502
481
endif ()
503
482
504
- set (fb_dir "${Halide_BINARY_DIR} /flatc/include" )
505
-
506
483
set (fb_def "${CMAKE_CURRENT_SOURCE_DIR} /halide_ir.fbs" )
484
+ set (fb_dir "${Halide_BINARY_DIR} /include/flatc" )
507
485
set (fb_header "${fb_dir} /halide_ir.fbs.h" )
508
486
add_custom_command (
509
487
OUTPUT "${fb_header} "
@@ -512,21 +490,21 @@ if (WITH_SERIALIZATION)
512
490
VERBATIM
513
491
)
514
492
add_custom_target (generate_fb_header DEPENDS "${fb_header} " )
515
- set_source_files_properties ("${fb_header} " PROPERTIES GENERATED TRUE )
516
493
517
494
add_dependencies (Halide generate_fb_header )
518
495
target_include_directories (Halide PRIVATE "$<BUILD_INTERFACE:${fb_dir} >" )
519
- target_link_libraries (Halide PRIVATE Halide_flatbuffers )
496
+ target_link_libraries (Halide PRIVATE ${flatbuffers_target} )
520
497
target_compile_definitions (Halide PRIVATE WITH_SERIALIZATION )
521
498
endif ()
522
499
523
500
# Enable serialization testing by intercepting JIT compilation with a serialization roundtrip;
524
501
# This is used only for special builds made specifically for testing, and must be disabled by default.
525
- option (WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING "Intercepting JIT compilation with a serialization roundtrip, for test only" OFF )
502
+ cmake_dependent_option (
503
+ WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING "Intercepting JIT compilation with a serialization roundtrip, for test only" OFF
504
+ "WITH_SERIALIZATION" OFF
505
+ )
526
506
if (WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING )
527
- if (WITH_SERIALIZATION )
528
- target_compile_definitions (Halide PRIVATE WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING )
529
- endif ()
507
+ target_compile_definitions (Halide PRIVATE WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING )
530
508
endif ()
531
509
532
510
add_library (Halide::Halide ALIAS Halide )
0 commit comments