Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cld3] Cleanup, use protobuf config #37495

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions ports/cld3/fix-build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2fa3908..37e9944 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,11 +1,11 @@
# This cmake scripts only builds a static cld3 lib and the unittests.

-project(cld3)

# Old versions of cmake dont search/find protobuf lite
cmake_minimum_required(VERSION 3.9)
+project(cld3)

-find_package(Protobuf REQUIRED)
+find_package(Protobuf CONFIG REQUIRED)
message(STATUS "Protobuf_FOUND= ${Protobuf_FOUND}")
message(STATUS "Protobuf_VERSION= ${Protobuf_VERSION}")
message(WARNING "Protobuf 2.5 and CLD3 seems happy together. This script does NOT check if your verison of protobuf is compatible.")
@@ -20,9 +20,6 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/misc/myprotobuf.cmake)
my_protobuf_generate_cpp(cld_3/protos PROTO_SRCS PROTO_HDRS src/feature_extractor.proto src/sentence.proto src/task_spec.proto)
message(STATUS "PROTO_HDRS= ${PROTO_HDRS}")

-add_definitions(-fPIC) # Position Independant Code
-add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
-add_definitions(-std=c++11) # Needed for std::to_string(), ...

include_directories(${CMAKE_CURRENT_BINARY_DIR} ${Protobuf_INCLUDE_DIRS}) # needed to include generated pb headers

@@ -58,6 +55,10 @@ add_library(${PROJECT_NAME}
src/script_span/fixunicodevalue.cc
)

+target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
+target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf-lite)
+
+if(BUILD_TESTS)
# unit tests exec:
add_executable(language_identifier_main src/language_identifier_main.cc)
target_link_libraries(language_identifier_main cld3 ${Protobuf_LITE_LIBRARIES})
@@ -67,3 +68,4 @@ target_link_libraries(getonescriptspan_test cld3 ${Protobuf_LITE_LIBRARIES})

add_executable(language_identifier_features_test src/language_identifier_features_test.cc)
target_link_libraries(language_identifier_features_test cld3 ${Protobuf_LITE_LIBRARIES})
+endif()
diff --git a/src/base.h b/src/base.h
index 20189e2..3c610e3 100644
--- a/src/base.h
+++ b/src/base.h
@@ -71,7 +71,7 @@ typedef unsigned short uint16; // NOLINT
typedef signed int char32;
#endif // SWIG

-#ifdef COMPILER_MSVC
+#ifdef _MSC_VER
typedef __int64 int64;
#else
typedef long long int64; // NOLINT
diff --git a/src/script_span/utf8statetable.cc b/src/script_span/utf8statetable.cc
index 8fcfb1e..87da972 100644
--- a/src/script_span/utf8statetable.cc
+++ b/src/script_span/utf8statetable.cc
@@ -17,7 +17,7 @@
// 32- or 16-bit Unicode values.
//

-#ifdef COMPILER_MSVC
+#ifdef _MSC_VER
// MSVC warns: warning C4309: 'initializing' : truncation of constant value
// But the value is in fact not truncated. 0xFF still comes out 0xFF at
// runtime.
diff --git a/src/sentence_features.h b/src/sentence_features.h
index cc0be88..e2e27d2 100644
--- a/src/sentence_features.h
+++ b/src/sentence_features.h
@@ -34,7 +34,7 @@ using WholeSentenceExtractor = FeatureExtractor<Sentence>;
// for clang's -Wundefined-var-template. However, MSVC has a bug which treats
// this declaration as a definition, leading to multiple definition errors, so
// omit this on MSVC.
-#if !defined(COMPILER_MSVC)
+#if !defined(_MSC_VER)
template <>
WholeSentenceFeature::Registry
*RegisterableClass<WholeSentenceFeature>::registry_;
2 changes: 1 addition & 1 deletion ports/cld3/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ vcpkg_from_github(
SHA512 c3650ffbf5855aaf04d03930f01c6efd76e1f2b2d47365348721f16531a14653ae5b3aff8fefa8e5fa1c769fdf1a9b441a88bc687f97f8c579b84f17c6984c9e
HEAD_REF master
PATCHES
fix-build.patch
unofficial-export.patch
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS ${FEATURE_OPTIONS}
)

vcpkg_cmake_install()
Expand Down
35 changes: 7 additions & 28 deletions ports/cld3/unofficial-export.patch
Original file line number Diff line number Diff line change
@@ -1,35 +1,11 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2fa3908..d776dd1 100644
index 37e9944..fb27632 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,7 +21,6 @@ my_protobuf_generate_cpp(cld_3/protos PROTO_SRCS PROTO_HDRS src/feature_extracto
message(STATUS "PROTO_HDRS= ${PROTO_HDRS}")
@@ -57,6 +57,19 @@ add_library(${PROJECT_NAME}

add_definitions(-fPIC) # Position Independant Code
-add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
add_definitions(-std=c++11) # Needed for std::to_string(), ...

include_directories(${CMAKE_CURRENT_BINARY_DIR} ${Protobuf_INCLUDE_DIRS}) # needed to include generated pb headers
@@ -58,6 +57,7 @@ add_library(${PROJECT_NAME}
src/script_span/fixunicodevalue.cc
)

+if (0) # Disable unit tests
# unit tests exec:
add_executable(language_identifier_main src/language_identifier_main.cc)
target_link_libraries(language_identifier_main cld3 ${Protobuf_LITE_LIBRARIES})
@@ -67,3 +67,24 @@ target_link_libraries(getonescriptspan_test cld3 ${Protobuf_LITE_LIBRARIES})

add_executable(language_identifier_features_test src/language_identifier_features_test.cc)
target_link_libraries(language_identifier_features_test cld3 ${Protobuf_LITE_LIBRARIES})
+endif()
+
+if (MSVC)
+ add_compile_definitions(COMPILER_MSVC)
+endif()
+
+target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf-lite)
+
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf-lite)
+target_include_directories(${PROJECT_NAME} PUBLIC $<INSTALL_INTERFACE:include>)
+
+install(TARGETS ${PROJECT_NAME}
Expand All @@ -43,3 +19,6 @@ index 2fa3908..d776dd1 100644
+ NAMESPACE unofficial::cld3::
+ DESTINATION share/unofficial-cld3
+)

if(BUILD_TESTS)
# unit tests exec:
2 changes: 1 addition & 1 deletion ports/cld3/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cld3",
"version": "3.0.14",
"port-version": 1,
"port-version": 2,
"description": "Compact Language Detector v3",
"homepage": "https://github.com/google/cld3",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@
},
"cld3": {
"baseline": "3.0.14",
"port-version": 1
"port-version": 2
},
"clfft": {
"baseline": "2.12.2",
Expand Down
5 changes: 5 additions & 0 deletions versions/c-/cld3.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "41fd2fe36358570f0bdbfaf689bf12132af99a6f",
"version": "3.0.14",
"port-version": 2
},
{
"git-tree": "a9553fd0c6e8053c54c83a51d8e93bdfab419c8e",
"version": "3.0.14",
Expand Down