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

improve handling of third-party dependencies in CMake #391

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
27 changes: 20 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ option(BLOATY_ENABLE_CMAKETARGETS "Enable installing cmake target files." ON)
option(BLOATY_ENABLE_BUILDID "Enable build id." ON)
option(BLOATY_ENABLE_RE2 "Enable the support for regular expression functions." ON)
option(BLOATY_PREFER_SYSTEM_CAPSTONE "Prefer to use the system capstone if available" YES)
option(BLOATY_PREFER_SYSTEM_PROTOBUF "Prefer to use the system protobuf if available" YES)
option(BLOATY_PREFER_SYSTEM_RE2 "Prefer to use the system re2 if available" YES)

if(UNIX OR MINGW)
find_package(PkgConfig)
find_package(ZLIB)
if(BLOATY_ENABLE_RE2)
if(BLOATY_ENABLE_RE2 AND BLOATY_PREFER_SYSTEM_RE2)
pkg_search_module(RE2 re2)
endif()
if(BLOATY_PREFER_SYSTEM_CAPSTONE)
pkg_search_module(CAPSTONE capstone)
endif()
pkg_search_module(PROTOBUF protobuf)
if(BLOATY_PREFER_SYSTEM_PROTOBUF)
pkg_search_module(PROTOBUF protobuf)
endif()
if(BLOATY_ENABLE_RE2)
if(RE2_FOUND)
MESSAGE(STATUS "System re2 found, using")
Expand Down Expand Up @@ -65,11 +69,13 @@ if(NOT CMAKE_BUILD_TYPE)
FORCE)
endif()

# Check out Git submodules.
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.gitmodules")
execute_process (COMMAND git submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
# Helper function for checking out Git submodules.
function(init_submodule PATH)
execute_process(
COMMAND git submodule update --init --recursive "${PATH}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
endfunction()

# Add third_party libraries, disabling as much as we can of their builds.

Expand Down Expand Up @@ -105,6 +111,7 @@ if(UNIX OR MINGW)
if(RE2_FOUND)
include_directories(${RE2_INCLUDE_DIRS})
else()
init_submodule(third_party/re2)
set(RE2_BUILD_TESTING OFF CACHE BOOL "enable testing for RE2" FORCE)
add_subdirectory(third_party/re2)
include_directories(third_party/re2)
Expand All @@ -113,6 +120,7 @@ if(UNIX OR MINGW)
if(CAPSTONE_FOUND)
include_directories(${CAPSTONE_INCLUDE_DIRS})
else()
init_submodule(third_party/capstone)
set(CAPSTONE_BUILD_SHARED OFF CACHE BOOL "Build shared library" FORCE)
set(CAPSTONE_BUILD_TESTS OFF CACHE BOOL "Build tests" FORCE)
add_subdirectory(third_party/capstone)
Expand All @@ -121,17 +129,20 @@ if(UNIX OR MINGW)
if(PROTOBUF_FOUND)
include_directories(${PROTOBUF_INCLUDE_DIRS})
else()
init_submodule(third_party/protobuf)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "enable tests for proto2" FORCE)
set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "enable shared libs for proto2" FORCE)
add_subdirectory(third_party/protobuf/cmake)
include_directories(SYSTEM third_party/protobuf/src)
endif()
if(NOT ZLIB_FOUND)
init_submodule(third_party/zlib)
add_subdirectory(third_party/zlib)
include_directories(SYSTEM third_party/zlib)
endif()
else()
if(BLOATY_ENABLE_RE2)
init_submodule(third_party/re2)
set(RE2_BUILD_TESTING OFF CACHE BOOL "enable testing for RE2" FORCE)
add_subdirectory(third_party/re2)
include_directories(third_party/re2)
Expand Down Expand Up @@ -165,6 +176,7 @@ endif()
include_directories(.)
include_directories(src)
if(NOT absl_FOUND)
init_submodule(third_party/abseil-cpp)
include_directories(third_party/abseil-cpp)
endif()
include_directories("${CMAKE_CURRENT_BINARY_DIR}/src")
Expand Down Expand Up @@ -366,6 +378,7 @@ else()

if(BUILD_TESTING)
option(INSTALL_GTEST "" OFF)
init_submodule(third_party/googletest)
add_subdirectory(third_party/googletest)
include_directories(third_party/googletest/googletest/include)
include_directories(third_party/googletest/googlemock/include)
Expand Down