Skip to content

Commit

Permalink
switch cmake cmp0169 flag to new (microsoft#762)
Browse files Browse the repository at this point in the history
* switch cmake cmp0169 flag to new

* the missing spm code.

* more refinement on cmake build targets

* Update ci.yml

* Update ci.yml

* update the jpg files after using libjpeg instead of libjpeg-turbo

* exclude cutlass too

* upgrade the protobuf library to be consistent with ORT

* update the protoc generated files

* use the right patch name

* Update cutlass.cmake
  • Loading branch information
wenbingl authored Jul 16, 2024
1 parent 8153bc1 commit 38a3d85
Show file tree
Hide file tree
Showing 28 changed files with 5,149 additions and 1,663 deletions.
2 changes: 1 addition & 1 deletion .pipelines/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ stages:
- job: AndroidCpp_BuildOnly
pool:
vmImage: 'macOS-13'
timeoutInMinutes: 30
timeoutInMinutes: 45
steps:
- task: UsePythonVersion@0
inputs:
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ endif()
# Avoid warning of Calling FetchContent_Populate(GSL) is deprecated temporarily
# TODO: find a better way to handle the header-only 3rd party deps
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.30.0")
cmake_policy(SET CMP0169 OLD)
cmake_policy(SET CMP0169 NEW)
endif()

# Needed for Java
Expand Down Expand Up @@ -759,6 +759,7 @@ else()
standardize_output_folder(ortcustomops)
set(_BUILD_SHARED_LIBRARY TRUE)
endif()
set_target_properties(ortcustomops PROPERTIES FOLDER "operators")

if(OCOS_ENABLE_AZURE)
if (ANDROID)
Expand Down
2 changes: 1 addition & 1 deletion cgmanifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"component": {
"type": "other",
"other": {
"name": "libjpeg",
"name": "libpng",
"version": "1.6.37",
"downloadUrl": "https://github.com/opencv/opencv/tree/4.5.4/3rdparty/libpng"
},
Expand Down
27 changes: 9 additions & 18 deletions cmake/externals/blingfire.cmake
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
FetchContent_Declare(
Blingfire
GIT_REPOSITORY https://github.com/microsoft/BlingFire.git
GIT_TAG 0831265c1aca95ca02eca5bf1155e4251e545328
)


FetchContent_GetProperties(Blingfire)

if (NOT blingfire_POPULATED)
FetchContent_Populate(Blingfire)

# enable size optimization build
add_subdirectory(${blingfire_SOURCE_DIR} ${blingfire_BINARY_DIR} EXCLUDE_FROM_ALL)
set_target_properties(bingfirtinydll_static PROPERTIES
FOLDER externals/bingfire)
set_target_properties(fsaClientTiny PROPERTIES
FOLDER externals/bingfire)
endif()
Blingfire
GIT_REPOSITORY https://github.com/microsoft/BlingFire.git
GIT_TAG 0831265c1aca95ca02eca5bf1155e4251e545328
EXCLUDE_FROM_ALL)

FetchContent_MakeAvailable(Blingfire)
set_target_properties(bingfirtinydll_static PROPERTIES FOLDER
externals/bingfire)
set_target_properties(fsaClientTiny PROPERTIES FOLDER externals/bingfire)
15 changes: 6 additions & 9 deletions cmake/externals/cutlass.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
FetchContent_Declare(
cutlass
GIT_REPOSITORY https://github.com/NVIDIA/cutlass.git
GIT_TAG v3.1.0
)

FetchContent_GetProperties(cutlass)
if(NOT cutlass_POPULATED)
FetchContent_Populate(cutlass)
endif()
cutlass
GIT_REPOSITORY https://github.com/NVIDIA/cutlass.git
GIT_TAG v3.1.0
EXCLUDE_FROM_ALL)
set(CUTLASS_ENABLE_HEADERS_ONLY ON CACHE BOOL "")
FetchContent_MakeAvailable(cutlass)
7 changes: 2 additions & 5 deletions cmake/externals/dlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ FetchContent_Declare(dlib
# there is non an official tag which supports STFT,
# choose a relatively stable commit id for that.
GIT_TAG a12824d42584e292ecb3bad05c4b32c2015a7b89
SOURCE_SUBDIR not_set
)

