Skip to content

Commit 0a93e14

Browse files
authored
Upgrade minimum cmake and update ci (#78)
* always set msvc flag and upgrade minimum cmake Signed-off-by: daquexian <[email protected]> * update PATH for cmake Signed-off-by: daquexian <[email protected]> * update Signed-off-by: daquexian <[email protected]> * msvc dynamic runtime by default, override /usr/local/bin/cmake Signed-off-by: daquexian <[email protected]> * remove duplicated protobuf in ci, other changes Signed-off-by: daquexian <[email protected]>
1 parent ec555f8 commit 0a93e14

File tree

4 files changed

+35
-26
lines changed

4 files changed

+35
-26
lines changed

.github/workflows/build-and-test.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ jobs:
66
build_wheels:
77
env:
88
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
9-
CIBW_BEFORE_ALL_LINUX: WD=`pwd` && /opt/python/cp38-cp38/bin/python -m pip install cmake && cp /opt/python/cp38-cp38/bin/cmake /usr/bin/cmake && mkdir temp && curl -L https://github.com/protocolbuffers/protobuf/releases/download/v3.13.0/protobuf-all-3.13.0.tar.gz -o protobuf.tar.gz && tar xf protobuf.tar.gz -C temp && rm -rf protobuf.tar.gz && cd temp/* && mkdir cmake/build && cd cmake/build && cmake -Dprotobuf_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release .. && cmake --build . -j4 && cmake -P cmake_install.cmake && cd $WD && rm -rf temp
10-
CIBW_BEFORE_ALL_MACOS: WD=`pwd` && pip install cmake && git clone https://github.com/protocolbuffers/protobuf.git && cd protobuf && git checkout v3.13.0 && cd cmake && mkdir build && cd build && cmake -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release .. && cmake --build . -j4 && cmake -P cmake_install.cmake && cd $WD && rm -rf protobuf
11-
CIBW_BEFORE_ALL_WINDOWS: bash -c "WD=`pwd` && git clone https://github.com/protocolbuffers/protobuf.git && cd protobuf && git checkout v3.13.0 && cd cmake && mkdir build && cd build && cmake -G \"Visual Studio 16 2019\" -A x64 -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=C:/protobuf_install -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON .. && cmake --build . --config Release -j4 && cmake -P cmake_install.cmake --config Release && cd $WD && rm -rf protobuf"
9+
CIBW_BEFORE_ALL_LINUX: WD=`pwd` && /opt/python/cp38-cp38/bin/python -m pip install cmake && cp /opt/_internal/cpython-3.8.6/bin/cmake /usr/local/bin/cmake && cmake --version && whereis cmake
10+
CIBW_BEFORE_ALL_MACOS: WD=`pwd` && pip install cmake
1211
CIBW_TEST_REQUIRES_LINUX: pytest==5.4.3 nbval flake8 mypy onnxruntime
1312
CIBW_TEST_REQUIRES_MACOS: pytest==5.4.3 nbval
1413
CIBW_TEST_REQUIRES_WINDOWS: pytest==5.4.3 nbval
@@ -17,7 +16,7 @@ jobs:
1716
CIBW_TEST_COMMAND: pytest {project}/onnxoptimizer/test
1817
CIBW_TEST_COMMAND_LINUX: cd {project} && flake8 && ! grep -R --include='*.cc' --include='*.h' 'namespace onnx' . && ! grep -R --include='*.cc' --include='*.h' 'onnx::' . && pytest
1918
CIBW_ENVIRONMENT: CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON"
20-
CIBW_ENVIRONMENT_WINDOWS: CMAKE_PREFIX_PATH=C:/protobuf_install USE_MSVC_STATIC_RUNTIME=0 CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON"
19+
CIBW_ENVIRONMENT_WINDOWS: USE_MSVC_STATIC_RUNTIME=0 CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON"
2120
# Only build on Python 3 and skip 32-bit builds
2221
CIBW_BUILD: cp3?-*
2322
# Skip python 3.5 and 3.6
@@ -39,6 +38,7 @@ jobs:
3938
run: |
4039
python -m pip install --upgrade pip
4140
python -m pip install cibuildwheel==1.7.2
41+
cmake --version
4242
cibuildwheel --output-dir wheelhouse .
4343
- uses: actions/upload-artifact@v2
4444
with:

CMakeLists.txt

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.1)
1+
cmake_minimum_required(VERSION 3.22)
22

33
# For std::filesystem
44
# Must be a cache variable and be set before project()
@@ -12,21 +12,17 @@ set(CMAKE_CXX_STANDARD 17)
1212

1313
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
1414

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)
2116

2217
# For integration with onnxruntime_webassembly etc.
2318
if (NOT DEFINED ONNX_TARGET_NAME)
2419
set(ONNX_TARGET_NAME onnx)
2520
endif()
2621

