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

Allow to create workspace #701

Merged
merged 14 commits into from
Jul 24, 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
52 changes: 39 additions & 13 deletions base.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,26 @@
# https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html#generating-a-package-version-file
# for further details.
#
# .. variable:: PROJECT_AUTO_RUN_FINALIZE
#
# If set, to true or unset SETUP_PROJECT_FINALIZE run automatically at the end
# of the root CMakeLists.txt. If set to false, SETUP_PROJECT_FINALIZE must be
# called manually. This is helpful when creating a CMake workspace where the
# root CMakelists.txt don't belong to a project.
#
# .. variable:: PROJECT_PACKAGES_IN_WORKSPACE
#
# List of packages in the workspace. This must be defined in the root
# CMakeLists. These packages will not be searched with find_package and all
# target and variables defined in the module should be defined in a workspace
# projects.
#
# .. variable:: PROJECT_PYTHON_PACKAGES_IN_WORKSPACE
#
# List of paths to Python package in the workspace. This must be defined in the
# root CMakeLists.txt. Python package should be generated in a workspace
# projects.
#
# Macros
# ------
#
Expand All @@ -134,6 +154,10 @@ set(PROJECT_JRL_CMAKE_BINARY_DIR
${CMAKE_CURRENT_BINARY_DIR}
CACHE INTERNAL "")

if(NOT DEFINED PROJECT_AUTO_RUN_FINALIZE)
set(PROJECT_AUTO_RUN_FINALIZE TRUE)
endif()

# Please note that functions starting with an underscore are internal functions
# and should not be used directly.