FetchContent_GetProperties(dlib)
if(NOT dlib_POPULATED)
# Fetch the content using previously declared details
FetchContent_Populate(dlib)
endif()
FetchContent_MakeAvailable(dlib)
7 changes: 2 additions & 5 deletions cmake/externals/dr_libs.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
FetchContent_Declare(dr_libs
URL https://github.com/mackron/dr_libs/archive/dbbd08d81fd2b084c5ae931531871d0c5fd83b87.zip
URL_HASH SHA1=84a2a31ef890b6204223b12f71d6e701c0edcd92
SOURCE_SUBDIR not_set
)

FetchContent_GetProperties(dr_libs)
if(NOT dr_libs_POPULATED)
# Fetch the content using previously declared details
FetchContent_Populate(dr_libs)
endif()
FetchContent_MakeAvailable(dr_libs)
16 changes: 6 additions & 10 deletions cmake/externals/googlere2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ FetchContent_Declare(
googlere2
GIT_REPOSITORY https://github.com/google/re2.git
GIT_TAG 2021-06-01
EXCLUDE_FROM_ALL
)

FetchContent_GetProperties(googlere2)
string(TOLOWER "googlere2" lcName)
if(NOT ${lcName}_POPULATED)
FetchContent_Populate(googlere2)
add_subdirectory(${googlere2_SOURCE_DIR} ${googlere2_BINARY_DIR} EXCLUDE_FROM_ALL)
set_target_properties(re2
PROPERTIES
POSITION_INDEPENDENT_CODE ON
FOLDER externals/google/re2)
endif()
FetchContent_MakeAvailable(googlere2)
set_target_properties(re2
PROPERTIES
POSITION_INDEPENDENT_CODE ON
FOLDER externals/google)
8 changes: 4 additions & 4 deletions cmake/externals/googletest.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/9406a60c7839052e4944ea4dbc8344762a89f9bd.zip
URL_HASH SHA1=06096d3900c356e468ba060a609642c635131106
URL https://github.com/google/googletest/archive/9406a60c7839052e4944ea4dbc8344762a89f9bd.zip
URL_HASH SHA1=06096d3900c356e468ba060a609642c635131106
EXCLUDE_FROM_ALL
)

set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
set_target_properties(gtest PROPERTIES FOLDER "externals/gtest")
set_target_properties(gtest_main PROPERTIES FOLDER "externals/gtest")
set_target_properties(gtest PROPERTIES FOLDER "externals/google")
11 changes: 2 additions & 9 deletions cmake/externals/gsl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0")
URL_HASH SHA1=cf368104cd22a87b4dd0c80228919bb2df3e2a14
FIND_PACKAGE_ARGS 4.0 NAMES Microsoft.GSL
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
SOURCE_SUBDIR not_set
)
else()
FetchContent_Declare(
Expand All @@ -14,13 +15,5 @@ else()
)
endif()

FetchContent_GetProperties(GSL)
string(TOLOWER "GSL" lcName)
if(NOT ${lcName}_POPULATED)
FetchContent_Populate(GSL)
# add_subdirectory(${GSL_SOURCE_DIR} ${GSL_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

FetchContent_MakeAvailable(GSL)
set(GSL_INCLUDE_DIR ${gsl_SOURCE_DIR}/include)

#get_target_property(GSL_INCLUDE_DIR Microsoft.GSL::GSL INTERFACE_INCLUDE_DIRECTORIES)
10 changes: 4 additions & 6 deletions cmake/externals/json.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
FetchContent_Declare(nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.10.5)
GIT_TAG v3.10.5
SOURCE_SUBDIR single_include
)