27-
option(protobuf_BUILD_TESTS "" OFF)
2822
option(ONNX_OPT_USE_SYSTEM_PROTOBUF "" OFF)
2923
if(NOT ONNX_OPT_USE_SYSTEM_PROTOBUF)
24+
option(protobuf_BUILD_TESTS "" OFF)
25+
option(protobuf_MSVC_STATIC_RUNTIME "" ${ONNX_USE_MSVC_STATIC_RUNTIME})
3026
add_subdirectory_if_no_target(${PROJECT_SOURCE_DIR}/third_party/protobuf/cmake libprotobuf)
3127
endif()
3228

@@ -42,14 +38,14 @@ file(GLOB_RECURSE onnx_opt_srcs "onnxoptimizer/*.cc"
4238
)
4339
list(REMOVE_ITEM onnx_opt_srcs "${PROJECT_SOURCE_DIR}/onnxoptimizer/cpp2py_export.cc")
4440

45-
add_library(onnx_optimizer ${onnx_opt_srcs})
41+
onnxopt_add_library(onnx_optimizer ${onnx_opt_srcs})
4642
target_link_libraries(onnx_optimizer PUBLIC ${ONNX_TARGET_NAME})
4743
target_include_directories(onnx_optimizer PUBLIC
4844
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
4945
$<INSTALL_INTERFACE:include>
5046
)
5147

52-
add_executable(onnx_optimizer_exec examples/onnx_optimizer_exec.cpp)
48+
onnxopt_add_executable(onnx_optimizer_exec examples/onnx_optimizer_exec.cpp)
5349
target_link_libraries(onnx_optimizer_exec onnx_optimizer)
5450

5551
if(BUILD_ONNX_PYTHON)
@@ -61,7 +57,7 @@ if(BUILD_ONNX_PYTHON)
6157
endif()
6258
endif()
6359

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")
6561
set_target_properties(onnx_opt_cpp2py_export PROPERTIES PREFIX "")
6662
set_target_properties(onnx_opt_cpp2py_export
6763
PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
@@ -140,7 +136,6 @@ if(BUILD_ONNX_PYTHON)
140136
# clients of class 'type2'
141137
)
142138
endif()
143-
add_msvc_runtime_flag(onnx_opt_cpp2py_export)
144139
endif()
145140
endif()
146141

cmake/utils.cmake

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
include(${PROJECT_SOURCE_DIR}/third_party/onnx/cmake/Utils.cmake)
2+
3+
# Poor man's FetchContent
4+
function(add_subdirectory_if_no_target dir target)
5+
if (NOT TARGET ${target})
6+
add_subdirectory(${dir})
7+
endif()
8+
endfunction()
9+
10+
function(onnxopt_add_library)
11+
add_library(${ARGV})
12+
if (MSVC)
13+
add_msvc_runtime_flag(${ARGV0})
14+
endif()
15+
endfunction()
16+
17+
function(onnxopt_add_executable)
18+
add_executable(${ARGV})
19+
if (MSVC)
20+
add_msvc_runtime_flag(${ARGV0})
21+
endif()
22+
endfunction()

setup.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030

3131
WINDOWS = (os.name == 'nt')
3232

33-
CMAKE = find_executable('cmake3') or find_executable('cmake')
34-
MAKE = find_executable('make')
33+
CMAKE = find_executable('cmake')
3534

3635
install_requires = []
3736
setup_requires = []
@@ -41,9 +40,7 @@
4140
# Global variables for controlling the build variant
4241
################################################################################
4342

44-
# Default value is set to TRUE\1 to keep the settings same as the current ones.
45-
# However going forward the recomemded way to is to set this to False\0
46-
USE_MSVC_STATIC_RUNTIME = bool(os.getenv('USE_MSVC_STATIC_RUNTIME', '1') == '1')
43+
USE_MSVC_STATIC_RUNTIME = bool(os.getenv('USE_MSVC_STATIC_RUNTIME', '0') == '1')
4744
ONNX_ML = not bool(os.getenv('ONNX_ML') == '0')
4845
ONNX_VERIFY_PROTO3 = bool(os.getenv('ONNX_VERIFY_PROTO3') == '1')
4946
ONNX_NAMESPACE = os.getenv('ONNX_NAMESPACE', 'onnx')
@@ -114,11 +111,6 @@ def run(self):
114111
f.write(dedent('''\
115112
# This file is generated by setup.py. DO NOT EDIT!
116113
117-
from __future__ import absolute_import
118-
from __future__ import division
119-
from __future__ import print_function
120-
from __future__ import unicode_literals
121-
122114
version = '{version}'
123115
git_version = '{git_version}'
124116
'''.format(**dict(VersionInfo._asdict()))))

0 commit comments

Comments
 (0)