Skip to content

Commit

Permalink
Add few external deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Sep 21, 2023
1 parent 0811323 commit 6132c96
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 4 deletions.
56 changes: 52 additions & 4 deletions cmake/cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,71 @@ if(CHECK_TYPE)
cmake_pop_check_state()
endif()

# Check dependencies
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREAD_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)

include(FetchContent)

message(CHECK_START "Fetching Abseil-cpp")
list(APPEND CMAKE_MESSAGE_INDENT " ")
set(ABSL_USE_SYSTEM_INCLUDES ON)
# We want Abseil to declare what C++ standard it was compiled with.
set(ABSL_PROPAGATE_CXX_STD ON)
# We want Abseil to keep the INSTALL rules enabled, even though it is a
# subproject. Otherwise the install rules in this project break.
set(ABSL_ENABLE_INSTALL ON)
FetchContent_Declare(
absl
GIT_REPOSITORY "https://github.com/abseil/abseil-cpp.git"
GIT_TAG "20230802.0"
GIT_SHALLOW TRUE
#PATCH_COMMAND git apply --ignore-whitespace "${CMAKE_CURRENT_LIST_DIR}/../patches/abseil-cpp-20230802.0.patch"
OVERRIDE_FIND_PACKAGE)
FetchContent_MakeAvailable(absl)
list(POP_BACK CMAKE_MESSAGE_INDENT)
message(CHECK_PASS "fetched")

message(CHECK_START "Fetching Protobuf")
list(APPEND CMAKE_MESSAGE_INDENT " ")
set(protobuf_BUILD_TESTS OFF)
set(protobuf_BUILD_SHARED_LIBS OFF)
set(protobuf_BUILD_EXPORT OFF)
set(protobuf_MSVC_STATIC_RUNTIME OFF)
set(protobuf_WITH_ZLIB OFF)
FetchContent_Declare(
protobuf
GIT_REPOSITORY "https://github.com/protocolbuffers/protobuf.git"
GIT_TAG "v24.0"
GIT_SUBMODULES ""
GIT_SHALLOW TRUE
PATCH_COMMAND git apply --ignore-whitespace "${CMAKE_CURRENT_LIST_DIR}/../patches/protobuf-v24.0.patch")
FetchContent_MakeAvailable(protobuf)
list(POP_BACK CMAKE_MESSAGE_INDENT)
message(CHECK_PASS "fetched")

if(BUILD_TESTING)
include(FetchContent)
message(CHECK_START "Fetching Googletest")
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG main)
GIT_TAG main
GIT_SHALLOW TRUE
FIND_PACKAGE_ARGS NAMES GTest GMock)
#set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
message(CHECK_PASS "fetched")

message(CHECK_START "Fetching Catch2")
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG devel
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FIND_PACKAGE_ARGS)
FetchContent_MakeAvailable(Catch2)
message(CHECK_PASS "fetched")
endif()

