1

One of my project is build by gn+ninja. I want to use flat buffer https://github.com/dvidelabs/flatcc, but it is written in cmake.

Because my project should build on old red hat 6, there is no proper cmake version to build flatcc. What's the better method to import it as part of my project's sub-directory, and use gn to build.

Daniel YC Lin
  • 15,050
  • 18
  • 63
  • 96

1 Answers1

0

See my answer here: https://stackoverflow.com/a/63326374/12529885

If there are .so binary files, using script above, otherwise it can only using static_library or shared_library to import as a source-code-target.

For example

# RocksDB 
#--------------------------
import("//gn_build/platform_support.gni") ## variable SSE42 here. 

config("rocksdb_export") {
    include_dirs = ["rocksdb/include"]
    visibility = [":rocksdb"]
}
config("rocksdb_build") {
    defines = [
        "ROCKSDB_SUPPORT_THREAD_LOCAL",  # HAVE_THREAD_LOCAL
        # "NUMA",  # build with NUMA policy support(numactl-devel)
        "TBB",   # build with Threading Building Blocks (TBB)
        "ROCKSDB_USE_RTTI",
        "ZSTD",
        "GFLAGS=1"
    ]

    if (is_win) {
        defines += ["ROCKSDB_WINDOWS_UTF8_FILENAMES", "WIN32", "OS_WIN", "_MBCS", "WIN64", "NOMINMAX"]
        # defines += ["ROCKSDB_DLL", "ROCKSDB_LIBRARY_EXPORTS"]
        libs = ["shlwapi.lib", "rpcrt4.lib"]
        cflags_cc = ["/wd4127", "/wd4800", "/wd4996", 
            "/wd4351", "/wd4100", "/wd4204", "/wd4324"]
    }else {
        defines += ["ROCKSDB_PLATFORM_POSIX", "ROCKSDB_LIB_IO_POSIX"]
    }

    if (is_linux) {
        defines += [
            "OS_LINUX",
            "ROCKSDB_PTHREAD_ADAPTIVE_MUTEX",
            "ROCKSDB_SCHED_GETCPU_PRESENT",
            "ROCKSDB_AUXV_GETAUXVAL_PRESENT",
            "ROCKSDB_RANGESYNC_PRESENT",
        ]
        if (!is_llvm) {
            cflags_cc = ["-fno-builtin-memcmp"]
        }
    }

    if (SSE42) {
        defines += ["HAVE_SSE42", "HAVE_PCLMUL"]
    }

    include_dirs = ["rocksdb"]
}

static_library("rocksdb") {
    configs += [":rocksdb_build"]
    slist = read_file("rocksdb-master.gn_helper", "scope")

    base = "rocksdb"
    include_dirs = ["$base"]
    sources = slist.SOURCES
    base_pth = rebase_path("$base")
    
    if (is_win) {
        sources += slist.PORTWIN32
    }

    if (is_linux) {
        sources += slist.PORTLINUX
    }

    #Enable folly mutex
    include_dirs += ["$base/third-party/folly"]
    sources += slist.FOLLY_DISTRIBUTED_MUTEX
    #End folly mutex

    deps = [":zstd_static", ":gflags"]
    public_deps = [":tbb"]
    public_configs = [":rocksdb_export"]
}

file rocksdb-master.gn_helper

SOURCES = [
    "rocksdb/cache/cache.cc",
    "rocksdb/cache/clock_cache.cc",
    ...
]

PORTWIN32 = [
    "rocksdb/port/win/io_win.cc",
    "rocksdb/port/win/env_win.cc",
    ...
]
...
vrqq
  • 448
  • 3
  • 8