Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / runtime / onert / core / CMakeLists.txt
1 file(GLOB_RECURSE SOURCES "src/*.cc")
2 file(GLOB_RECURSE TESTS "*.test.cc")
3 list(REMOVE_ITEM SOURCES ${TESTS})
4
5 if(NOT BUILD_MINMAX_H5DUMPER)
6   file(GLOB_RECURSE SRC_TO_REMOVE "src/dumper/h5/*.cc")
7   list(REMOVE_ITEM SOURCES ${SRC_TO_REMOVE})
8   file(GLOB_RECURSE SRC_TO_REMOVE "src/exec/MinMaxRecorder.cc")
9   list(REMOVE_ITEM SOURCES ${SRC_TO_REMOVE})
10 endif(NOT BUILD_MINMAX_H5DUMPER)
11
12 if(NOT ENABLE_ONERT_TRAIN)
13   file(GLOB_RECURSE SRC_TRAIN "src/*/train/*.cc")
14   list(REMOVE_ITEM SOURCES ${SRC_TRAIN})
15   file(GLOB_RECURSE SRC_TRAIN "src/*/*/train/*.cc")
16   list(REMOVE_ITEM SOURCES ${SRC_TRAIN})
17 endif(NOT ENABLE_ONERT_TRAIN)
18
19 add_library(onert_core SHARED ${SOURCES})
20 set_target_properties(onert_core PROPERTIES POSITION_INDEPENDENT_CODE ON)
21
22 # NOTE
23 # We publish public headers into developer package.
24 # To avoid mistake using private header in public header, do not define
25 # private target_include_directories scope for src/ directory.
26 target_include_directories(onert_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
27
28 target_link_libraries(onert_core PRIVATE jsoncpp half)
29 target_link_libraries(onert_core PRIVATE nnfw_lib_misc nnfw_lib_cker)
30 target_link_libraries(onert_core PRIVATE nnfw_common)
31 target_link_libraries(onert_core PRIVATE nnfw_coverage)
32 target_link_libraries(onert_core PRIVATE dl ${LIB_PTHREAD})
33
34 # Ruy
35 nnfw_find_package(Ruy REQUIRED)
36 target_link_libraries(onert_core PRIVATE ruy)
37 target_link_libraries(onert_core INTERFACE ruy_instrumentation)
38
39 # H5 Minmax Dumper
40 if(BUILD_MINMAX_H5DUMPER)
41   nnfw_find_package(HDF5 REQUIRED)
42   target_compile_definitions(onert_core PRIVATE MINMAX_H5DUMPER=1)
43   target_include_directories(onert_core PRIVATE ${HDF5_INCLUDE_DIRS})
44   target_link_libraries(onert_core PRIVATE ${HDF5_CXX_LIBRARIES})
45 endif(BUILD_MINMAX_H5DUMPER)
46
47 # Training feature
48 # Use public to use this flag on all modules and tests
49 if(ENABLE_ONERT_TRAIN)
50   target_compile_definitions(onert_core PUBLIC ONERT_TRAIN)
51 endif(ENABLE_ONERT_TRAIN)
52
53 if(CMAKE_BUILD_TYPE_LC STREQUAL "release")
54   add_custom_command(TARGET onert_core POST_BUILD
55                      COMMAND ${CMAKE_STRIP} "--strip-unneeded" $<TARGET_FILE_NAME:onert_core>)
56 endif()
57
58 # NOTE Below line is added to remove warning for android build
59 #      It will be removed after android build uses gold linker
60 if (ANDROID)
61   target_link_libraries(onert_core INTERFACE log)
62 endif (ANDROID)
63
64 if(ENVVAR_ONERT_CONFIG)
65   target_compile_definitions(onert_core PRIVATE ENVVAR_FOR_DEFAULT_CONFIG)
66 endif(ENVVAR_ONERT_CONFIG)
67
68 install(TARGETS onert_core LIBRARY DESTINATION lib)
69 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/"
70         DESTINATION "include/onert"
71         FILES_MATCHING PATTERN "*.h" PATTERN "*.lst"
72         )
73
74 if(NOT ENABLE_TEST)
75   return()
76 endif(NOT ENABLE_TEST)
77
78 # Unit Tests
79 set(TEST_ONERT_CORE test_onert_core)
80
81 add_executable(${TEST_ONERT_CORE} ${TESTS})
82
83 target_link_libraries(${TEST_ONERT_CORE} onert_core)
84 # Requires linking nnfw_coverage: check header coverage
85 target_link_libraries(${TEST_ONERT_CORE} nnfw_coverage)
86 target_link_libraries(${TEST_ONERT_CORE} gtest gtest_main dl ${LIB_PTHREAD})
87
88 add_test(${TEST_ONERT_CORE} ${TEST_ONERT_CORE})
89 install(TARGETS ${TEST_ONERT_CORE} DESTINATION unittest)