set(JSON_BuildTests OFF CACHE INTERNAL "")

FetchContent_GetProperties(nlohmann_json)
if(NOT nlohmann_json_POPULATED)
FetchContent_Populate(nlohmann_json)
endif()

add_compile_definitions(JSON_HAS_CPP_17=1)
FetchContent_MakeAvailable(nlohmann_json)
2 changes: 2 additions & 0 deletions cmake/externals/opencv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ if (OCOS_ENABLE_OPENCV_CODECS)

set(WITH_JPEG ON CACHE INTERNAL "")
set(WITH_PNG ON CACHE INTERNAL "")
set(BUILD_JPEG_TURBO_DISABLE ON CACHE INTERNAL "")
endif()

set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
Expand Down Expand Up @@ -149,6 +150,7 @@ FetchContent_Declare(
-DBUILD_SHARED_LIBS:BOOL=FALSE
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/opencv
PATCH_COMMAND git checkout . && git apply --whitespace=fix --ignore-space-change --ignore-whitespace ${CMAKE_CURRENT_SOURCE_DIR}/cmake/externals/opencv-no-rtti.patch
EXCLUDE_FROM_ALL
)

FetchContent_MakeAvailable(opencv)
Expand Down
50 changes: 37 additions & 13 deletions cmake/externals/protobuf_cmake.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index ac92442a1..e930cbd2e 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -240,9 +240,7 @@ if (MSVC)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 04cb3303a..c023001de 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -249,9 +249,7 @@ if (MSVC)
# MSVC warning suppressions
add_definitions(
/wd4065 # switch statement contains 'default' but no 'case' labels
Expand All @@ -12,20 +12,44 @@ index ac92442a1..e930cbd2e 100644
/wd4305 # 'identifier' : truncation from 'type1' to 'type2'
/wd4307 # 'operator' : integral constant overflow
/wd4309 # 'conversion' : truncation of constant value
@@ -250,7 +248,6 @@ if (MSVC)
@@ -259,7 +257,7 @@ if (MSVC)
/wd4355 # 'this' : used in base member initializer list
/wd4506 # no definition for inline function 'function'
/wd4800 # 'type' : forcing value to bool 'true' or 'false' (performance warning)
- /wd4996 # The compiler encountered a deprecated declaration.
+ ${onnxruntime_PROTOBUF_EXTRA_WARNING_DISABLEMENT}
)
# Allow big object
add_definitions(/bigobj)
@@ -272,6 +269,8 @@ if (MSVC)
endif()

configure_file(version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY)
+else (MSVC)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
endif (MSVC)
@@ -289,7 +286,6 @@ if (MSVC)
else (MSVC)
# No version.rc file.
set(protobuf_version_rc_file)
-
# When building with "make", "lib" prefix will be added automatically by
# the build tool.
set(LIB_PREFIX)
diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h
index 008c19225..cbab108c2 100644
--- a/src/google/protobuf/map.h
+++ b/src/google/protobuf/map.h
@@ -52,7 +52,8 @@
#endif // defined(__cpp_lib_string_view)

#if !defined(GOOGLE_PROTOBUF_NO_RDTSC) && defined(__APPLE__)
-#include <mach/mach_time.h>
+// apply update from https://github.com/protocolbuffers/protobuf/pull/15662/
+#include <time.h>
#endif