Expand Down Expand Up @@ -218,20 +242,19 @@ set(CMAKE_PROJECT_${PROJECT_NAME}_INCLUDE
# Set a hook to finalize the setup, CMake will set CMAKE_CURRENT_LIST_DIR to ""
# at the end Based off
# https://stackoverflow.com/questions/15760580/execute-command-or-macro-in-cmake-as-the-last-step-before-the-configure-step-f
variable_watch(CMAKE_CURRENT_LIST_DIR SETUP_PROJECT_FINALIZE_HOOK)
function(SETUP_PROJECT_FINALIZE_HOOK VARIABLE ACCESS)
if("${${VARIABLE}}" STREQUAL "")
set(CMAKE_CURRENT_LIST_DIR ${PROJECT_JRL_CMAKE_MODULE_DIR})
set(JRL_CMAKEMODULE_LOGGING_FILENAME
"${PROJECT_JRL_CMAKE_BINARY_DIR}/config.log")
setup_project_finalize()
if(PROJECT_USE_CMAKE_EXPORT)
setup_project_package_finalize()
if(PROJECT_AUTO_RUN_FINALIZE)
variable_watch(CMAKE_CURRENT_LIST_DIR SETUP_PROJECT_FINALIZE_HOOK)
function(SETUP_PROJECT_FINALIZE_HOOK VARIABLE ACCESS)
if("${${VARIABLE}}" STREQUAL "")
set(CMAKE_CURRENT_LIST_DIR ${PROJECT_JRL_CMAKE_MODULE_DIR})
set(JRL_CMAKEMODULE_LOGGING_FILENAME
"${PROJECT_JRL_CMAKE_BINARY_DIR}/config.log")
setup_project_finalize()
set(CMAKE_CURRENT_LIST_DIR "") # restore value
set(JRL_CMAKEMODULE_LOGGING_FILENAME "") # restore value
endif()
set(CMAKE_CURRENT_LIST_DIR "") # restore value
set(JRL_CMAKEMODULE_LOGGING_FILENAME "") # restore value
endif()
endfunction()
endfunction()
endif()

# --------------------- # Project configuration # --------------------- #

Expand Down Expand Up @@ -332,6 +355,9 @@ macro(SETUP_PROJECT_FINALIZE)
_install_project_data()

logging_finalize()
if(PROJECT_USE_CMAKE_EXPORT)
setup_project_package_finalize()
endif()
endmacro(SETUP_PROJECT_FINALIZE)

# .rst: .. ifmode:: user
Expand Down
7 changes: 6 additions & 1 deletion coverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,16 @@ macro(_SETUP_COVERAGE_FINALIZE)
message(STATUS "Python coverage will be generated")
endif()

if(NOT TARGET coverage)
add_custom_target(coverage
COMMENT "Generating HTML report for code coverage")
endif()
add_custom_target(
coverage
${PROJECT_NAME}-coverage
COMMAND ${_COVERAGE_HTML} -o ${_COVERAGE_DIR} ${_COVERAGE_FILES}
DEPENDS ${_COVERAGE_FILES}
BYPRODUCTS ${_COVERAGE_DIR}
COMMENT "Generating HTML report for code coverage")
add_dependencies(coverage ${PROJECT_NAME}-coverage)
endif()
endmacro()
13 changes: 11 additions & 2 deletions debian.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,25 @@ endmacro(_SETUP_DEBIAN)

macro(_SETUP_PROJECT_DEB)
if(UNIX AND NOT APPLE)
if(NOT TARGET deb-src)
add_custom_target(deb-src COMMENT "Generating source Debian package...")
endif()
add_custom_target(
deb-src
${PROJECT_NAME}-deb-src
COMMAND git-buildpackage --git-debian-branch=debian
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Generating source Debian package...")
add_dependencies(deb-src ${PROJECT_NAME}-deb-src)

if(NOT TARGET deb)
add_custom_target(deb COMMENT "Generating Debian package...")
endif()
add_custom_target(
deb
${PROJECT_NAME}-deb
COMMAND git-buildpackage --git-debian-branch=debian
--git-builder="debuild -S -i.git -I.git"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Generating Debian package...")
add_dependencies(deb ${PROJECT_NAME}-deb)
endif(UNIX AND NOT APPLE)
endmacro(_SETUP_PROJECT_DEB)
159 changes: 98 additions & 61 deletions dist.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,97 +35,134 @@ macro(_SETUP_PROJECT_DIST)
endif(APPLE)

# Use git-archive-all.sh to generate distributable source code
if(NOT TARGET distdir)
add_custom_target(distdir COMMENT "Generating dist directory...")
endif()
add_custom_target(
distdir
${PROJECT_NAME}-distdir
COMMAND
rm -f /tmp/${PROJECT_NAME}.tar && ${GIT_ARCHIVE_ALL} --prefix
${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/ ${PROJECT_NAME}.tar
&& cd ${CMAKE_BINARY_DIR}/ &&
(test
-d
${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}
&&
find
${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/
-type
d
-print0
|
xargs
-0
chmod
a+w
||
true) && rm -rf ${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/ &&
${TAR} xf ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.tar && echo
"${PROJECT_VERSION}" >
${CMAKE_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/.version
&& ${PROJECT_JRL_CMAKE_MODULE_DIR}/gitlog-to-changelog >
${CMAKE_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/ChangeLog
&& rm -f ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.tar
# cmake-format: off
rm -f /tmp/${PROJECT_NAME}.tar &&
${GIT_ARCHIVE_ALL} --prefix ${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/
${PROJECT_NAME}.tar &&
cd ${PROJECT_BINARY_DIR}/ &&
(
test -d ${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION} &&
find ${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/ -type d -print0 |
xargs -0 chmod a+w || true
) &&
rm -rf ${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/ &&
${TAR} xf ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.tar &&
echo "${PROJECT_VERSION}" >
${PROJECT_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/.version &&
${PROJECT_JRL_CMAKE_MODULE_DIR}/gitlog-to-changelog --srcdir ${PROJECT_SOURCE_DIR} >
${PROJECT_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/ChangeLog &&
rm -f ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.tar
# cmake-format: on
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Generating dist directory...")
COMMENT "Generating dist directory for ${PROJECT_NAME}...")
add_dependencies(distdir ${PROJECT_NAME}-distdir)

# Create a tar.gz tarball for the project, and generate the signature
if(NOT TARGET dist_targz)
add_custom_target(
dist_targz COMMENT "Generating tar.gz tarball and its signature...")
endif()
add_custom_target(
dist_targz
${PROJECT_NAME}-dist_targz
COMMAND
# cmake-format: off
${TAR} -czf ${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.tar.gz
${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/ && ${GPG}
--detach-sign --armor -o
${CMAKE_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.tar.gz.sig
${CMAKE_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.tar.gz
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating tar.gz tarball and its signature...")
${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/ &&
${GPG} --detach-sign --armor -o
${PROJECT_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.tar.gz.sig
${PROJECT_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.tar.gz
# cmake-format: on
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMENT
"Generating tar.gz tarball and its signature for ${PROJECT_NAME}...")
add_dependencies(dist_targz ${PROJECT_NAME}-dist_targz)

# Create a tar.bz2 tarball for the project, and generate the signature
if(NOT TARGET dist_tarbz2)
add_custom_target(
dist_tarbz2 COMMENT "Generating tar.bz2 tarball and its signature...")
endif()
add_custom_target(
dist_tarbz2
${PROJECT_NAME}-dist_tarbz2
COMMAND
# cmake-format: off
${TAR} -cjf ${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.tar.bz2
${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/ && ${GPG}
--detach-sign --armor -o
${CMAKE_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.tar.bz2.sig
${CMAKE_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.tar.bz2
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating tar.bz2 tarball and its signature...")
${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/ &&
${GPG} --detach-sign --armor -o
${PROJECT_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.tar.bz2.sig
${PROJECT_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.tar.bz2
# cmake-format: on
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMENT
"Generating tar.bz2 tarball and its signature for ${PROJECT_NAME}...")
add_dependencies(dist_tarbz2 ${PROJECT_NAME}-dist_tarbz2)

# Create a tar.xz tarball for the project, and generate the signature
if(NOT TARGET dist_tarxz)
add_custom_target(
dist_tarxz COMMENT "Generating tar.xz tarball and its signature...")
endif()
add_custom_target(
dist_tarxz
${PROJECT_NAME}-dist_tarxz
COMMAND
# cmake-format: off
${TAR} -cJf ${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.tar.xz
${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/ && ${GPG}
--detach-sign --armor -o
${CMAKE_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.tar.xz.sig
${CMAKE_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.tar.xz
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating tar.xz tarball and its signature...")
${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/ &&
${GPG} --detach-sign --armor -o
${PROJECT_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.tar.xz.sig
${PROJECT_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.tar.xz
# cmake-format: on
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMENT
"Generating tar.xz tarball and its signature for ${PROJECT_NAME}...")
add_dependencies(dist_tarxz ${PROJECT_NAME}-dist_tarxz)

# Alias: dist = dist_targz (backward compatibility)
add_custom_target(dist DEPENDS dist_targz)
if(NOT TARGET dist)
add_custom_target(dist)
endif()
add_custom_target(${PROJECT_NAME}-dist DEPENDS ${PROJECT_NAME}-dist_targz)
add_dependencies(dist ${PROJECT_NAME}-dist)

# TODO: call this during `make clean`
if(NOT TARGET distclean)
add_custom_target(distclean COMMENT "Cleaning dist sources...")
endif()
add_custom_target(
distclean
${PROJECT_NAME}-distclean
COMMAND
# cmake-format: off
rm -rf
${CMAKE_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Cleaning dist sources...")
${PROJECT_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}/
# cmake-format: on
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMENT "Cleaning dist sources for ${PROJECT_NAME}...")
add_dependencies(distclean ${PROJECT_NAME}-distclean)

if(NOT TARGET distorig)
add_custom_target(distorig COMMENT "Generating orig tarball...")
endif()
add_custom_target(
distorig
${PROJECT_NAME}-distorig
COMMAND
# cmake-format: off
cmake -E copy ${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.tar.gz
${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.orig.tar.gz
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating orig tarball...")
${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}.orig.tar.gz
# cmake-format: on
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMENT "Generating orig tarball for ${PROJECT_NAME}...")
add_dependencies(distorig ${PROJECT_NAME}-distorig)

add_dependencies(dist_targz distdir)
add_dependencies(dist_tarbz2 distdir)
add_dependencies(dist_tarxz distdir)
add_dependencies(distorig dist)
add_dependencies(${PROJECT_NAME}-dist_targz ${PROJECT_NAME}-distdir)
add_dependencies(${PROJECT_NAME}-dist_tarbz2 ${PROJECT_NAME}-distdir)
add_dependencies(${PROJECT_NAME}-dist_tarxz ${PROJECT_NAME}-distdir)
add_dependencies(${PROJECT_NAME}-distorig ${PROJECT_NAME}-dist)
else()
# FIXME: what to do here?
endif()
Expand Down
8 changes: 6 additions & 2 deletions distcheck.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ macro(DISTCHECK_SETUP)
string(REPLACE "${CMAKE_SOURCE_DIR}" "${SRCDIR}" NEW_CMAKE_BINARY_DIR
"${CMAKE_BINARY_DIR}")

if(NOT TARGET distcheck)
add_custom_target(distcheck COMMENT "Checking generated tarball...")
endif()
add_custom_target(
distcheck
${PROJECT_NAME}-distcheck
COMMAND
export LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} && export
${LD_LIBRARY_PATH_VARIABLE_NAME}=$ENV{${LD_LIBRARY_PATH_VARIABLE_NAME}}
Expand Down Expand Up @@ -129,7 +132,8 @@ macro(DISTCHECK_SETUP)
WORKING_DIRECTORY
${CMAKE_BINARY_DIR}/${PROJECT_NAME}${PROJECT_SUFFIX}-${PROJECT_VERSION}
COMMENT "Checking generated tarball...")
add_dependencies(distcheck distdir)
add_dependencies(distcheck ${PROJECT_NAME}-distcheck)
add_dependencies(${PROJECT_NAME}-distcheck ${PROJECT_NAME}-distdir)

unset(NEW_CMAKE_BINARY_DIR)
unset(SRCDIR)
Expand Down
18 changes: 14 additions & 4 deletions doxygen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -518,17 +518,20 @@ macro(_SETUP_PROJECT_DOCUMENTATION)
endif(DOXYGEN_DOT_FOUND)

# Teach CMake how to generate the documentation.
if(NOT TARGET doc)
add_custom_target(doc ALL COMMENT "Generating Doxygen documentation")
endif()
if(MSVC)
# FIXME: it is impossible to trigger documentation installation at
# install, so put the target in ALL instead.
add_custom_target(
doc ALL
${PROJECT_NAME}-doc
COMMAND ${DOXYGEN_EXECUTABLE} ${JRL_CMAKEMODULE_DOXYFILE_PATH}
WORKING_DIRECTORY doc
COMMENT "Generating Doxygen documentation")
else(MSVC)
add_custom_target(
doc
${PROJECT_NAME}-doc
COMMAND ${DOXYGEN_EXECUTABLE} ${JRL_CMAKEMODULE_DOXYFILE_PATH}
WORKING_DIRECTORY doc
COMMENT "Generating Doxygen documentation")
Expand All @@ -537,18 +540,25 @@ macro(_SETUP_PROJECT_DOCUMENTATION)
install(CODE "EXECUTE_PROCESS(COMMAND ${CMAKE_MAKE_PROGRAM} doc)")
endif(INSTALL_DOCUMENTATION)
endif(MSVC)
add_dependencies(doc ${PROJECT_NAME}-doc)

if(DOXYGEN_USE_TEMPLATE_CSS)
if(NOT TARGET generate-template-css)
add_custom_target(generate-template-css)
endif()
add_custom_target(
generate-template-css
${PROJECT_NAME}-generate-template-css
COMMAND
${DOXYGEN_EXECUTABLE} -w html ${PROJECT_BINARY_DIR}/doc/header.html
${PROJECT_BINARY_DIR}/doc/footer.html
${PROJECT_BINARY_DIR}/doc/doxygen.css
BYPRODUCTS ${PROJECT_BINARY_DIR}/doc/header.html
${PROJECT_BINARY_DIR}/doc/footer.html
${PROJECT_BINARY_DIR}/doc/doxygen.css)
add_dependencies(doc generate-template-css)
add_dependencies(generate-template-css
${PROJECT_NAME}-generate-template-css)
add_dependencies(${PROJECT_NAME}-doc
${PROJECT_NAME}-generate-template-css)
_set_if_undefined(DOXYGEN_HTML_HEADER
"${PROJECT_BINARY_DIR}/doc/header.html")
_set_if_undefined(DOXYGEN_HTML_FOOTER
Expand Down
Loading
Loading