1
- cmake_minimum_required (VERSION 3.1 )
1
+ cmake_minimum_required (VERSION 3.22 )
2
2
3
3
# For std::filesystem
4
4
# Must be a cache variable and be set before project()
@@ -12,21 +12,17 @@ set(CMAKE_CXX_STANDARD 17)
12
12
13
13
set (CMAKE_POSITION_INDEPENDENT_CODE ON )
14
14
15
- # Poor man's FetchContent
16
- function (add_subdirectory_if_no_target dir target )
17
- if (NOT TARGET ${target} )
18
- add_subdirectory (${dir} )
19
- endif ()
20
- endfunction ()
15
+ include (cmake/utils.cmake)
21
16
22
17
# For integration with onnxruntime_webassembly etc.
23
18
if (NOT DEFINED ONNX_TARGET_NAME)
24
19
set (ONNX_TARGET_NAME onnx)
25
20
endif ()
26
21
27
- option (protobuf_BUILD_TESTS "" OFF )
28
22
option (ONNX_OPT_USE_SYSTEM_PROTOBUF "" OFF )
29
23
if (NOT ONNX_OPT_USE_SYSTEM_PROTOBUF)
24
+ option (protobuf_BUILD_TESTS "" OFF )
25
+ option (protobuf_MSVC_STATIC_RUNTIME "" ${ONNX_USE_MSVC_STATIC_RUNTIME} )
30
26
add_subdirectory_if_no_target(${PROJECT_SOURCE_DIR} /third_party/protobuf/cmake libprotobuf)
31
27
endif ()
32
28
@@ -42,14 +38,14 @@ file(GLOB_RECURSE onnx_opt_srcs "onnxoptimizer/*.cc"
42
38
)
43
39
list (REMOVE_ITEM onnx_opt_srcs "${PROJECT_SOURCE_DIR} /onnxoptimizer/cpp2py_export.cc" )
44
40
45
- add_library (onnx_optimizer ${onnx_opt_srcs} )
41
+ onnxopt_add_library (onnx_optimizer ${onnx_opt_srcs} )
46
42
target_link_libraries (onnx_optimizer PUBLIC ${ONNX_TARGET_NAME} )
47
43
target_include_directories (onnx_optimizer PUBLIC
48
44
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} >
49
45
$<INSTALL_INTERFACE:include >
50
46
)
51
47
52
- add_executable (onnx_optimizer_exec examples/onnx_optimizer_exec.cpp)
48
+ onnxopt_add_executable (onnx_optimizer_exec examples/onnx_optimizer_exec.cpp)
53
49
target_link_libraries (onnx_optimizer_exec onnx_optimizer)
54
50
55
51
if (BUILD_ONNX_PYTHON)
@@ -61,7 +57,7 @@ if(BUILD_ONNX_PYTHON)
61
57
endif ()
62
58
endif ()
63
59
64
- add_library (onnx_opt_cpp2py_export MODULE "onnxoptimizer/cpp2py_export.cc" )
60
+ onnxopt_add_library (onnx_opt_cpp2py_export MODULE "onnxoptimizer/cpp2py_export.cc" )
65
61
set_target_properties (onnx_opt_cpp2py_export PROPERTIES PREFIX "" )
66
62
set_target_properties (onnx_opt_cpp2py_export
67
63
PROPERTIES COMPILE_FLAGS "-fvisibility=hidden" )
@@ -140,7 +136,6 @@ if(BUILD_ONNX_PYTHON)
140
136
# clients of class 'type2'
141
137
)
142
138
endif ()
143
- add_msvc_runtime_flag(onnx_opt_cpp2py_export)
144
139
endif ()
145
140
endif ()
146
141
0 commit comments