#include <google/protobuf/stubs/common.h>
@@ -1154,7 +1155,8 @@ class Map {
#if defined(__APPLE__)
// Use a commpage-based fast time function on Apple environments (MacOS,
// iOS, tvOS, watchOS, etc).
- s += mach_absolute_time();
+ // apply update from https://github.com/protocolbuffers/protobuf/pull/15662/
+ s += clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
#elif defined(__x86_64__) && defined(__GNUC__)
uint32_t hi, lo;
asm volatile("rdtsc" : "=a"(lo), "=d"(hi));
9 changes: 2 additions & 7 deletions cmake/externals/pybind11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ FetchContent_Declare(
pybind11
URL https://github.com/pybind/pybind11/archive/refs/tags/v2.12.0.zip
URL_HASH SHA1=8482f57ed55c7b100672815a311d5450858723fb
SOURCE_SUBDIR not_set
)

FetchContent_GetProperties(pybind11)
# Check if population has already been performed
string(TOLOWER "pybind11" lcName)
if(NOT ${lcName}_POPULATED)
# Fetch the content using previously declared details
FetchContent_Populate(pybind11)
endif()
FetchContent_MakeAvailable(pybind11)

set(pybind11_INCLUDE_DIRS ${pybind11_SOURCE_DIR}/include)
32 changes: 9 additions & 23 deletions cmake/externals/sentencepieceproject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ if(NOT _ONNXRUNTIME_EMBEDDED)
FetchContent_Declare(
protobuf
GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
GIT_TAG v3.20.3
GIT_TAG v21.12
EXCLUDE_FROM_ALL
PATCH_COMMAND git checkout . && git apply --ignore-space-change --ignore-whitespace ${PROJECT_SOURCE_DIR}/cmake/externals/protobuf_cmake.patch
)

set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build tests")
set(protobuf_WITH_ZLIB OFF CACHE BOOL "Use zlib")

Expand All @@ -25,23 +27,10 @@ if(NOT _ONNXRUNTIME_EMBEDDED)
set(protobuf_MSVC_STATIC_RUNTIME ON CACHE BOOL "")
endif()
set(protobuf_DISABLE_RTTI ON CACHE BOOL "Disable RTTI")
FetchContent_GetProperties(protobuf)
if(NOT protobuf_POPULATED)
FetchContent_Populate(protobuf)
add_subdirectory(${protobuf_SOURCE_DIR}/cmake ${protobuf_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

FetchContent_MakeAvailable(protobuf)
set_target_properties(libprotobuf PROPERTIES
FOLDER externals/google/protobuf)
set_target_properties(libprotobuf-lite PROPERTIES
FOLDER externals/google/protobuf)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
set_target_properties(libprotoc PROPERTIES
FOLDER externals/google/protobuf)
set_target_properties(protoc PROPERTIES
FOLDER externals/google/protobuf)
endif()
FOLDER externals/google)
endif()

# To avoid creating complicated logic to build protoc, especially for mobile platforms, we use the pre-generated pb files
Expand All @@ -62,9 +51,9 @@ FetchContent_Declare(
spm
GIT_REPOSITORY https://github.com/google/sentencepiece.git
GIT_TAG v0.1.96
EXCLUDE_FROM_ALL
PATCH_COMMAND ${spm_patch_command}
)
FetchContent_GetProperties(spm)

set(SPM_USE_EXTERNAL_ABSL OFF CACHE BOOL "Use external absl" FORCE)
set(SPM_USE_BUILTIN_PROTOBUF OFF CACHE BOOL "Use built-in protobuf" FORCE)
Expand All @@ -73,13 +62,10 @@ if(NOT protobuf_SOURCE_DIR)
message(FATAL_ERROR "Cannot find the protobuf library in ORT")
endif()

if(NOT spm_POPULATED)
FetchContent_Populate(spm)
add_subdirectory(${spm_SOURCE_DIR} ${spm_BINARY_DIR} EXCLUDE_FROM_ALL)
target_link_libraries(sentencepiece-static PUBLIC protobuf::libprotobuf-lite)
set_target_properties(sentencepiece-static PROPERTIES
FOLDER externals/google/sentencepiece)
endif()
FetchContent_MakeAvailable(spm)
target_link_libraries(sentencepiece-static PUBLIC protobuf::libprotobuf-lite)
set_target_properties(sentencepiece-static PROPERTIES
FOLDER externals/google)

set(spm_INCLUDE_DIRS
${protobuf_SOURCE_DIR}/src
Expand Down
Loading

0 comments on commit 38a3d85

Please sign in to comment.