summaryrefslogtreecommitdiff
path: root/infra/nnfw/CMakeLists.txt
blob: f2eb2f3ba1817b7fc1ec9eb1ce63abfe391f2cb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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)