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

cmake: simplify by not using FetchContent #273

Merged
merged 1 commit into from
Jan 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
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ message(STATUS "p4est ${PROJECT_VERSION} "

# --- external libs

include(cmake/sc.cmake)
include(cmake/GitSubmodule.cmake)
git_submodule("${PROJECT_SOURCE_DIR}/sc")
add_subdirectory(sc)

# --- configure p4est

Expand All @@ -37,7 +39,7 @@ target_include_directories(p4est PUBLIC
$<INSTALL_INTERFACE:include>)
target_link_libraries(p4est PUBLIC SC::SC $<$<BOOL:${P4EST_HAVE_WINSOCK2_H}>:${WINSOCK_LIBRARIES}>)

# imported target, for use from FetchContent
# imported target, for use from parent projects
add_library(P4EST::P4EST INTERFACE IMPORTED GLOBAL)
target_link_libraries(P4EST::P4EST INTERFACE p4est)

Expand Down
30 changes: 20 additions & 10 deletions cmake/GitSubmodule.cmake
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
function(git_submodule dir)
# else it's an offline archive
if(IS_DIRECTORY ${PROJECT_SOURCE_DIR}/.git)
find_package(Git REQUIRED)
endif()

function(git_submodule submod_dir)
# get/update Git submodule directory to CMake, assuming the
# Git submodule directory is a CMake project.

find_package(Git REQUIRED)
if(NOT IS_DIRECTORY ${PROJECT_SOURCE_DIR}/.git)
message(DEBUG "${PROJECT_SOURCE_DIR} is not a Git repository, skipping submodule ${submod_dir}")
return()
endif()

if(EXISTS ${submod_dir}/CMakeLists.txt)
return()
endif()

if(NOT EXISTS ${dir}/CMakeLists.txt)
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive -- ${dir}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE _err)
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive -- ${submod_dir}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE err)

if(NOT _err EQUAL 0)
message(SEND_ERROR "Could not retrieve Git submodule ${dir}.")
endif()
if(NOT err EQUAL 0)
message(FATAL_ERROR "${submod_dir} Git submodule failed to retrieve.")
endif()

endfunction(git_submodule)
endfunction()
2 changes: 1 addition & 1 deletion cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ set(P4EST_HAVE_FSYNC ${SC_HAVE_FSYNC} CACHE BOOL "platform has fsync")
set(P4EST_HAVE_GETOPT_H ${SC_HAVE_GETOPT_H} CACHE BOOL "platform has getopt.h")

if(P4EST_HAVE_ZLIB)
# ZLIB::ZLIB would be defined in sc/cmake/zlib.cmake IMPORTED INTERFACE GLOBAL via libsc FetchContent
# ZLIB::ZLIB would be defined in sc/cmake/zlib.cmake IMPORTED INTERFACE GLOBAL via libsc
if(NOT TARGET ZLIB::ZLIB)
# libsc didn't build Zlib, so must find an existing Zlib
find_package(ZLIB REQUIRED)
Expand Down
21 changes: 0 additions & 21 deletions cmake/sc.cmake

This file was deleted.