Skip to content
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
57 changes: 44 additions & 13 deletions capp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ function(capp_list_to_string)
set(${capp_list_to_string_STRING} "${str}" PARENT_SCOPE)
endfunction()

function(capp_set_git_clone_flags)
set(all_clone_flags "--recursive")
# Options if shallow clone enabled.
set(shallow_clone_flags "--depth" "1")
# Determine clone type.
set(capp_shallow_clone true)
if (DEFINED ENV{CAPP_SHALLOW_CLONE})
set(capp_shallow_clone $ENV{CAPP_SHALLOW_CLONE})
endif()
# Set desired clone flags.
if (${capp_shallow_clone})
set(capp_git_clone_flags ${all_clone_flags} ${shallow_clone_flags} PARENT_SCOPE)
else()
set(capp_git_clone_flags ${all_clone_flags} PARENT_SCOPE)
endif()
endfunction()

function(capp_get_subdirectories result curdir)
file(GLOB children RELATIVE "${curdir}" "${curdir}/*")
set(dirlist "")
Expand Down Expand Up @@ -170,6 +187,7 @@ function(capp_pip_download)
"${CAPP_VENV_ROOT}/bin/pip"
${CAPP_PIP_FLAGS}
download
--exists-action w
--dest "${CAPP_PIP_CACHE}"
--only-binary=:all:
${PIP_PLATFORM_FLAGS}
Expand Down Expand Up @@ -464,12 +482,13 @@ endfunction()
function(capp_clone)
cmake_parse_arguments(PARSE_ARGV 0 capp_clone "" "PACKAGE;RESULT_VARIABLE" "")
file(MAKE_DIRECTORY "${CAPP_SOURCE_ROOT}")
capp_set_git_clone_flags()
set(cmd_list
"${GIT_EXECUTABLE}"
clone --depth 1
clone ${capp_git_clone_flags}
"${${capp_clone_PACKAGE}_GIT_URL}"
${capp_clone_PACKAGE})
message("\nCApp: shallow cloning ${capp_clone_PACKAGE} from ${${capp_clone_PACKAGE}_GIT_URL}\n")
message("\nCApp: cloning ${capp_clone_PACKAGE} from ${${capp_clone_PACKAGE}_GIT_URL}\n")
capp_execute(
COMMAND ${cmd_list}
WORKING_DIRECTORY "${CAPP_SOURCE_ROOT}"
Expand All @@ -478,7 +497,7 @@ function(capp_clone)
)
if (NOT git_clone_result EQUAL 0)
capp_list_to_string(LIST cmd_list STRING cmd_string)
message("\nCApp: shallow clone of ${capp_clone_PACKAGE} failed.\nCommand was: ${cmd_string}\n")
message("\nCApp: clone of ${capp_clone_PACKAGE} failed.\nCommand was: ${cmd_string}\n")
file(REMOVE_RECURSE "${CAPP_SOURCE_ROOT}/${capp_clone_PACKAGE}")
set(${capp_clone_RESULT_VARIABLE} "${git_clone_result}" PARENT_SCOPE)
return()
Expand Down Expand Up @@ -649,6 +668,12 @@ function(capp_install)
set(cmakelists_path "${source_directory}/CMakeLists.txt")
set(setup_path "${source_directory}/setup.py")
set(pyproject_path "${source_directory}/pyproject.toml")
if (NOT EXISTS "${cmakelists_path}"
AND NOT EXISTS "${setup_path}"
AND NOT EXISTS "${pyproject_path}")
set(${capp_install_RESULT_VARIABLE} -1 PARENT_SCOPE)
message("CApp: none of the following exist:\n${cmakelists_path}\n${setup_path}\n${pyproject_path}")
endif()
if (EXISTS "${cmakelists_path}")
capp_execute(
COMMAND
Expand All @@ -661,9 +686,10 @@ function(capp_install)
RESULT_VARIABLE cmake_install_result
)
set(${capp_install_RESULT_VARIABLE} "${cmake_install_result}" PARENT_SCOPE)
elseif(EXISTS "${setup_path}" OR EXISTS "${pyproject_path}")
endif()
if(EXISTS "${setup_path}" OR EXISTS "${pyproject_path}")
capp_ensure_venv()
message("CApp: Installing ${capp_install_PACKAGE} using pip")
message("\nCApp: Installing ${capp_install_PACKAGE} using pip")
set(cmd_list
"${CAPP_VENV_ROOT}/bin/pip"
install
Expand Down Expand Up @@ -696,9 +722,6 @@ function(capp_install)
if (NOT pip_result EQUAL 0)
message("CApp: failed to install ${capp_install_PACKAGE} with pip\ncommand: ${cmd_string}\n")
endif()
else()
set(${capp_install_RESULT_VARIABLE} -1 PARENT_SCOPE)
message("CApp: none of the following exist:\n${cmakelists_path}\n${setup_path}")
endif()
endfunction()

Expand Down Expand Up @@ -1191,8 +1214,9 @@ endfunction()
function(capp_clone_command)
cmake_parse_arguments(PARSE_ARGV 0 capp_clone_command "" "RESULT_VARIABLE" "GIT_ARGUMENTS")
file(MAKE_DIRECTORY "${CAPP_SOURCE_ROOT}")
capp_set_git_clone_flags()
capp_execute(
COMMAND "${GIT_EXECUTABLE}" clone --depth 1 --recursive
COMMAND "${GIT_EXECUTABLE}" clone ${capp_git_clone_flags}
${capp_clone_command_GIT_ARGUMENTS}
WORKING_DIRECTORY "${CAPP_SOURCE_ROOT}"
RESULT_VARIABLE git_clone_result
Expand All @@ -1201,7 +1225,7 @@ function(capp_clone_command)
)
if (NOT git_clone_result EQUAL 0)
capp_list_to_string(LIST capp_clone_command_GIT_ARGUMENTS STRING arg_string)
message("CApp: git clone --depth 1 --recursive ${arg_string} failed:\n${git_clone_output}\n${git_clone_error}")
message("CApp: git clone ${capp_git_clone_flags} ${arg_string} failed:\n${git_clone_output}\n${git_clone_error}")
set(${capp_clone_command_RESULT_VARIABLE} ${git_clone_result} PARENT_SCOPE)
return()
endif()
Expand Down Expand Up @@ -1391,6 +1415,7 @@ function(capp_checkout_command)
"${CAPP_VENV_ROOT}/bin/pip"
${CAPP_PIP_FLAGS}
download
--exists-action w
--dest "${CAPP_PIP_CACHE}"
--only-binary=:all:
${PIP_PLATFORM_FLAGS}
Expand Down Expand Up @@ -1463,6 +1488,7 @@ function(capp_checkout_command)
"${CAPP_VENV_ROOT}/bin/pip"
${CAPP_PIP_FLAGS}
download
--exists-action w
--dest "${CAPP_PIP_CACHE}"
--only-binary=:all:
${PIP_PLATFORM_FLAGS}
Expand Down Expand Up @@ -1998,11 +2024,16 @@ elseif(CAPP_COMMAND STREQUAL "clean")
message("CApp: removing ${source_directory}/build")
file(REMOVE_RECURSE "${source_directory}/build")
endif()
set(egg_path "${source_directory}/src/${root_package}.egg-info")
if(EXISTS "${egg_path}")
# Find *.egg-info subdirectories throughout packages source tree and delete them.
file(GLOB_RECURSE egg_paths
LIST_DIRECTORIES true
"${source_directory}/*.egg-info"
)
list(FILTER egg_paths INCLUDE REGEX "^${source_directory}/.*\.egg-info$")
foreach(egg_path ${egg_paths})
message("CApp: removing ${egg_path}")
file(REMOVE_RECURSE "${egg_path}")
endif()
endforeach()
endforeach()
set(capp_command_result 0)
elseif(CAPP_COMMAND STREQUAL "pre-commit")
Expand Down