1 # NOTE find_package try to use at least python3.8 as follows depending on platform version
2 # Ubuntu18.04; explictly installed python3.8 (default is python3.6)
3 # Ubuntu20.04; default python3.8
4 # Ubuntu22.04; default python3.10
5 # refer https://github.com/Samsung/ONE/issues/9962
6 find_package(PythonInterp 3.8 QUIET)
7 find_package(PythonLibs 3.8 QUIET)
9 if(NOT ${PYTHONINTERP_FOUND})
10 message(STATUS "Build one-cmds: FALSE (Python3 is missing)")
14 if(${PYTHON_VERSION_MINOR} LESS 8)
15 message(STATUS "Build one-cmds: FALSE (You need to install Python version higher than 3.8)")
19 # NOTE these files should not have extensions.
20 # below code will remove extension when copy and install.
38 # TODO find better way for per-platform files
39 if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64")
40 # NOTE copy one-prepare-venv.aarch64 as build/../one-prepare-venv
41 # and install build/../one-prepare-venv file
42 list(APPEND ONE_COMMAND_FILES one-prepare-venv.aarch64)
43 else(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64")
44 if(ONE_UBUNTU_CODENAME_BIONIC)
45 # NOTE copy one-prepare-venv.u1804 as build/../one-prepare-venv
46 # and install build/../one-prepare-venv file
47 list(APPEND ONE_COMMAND_FILES one-prepare-venv.u1804)
48 else(ONE_UBUNTU_CODENAME_BIONIC)
49 list(APPEND ONE_COMMAND_FILES one-prepare-venv)
50 endif(ONE_UBUNTU_CODENAME_BIONIC)
51 endif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64")
53 # pytorch importer is an experimental feature, it is not used in default configuration
54 if(ENABLE_ONE_IMPORT_PYTORCH)
55 list(APPEND ONE_COMMAND_FILES one-import-pytorch)
56 endif(ENABLE_ONE_IMPORT_PYTORCH)
58 foreach(ONE_COMMAND IN ITEMS ${ONE_COMMAND_FILES})
60 set(ONE_COMMAND_FILE ${ONE_COMMAND})
61 set(ONE_COMMAND_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${ONE_COMMAND_FILE}")
62 # strip extension from the name
63 get_filename_component(ONE_COMMNAD_FILE_NAME ${ONE_COMMAND} NAME_WE)
64 set(ONE_COMMAND_BIN "${CMAKE_CURRENT_BINARY_DIR}/${ONE_COMMNAD_FILE_NAME}")
65 set(ONE_COMMAND_TARGET "${ONE_COMMAND}_target")
67 add_custom_command(OUTPUT ${ONE_COMMAND_BIN}
68 COMMAND ${CMAKE_COMMAND} -E copy "${ONE_COMMAND_SRC}" "${ONE_COMMAND_BIN}"
69 DEPENDS ${ONE_COMMAND_SRC}
70 COMMENT "Generate ${ONE_COMMAND_BIN}"
73 add_custom_target(${ONE_COMMAND_TARGET} ALL DEPENDS ${ONE_COMMAND_BIN})
75 install(FILES ${ONE_COMMAND_BIN}
76 PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE
77 GROUP_READ GROUP_EXECUTE
78 WORLD_READ WORLD_EXECUTE
81 endforeach(ONE_COMMAND)
84 one-build.template.cfg
89 foreach(ONE_UTILITY IN ITEMS ${ONE_UTILITY_FILES})
91 set(ONE_UTILITY_FILE ${ONE_UTILITY})
92 set(ONE_UTILITY_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${ONE_UTILITY_FILE}")
93 set(ONE_UTILITY_BIN "${CMAKE_CURRENT_BINARY_DIR}/${ONE_UTILITY_FILE}")
94 set(ONE_UTILITY_TARGET "${ONE_UTILITY}_target")
96 add_custom_command(OUTPUT ${ONE_UTILITY_BIN}
97 COMMAND ${CMAKE_COMMAND} -E copy "${ONE_UTILITY_SRC}" "${ONE_UTILITY_BIN}"
98 DEPENDS ${ONE_UTILITY_SRC}
99 COMMENT "Generate ${ONE_UTILITY_BIN}"
102 add_custom_target(${ONE_UTILITY_TARGET} ALL DEPENDS ${ONE_UTILITY_BIN})
104 install(FILES ${ONE_UTILITY}
105 PERMISSIONS OWNER_WRITE OWNER_READ
110 endforeach(ONE_UTILITY)
112 # one-pack internally uses model2nnpkg tool
113 set(MODEL2NNPKG "${NNAS_PROJECT_SOURCE_DIR}/tools/nnpackage_tool/model2nnpkg/model2nnpkg.py")
114 install(FILES ${MODEL2NNPKG}
115 PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE
116 GROUP_READ GROUP_EXECUTE
117 WORLD_READ WORLD_EXECUTE
119 RENAME "model2nnpkg")
121 # make python directory
122 set(ONE_PYTHON_FILES backends.py
128 TopologicalSortHelper.py
132 foreach(ONE_PYTHON_FILE IN ITEMS ${ONE_PYTHON_FILES})
134 set(ONE_PYTHON_DIR "onelib")
135 set(ONE_PYTHON_DIR_BIN "${CMAKE_CURRENT_BINARY_DIR}/${ONE_PYTHON_DIR}")
136 set(ONE_PYTHON_FILE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${ONE_PYTHON_DIR}/${ONE_PYTHON_FILE}")
137 set(ONE_PYTHON_FILE_BIN "${CMAKE_CURRENT_BINARY_DIR}/${ONE_PYTHON_DIR}/${ONE_PYTHON_FILE}")
138 set(ONE_PYTHON_TARGET "${ONE_PYTHON_FILE}_target")
140 add_custom_command(OUTPUT ${ONE_PYTHON_DIR_BIN}
141 COMMAND ${CMAKE_COMMAND} -E make_directory "${ONE_PYTHON_DIR_BIN}"
142 COMMENT "Generate ${ONE_PYTHON_DIR_BIN}"
145 add_custom_command(OUTPUT ${ONE_PYTHON_FILE_BIN}
146 COMMAND ${CMAKE_COMMAND} -E copy "${ONE_PYTHON_FILE_SRC}" "${ONE_PYTHON_FILE_BIN}"
147 DEPENDS ${ONE_PYTHON_SRC}
148 COMMENT "Generate ${ONE_PYTHON_FILE_BIN}"
151 add_custom_target(${ONE_PYTHON_TARGET} ALL DEPENDS ${ONE_PYTHON_DIR_BIN} ${ONE_PYTHON_FILE_BIN})
153 install(DIRECTORY ${ONE_PYTHON_DIR}
154 FILE_PERMISSIONS OWNER_WRITE OWNER_READ
159 endforeach(ONE_PYTHON_FILE)
161 set(CONSTANT_EXPORTING_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/${ONE_PYTHON_DIR}/export_constant.py")
163 set(O1_CFG_FILE "${O1_OPTION}.cfg")
164 set(O1_CFG_FILE_BIN "${CMAKE_CURRENT_BINARY_DIR}/${ONE_PYTHON_DIR}/${O1_CFG_FILE}")
166 add_custom_command(OUTPUT ${O1_CFG_FILE_BIN}
167 COMMAND ${PYTHON_EXECUTABLE} ${CONSTANT_EXPORTING_SCRIPT}
168 --constant ${O1_OPTION}
170 --output_path ${O1_CFG_FILE_BIN}
171 DEPENDS ${CONSTANT_EXPORTING_SCRIPT}
172 COMMENT "Generate ${O1_CFG_FILE}"
175 add_custom_target("O1_cfg_target" ALL DEPENDS ${O1_CFG_FILE_BIN})
177 install(FILES ${O1_CFG_FILE_BIN}
178 PERMISSIONS OWNER_WRITE OWNER_READ
181 DESTINATION optimization)
183 set(ONE_DOCUMENT_FILES
184 how-to-use-one-commands.txt
185 how-to-prepare-virtualenv.txt
186 how-to-create-hdf5-dataset.txt
189 foreach(ONE_DOCUMENT IN ITEMS ${ONE_DOCUMENT_FILES})
191 install(FILES ${ONE_DOCUMENT} DESTINATION doc)
193 endforeach(ONE_DOCUMENT)
197 endif(NOT ENABLE_TEST)
199 add_subdirectory(dummy-driver)
200 add_subdirectory(tests)
201 add_subdirectory(validate-onnx2circle)