include(GNUInstallDirs)
Expand Down
49 changes: 49 additions & 0 deletions patches/abseil-cpp-20230802.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
diff --git a/CMake/AbseilDll.cmake b/CMake/AbseilDll.cmake
index f0d984ae..9134696d 100644
--- a/CMake/AbseilDll.cmake
+++ b/CMake/AbseilDll.cmake
@@ -624,23 +624,33 @@ set(ABSL_INTERNAL_TEST_DLL_TARGETS

include(CheckCXXSourceCompiles)

-check_cxx_source_compiles(
- [==[
-#ifdef _MSC_VER
-# if _MSVC_LANG < 201700L
-# error "The compiler defaults or is configured for C++ < 17"
-# endif
-#elif __cplusplus < 201700L
-# error "The compiler defaults or is configured for C++ < 17"
-#endif
-int main() { return 0; }
-]==]
+message(WARNING "ABSL_CXX_STANDARD: ${ABSL_CXX_STANDARD}")
+message(WARNING "CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}")
+message(WARNING "CMAKE_CXX_STANDARD_REQUIRED: ${CMAKE_CXX_STANDARD_REQUIRED}")
+message(WARNING "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
+
+if(CMAKE_CXX_STANDARD GREATER_EQUAL 17)
+ set(ABSL_INTERNAL_AT_LEAST_CXX17 TRUE)
+else()
+ check_cxx_source_compiles(
+ [==[
+ #ifdef _MSC_VER
+ # if _MSVC_LANG < 201700L
+ # error "The compiler defaults or is configured for C++ < 17"
+ # endif
+ #elif __cplusplus < 201700L
+ # error "The compiler defaults or is configured for C++ < 17"
+ #endif
+ int main() { return 0; }
+ ]==]
ABSL_INTERNAL_AT_LEAST_CXX17)
+endif()

if(ABSL_INTERNAL_AT_LEAST_CXX17)
set(ABSL_INTERNAL_CXX_STD_FEATURE cxx_std_17)
else()
set(ABSL_INTERNAL_CXX_STD_FEATURE cxx_std_14)
+ message(FATAL_ERROR "Should not pass here !!!")
endif()

function(absl_internal_dll_contains)
71 changes: 71 additions & 0 deletions patches/protobuf-v24.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ac0d03c3a..ac8aee8a7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,7 +41,7 @@ else (BUILD_SHARED_LIBS)
endif (BUILD_SHARED_LIBS)
option(protobuf_BUILD_SHARED_LIBS "Build Shared Libraries" ${protobuf_BUILD_SHARED_LIBS_DEFAULT})
include(CMakeDependentOption)
-cmake_dependent_option(protobuf_MSVC_STATIC_RUNTIME "Link static runtime libraries" ON
+cmake_dependent_option(protobuf_MSVC_STATIC_RUNTIME "Link static runtime libraries" OFF
"NOT protobuf_BUILD_SHARED_LIBS" OFF)
set(protobuf_WITH_ZLIB_DEFAULT ON)
option(protobuf_WITH_ZLIB "Build with zlib support" ${protobuf_WITH_ZLIB_DEFAULT})
@@ -158,24 +158,16 @@ endif()

set(_protobuf_FIND_ZLIB)
if (protobuf_WITH_ZLIB)
- find_package(ZLIB)
- if (ZLIB_FOUND)
- set(HAVE_ZLIB 1)
- # FindZLIB module define ZLIB_INCLUDE_DIRS variable
- # Set ZLIB_INCLUDE_DIRECTORIES for compatible
- set(ZLIB_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRECTORIES} ${ZLIB_INCLUDE_DIRS})
- # Using imported target if exists
- if (TARGET ZLIB::ZLIB)
- set(ZLIB_LIBRARIES ZLIB::ZLIB)
- set(_protobuf_FIND_ZLIB "if(NOT ZLIB_FOUND)\n find_package(ZLIB)\nendif()")
- endif (TARGET ZLIB::ZLIB)
- else (ZLIB_FOUND)
- set(HAVE_ZLIB 0)
- # Explicitly set these to empty (override NOT_FOUND) so cmake doesn't
- # complain when we use them later.
- set(ZLIB_INCLUDE_DIRECTORIES)
- set(ZLIB_LIBRARIES)
- endif (ZLIB_FOUND)
+ if (NOT TARGET ZLIB::ZLIB)
+ find_package(ZLIB REQUIRED)
+ endif()
+ set(HAVE_ZLIB 1)
+ # FindZLIB module define ZLIB_INCLUDE_DIRS variable
+ # Set ZLIB_INCLUDE_DIRECTORIES for compatible
+ set(ZLIB_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRECTORIES} ${ZLIB_INCLUDE_DIRS})
+ # Using imported target if exists
+ set(ZLIB_LIBRARIES ZLIB::ZLIB)
+ set(_protobuf_FIND_ZLIB "if(NOT ZLIB_FOUND AND NOT TARGET ZLIB::ZLIB)\n find_package(ZLIB REQUIRED)\nendif()")
endif (protobuf_WITH_ZLIB)

# We need to link with libatomic on systems that do not have builtin atomics, or
@@ -277,7 +269,6 @@ else (MSVC)
endif (MSVC)

include_directories(
- ${ZLIB_INCLUDE_DIRECTORIES}
${protobuf_BINARY_DIR}
${protobuf_SOURCE_DIR}/src)

diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake
index 422754a1a..ea91898d5 100644
--- a/cmake/libprotobuf.cmake
+++ b/cmake/libprotobuf.cmake
@@ -26,7 +26,9 @@ endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
target_link_libraries(libprotobuf PRIVATE log)
endif()
-target_include_directories(libprotobuf PUBLIC ${protobuf_SOURCE_DIR}/src)
+target_include_directories(libprotobuf PUBLIC
+ ${protobuf_SOURCE_DIR}/src
+ ${protobuf_SOURCE_DIR})
target_link_libraries(libprotobuf PUBLIC ${protobuf_ABSL_USED_TARGETS})
protobuf_configure_target(libprotobuf)
if(protobuf_BUILD_SHARED_LIBS)

0 comments on commit 6132c96

Please sign in to comment.