diff options
Diffstat (limited to 'infra/nnfw/CMakeLists.txt')
-rw-r--r-- | infra/nnfw/CMakeLists.txt | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/infra/nnfw/CMakeLists.txt b/infra/nnfw/CMakeLists.txt new file mode 100644 index 000000000..f2eb2f3ba --- /dev/null +++ b/infra/nnfw/CMakeLists.txt @@ -0,0 +1,107 @@ +cmake_minimum_required(VERSION 3.5.1) + +project(nnfw) + +enable_testing() + +set(NNFW_EXTERNALS_DIR + "${CMAKE_CURRENT_LIST_DIR}/../../externals" CACHE + INTERNAL "Where to download external dependencies" +) +set(NNFW_OVERLAY_DIR "${CMAKE_BINARY_DIR}/overlay" CACHE + INTERNAL "Where locally built external dependencies are installed") + +# This allows find_package to access configurations installed inside overlay +list(APPEND CMAKE_PREFIX_PATH "${NNFW_OVERLAY_DIR}") + +macro(nnfw_include PREFIX) + include("${CMAKE_SOURCE_DIR}/cmake/modules/${PREFIX}.cmake") +endmacro(nnfw_include) + +# 'find_package()' wrapper to find in cmake/packages folder +# +# Example: +# nnfw_find_package(Boost): Load settings from 'BoostConfig.cmake' file +# - this may drop warnings like "-- Could NOT find Boost (missing: Boost_DIR) +# nnfw_find_package(Boost QUIET): Load settings silently, without warnings +# nnfw_find_package(Boost REQUIRED): Load settings but stop with error when failed +macro(nnfw_find_package PREFIX) + find_package(${PREFIX} CONFIG NO_DEFAULT_PATH PATHS ${CMAKE_SOURCE_DIR}/cmake/packages ${ARGN}) +endmacro(nnfw_find_package) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_EXTENSIONS OFF) + +# This feature works with CMake 3.5.2 or later. However, using previous versions does not produce +# an error. We are still officially using CMake 3.5.1, but put this code for the sake of semantic +# support in various development tools. +# Todo: Someday, CMake needs to be updated to 3.7.2 or later to take advantage of improvements +# such as `cmake-server`. +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# identify platform: HOST_PLATFORM, TARGET_PLATFORM and related +# note: this should be placed before flags and options setting +nnfw_include(IdentifyPlatform) + +# apply compilation flags +# note: this should be placed after cmake/option/option_xxx.cmake files +include("cmake/ApplyCompileFlags.cmake") + +# Configuration flags +include("cmake/CfgOptionFlags.cmake") +# and besides CfgOptionFlags.cmake that can be given outside +# COVERAGE_BUILD: build boolean flag that enables converage test +# ROOTFS_DIR: rootfs path for cross building +# TARGET_ARCH: target architecture string for cross building +# TARGET_OS: target os string for cross building + +nnfw_find_package(GTest QUIET) + +option(ENABLE_TEST "Build Tests using Google Test" ${GTest_FOUND}) + +if(${ENABLE_TEST} AND NOT ${GTest_FOUND}) + message(FATAL_ERROR "Google Test is required to enable test") +endif(${ENABLE_TEST} AND NOT ${GTest_FOUND}) + +if(${ENABLE_COVERAGE} AND NOT ${ENABLE_TEST}) + message(FATAL_ERROR "Test should be enabled to measure test coverage") +endif(${ENABLE_COVERAGE} AND NOT ${ENABLE_TEST}) + +add_library(nnfw_common INTERFACE) +if(ENABLE_STRICT_BUILD) + target_compile_options(nnfw_common INTERFACE -Werror -Wall -Wextra) +endif(ENABLE_STRICT_BUILD) + +# TODO Replace using default build option setting in cmake/buildtool/config/config_linux.cmake +# to link nnfw_coverage on each module which want to check coverage +add_library(nnfw_coverage INTERFACE) +if(ENABLE_COVERAGE) + target_compile_options(nnfw_coverage INTERFACE -g -O -DDEBUG -fprofile-arcs -ftest-coverage) + target_link_libraries(nnfw_coverage INTERFACE gcov) +endif(ENABLE_COVERAGE) + +nnfw_include(ExtendCMakeFunction) + +set(NNFW_SOURCE_ROOT "${CMAKE_SOURCE_DIR}/../..") + +add_library(nnfw-header INTERFACE) +target_include_directories(nnfw-header INTERFACE ${NNFW_SOURCE_ROOT}/runtimes/include) + +# TODO Support android build via fine-control for each component +# - Introduce BUILD_CONTRIB option +# - Set "BUILD_TFLITE_BENCHMARK_MODEL" as OFF for android build +# +# The original android build script (for future reference) +# +# add_subdirectory(libs) +# add_subdirectory(tests/tools/nnapi_test) +# add_subdirectory(tests/tools/tflite_benchmark) +# add_subdirectory(tests/nnapi) +# +# add_subdirectory(runtimes) + +add_subdirectory(${NNFW_SOURCE_ROOT}/runtimes/contrib contrib) +add_subdirectory(${NNFW_SOURCE_ROOT}/runtimes/libs libs) +add_subdirectory(${NNFW_SOURCE_ROOT}/runtimes runtimes) +add_subdirectory(${NNFW_SOURCE_ROOT}/tests tests) +add_subdirectory(${NNFW_SOURCE_ROOT}/tools tools) |