From cddf561ea5337d1b5a72145decf7dadc842598d6 Mon Sep 17 00:00:00 2001 From: Jeremy Wolcott Date: Mon, 17 Mar 2025 12:53:39 -0400 Subject: [PATCH 1/9] introduce a CMake build that exports its targets --- CMakeLists.txt | 41 ++++++++++++++++++++ cmake/templates/DUNEPlotStyleConfig.cmake.in | 4 ++ 2 files changed, 45 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/templates/DUNEPlotStyleConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..d945183 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,41 @@ +cmake_minimum_required(VERSION 3.12) +project(DUNEPlotStyle VERSION 01.01 LANGUAGES CXX) + +find_package(ROOT REQUIRED) + +add_library(DUNEPlotStyle INTERFACE) +target_include_directories(DUNEPlotStyle INTERFACE + $ + $ + ${ROOT_INCLUDE_DIRS} +) +set_target_properties(DUNEPlotStyle PROPERTIES + PUBLIC_HEADER + src/root/cpp/include/DUNEStyle.h +) + +install(TARGETS DUNEPlotStyle + EXPORT DUNEPlotStyleTargets + LIBRARY DESTINATION lib/ + PUBLIC_HEADER DESTINATION include/) + +add_executable(DUNEPlotStyleExample examples/root/cpp/example.C) +target_link_libraries(DUNEPlotStyleExample DUNEPlotStyle ROOT::Core ROOT::Hist ROOT::Gpad ROOT::Postscript) +install(TARGETS DUNEPlotStyleExample) + + +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${PROJECT_BINARY_DIR}/DUNEPlotStyleConfigVersion.cmake" + VERSION ${CMAKE_PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion +) +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/templates/DUNEPlotStyleConfig.cmake.in" + "${PROJECT_BINARY_DIR}/DUNEPlotStyleConfig.cmake" + INSTALL_DESTINATION lib/cmake/DUNEStyle +) +install(EXPORT DUNEPlotStyleTargets DESTINATION lib/cmake/DUNEPlotStyle) +install(FILES "${PROJECT_BINARY_DIR}/DUNEPlotStyleConfigVersion.cmake" + "${PROJECT_BINARY_DIR}/DUNEPlotStyleConfig.cmake" + DESTINATION lib/cmake/DUNEPlotStyle) \ No newline at end of file diff --git a/cmake/templates/DUNEPlotStyleConfig.cmake.in b/cmake/templates/DUNEPlotStyleConfig.cmake.in new file mode 100644 index 0000000..fe79c50 --- /dev/null +++ b/cmake/templates/DUNEPlotStyleConfig.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/DUNEPlotStyleTargets.cmake") +check_required_components("@PROJECT_NAME@") \ No newline at end of file From 447c36a934c9689dab245c559ff82207151c9803 Mon Sep 17 00:00:00 2001 From: Jeremy Wolcott Date: Mon, 17 Mar 2025 12:53:50 -0400 Subject: [PATCH 2/9] build example standalone as well --- examples/root/cpp/example.C | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/root/cpp/example.C b/examples/root/cpp/example.C index 0e6996e..c93e024 100644 --- a/examples/root/cpp/example.C +++ b/examples/root/cpp/example.C @@ -252,3 +252,11 @@ void example() c.SaveAs("example.root.histoverlay.png"); } + +#ifndef __ROOTCLING__ +int main() +{ + example(); + return 0; +} +#endif \ No newline at end of file From 49ea04ab8a1e93754d98550987fc2eefce7436a5 Mon Sep 17 00:00:00 2001 From: Jeremy Wolcott Date: Wed, 19 Mar 2025 10:34:42 -0400 Subject: [PATCH 3/9] since exported targets are architecture-independent, install CMake files to share/cmake instead of lib/cmake --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d945183..419c35d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,9 +33,9 @@ write_basic_package_version_file( configure_package_config_file( "${PROJECT_SOURCE_DIR}/cmake/templates/DUNEPlotStyleConfig.cmake.in" "${PROJECT_BINARY_DIR}/DUNEPlotStyleConfig.cmake" - INSTALL_DESTINATION lib/cmake/DUNEStyle + INSTALL_DESTINATION share/cmake/DUNEPlotStyle ) install(EXPORT DUNEPlotStyleTargets DESTINATION lib/cmake/DUNEPlotStyle) install(FILES "${PROJECT_BINARY_DIR}/DUNEPlotStyleConfigVersion.cmake" "${PROJECT_BINARY_DIR}/DUNEPlotStyleConfig.cmake" - DESTINATION lib/cmake/DUNEPlotStyle) \ No newline at end of file + DESTINATION share/cmake/DUNEPlotStyle) \ No newline at end of file From 0a7f8b0a6159ce8068abc24645bd9ddfc60738d4 Mon Sep 17 00:00:00 2001 From: Jeremy Wolcott Date: Wed, 19 Mar 2025 11:14:53 -0400 Subject: [PATCH 4/9] inject CMake package file dir into search path --- ups/dune_plot_style.table | 1 + 1 file changed, 1 insertion(+) diff --git a/ups/dune_plot_style.table b/ups/dune_plot_style.table index 8624f3b..a355d46 100644 --- a/ups/dune_plot_style.table +++ b/ups/dune_plot_style.table @@ -18,3 +18,4 @@ ACTION=SETUP PathPrepend(PYTHONPATH, ${UPS_PROD_DIR}/python) PathPrepend(MPLCONFIGDIR, ${UPS_PROD_DIR}/stylelib/) PathPrepend(ROOT_INCLUDE_PATH, ${UPS_PROD_DIR}/include) + PathPrepend(CMAKE_PREFIX_PATH, ${UPS_PROD_DIR}/share/cmake) From 85c4ab56f468836be3f677bd2a215af6d7aad642 Mon Sep 17 00:00:00 2001 From: Jeremy Wolcott Date: Wed, 19 Mar 2025 11:16:01 -0400 Subject: [PATCH 5/9] robustify and flexify --- ups/make_dune_plot_style_ups_product.sh | 76 +++++++++++++++++++------ 1 file changed, 58 insertions(+), 18 deletions(-) diff --git a/ups/make_dune_plot_style_ups_product.sh b/ups/make_dune_plot_style_ups_product.sh index a5a28ae..77f7a7a 100644 --- a/ups/make_dune_plot_style_ups_product.sh +++ b/ups/make_dune_plot_style_ups_product.sh @@ -3,16 +3,19 @@ # heavily inspired by NOvAs ups product making script # 2022-07-12 +path=/grid/fermiapp/products/dune/ + # print usage usage() { echo "" echo "Usage is:" - echo " sh make_dune_plot_style_ups_product.sh " + echo " sh make_dune_plot_style_ups_product.sh [install dir]" echo "" - echo "The version number should be of the form vXX_XX." + echo "The should be of the form vXX_XX." + echo "The optional [install dir] defaults to '$path'." echo "" - exit -1 + exit 1 } @@ -24,10 +27,9 @@ if [ ${#@} != 1 ]; then fi # useful vars -path=/grid/fermiapp/products/dune/ -reponame="dune_plot_style" +reponame="dune_plot_style" version=$1 -tmpdir=/tmp/${reponame}_${version} +if [ -n "$2" ]; then path="$2"; fi if [[ ! ${version} =~ v[0-9][0-9]_[0-9][0-9] ]]; then echo "" @@ -35,9 +37,30 @@ if [[ ! ${version} =~ v[0-9][0-9]_[0-9][0-9] ]]; then usage fi -echo "Tagging ${reponame} ${version}" +if ! [ -d "$path" ]; then + echo "" + echo "Requested install directory does not exist: '$path'" + usage +fi -source /grid/fermiapp/products/dune/setup_dune.sh +tmpdir="$(mktemp --directory /tmp/${reponame}_${version}.XXXXXXXXXX)" + +echo "Tagging ${reponame} ${version}" +echo "workdir: ${tmpdir}" + +if [[ $SETUP_UPS =~ .*products/dune ]]; then + # UPS is already set up, likely correctly + pass +elif [ -f /grid/fermiapp/products/dune/setup_dune.sh ]; then + source /grid/fermiapp/products/dune/setup_dune.sh +elif [ -f /cvmfs/dune.opensciencegrid.org/products/dune/setup_dune.sh ]; then + source /cvmfs/dune.opensciencegrid.org/products/dune/setup_dune.sh +else + echo "Can't set up DUNE UPS products!" + echo "Ensure setup_dune.sh is accessible either in /grid/fermiapp/products/dune or /cvmfs/dune.opensciencegrid.org/products/dune." + echo "Can't continue." + exit 1 +fi echo "Printing active products" echo "-------------------------------------------" @@ -46,9 +69,9 @@ echo "-------------------------------------------" # check if the first argument is a valid path if [ -d "${tmpdir}" ]; then - echo "${tmpdir} is already exists! Cannot do clean checkout!" + echo "${tmpdir} already exists! Cannot do clean checkout!" echo "Aborting" - exit -1 + exit 1 fi # pull the latest version of the git repo and put it in the product directory @@ -56,18 +79,35 @@ fi # clone to temp directory git clone -b ${version} git@github.com:DUNE/${reponame}.git ${tmpdir}/${reponame}-preorg +preorg_dir="${tmpdir}/${reponame}-preorg" + +# the exported CMake package files need to be autogenerated by running CMake +if which cmake > /dev/null 2>&1; then + builddir="$(mktemp --directory --tmpdir ${tmpdir} cmake-build.XXXXXXXXXX)" + + echo "Running CMake to generate CMake package files." + echo "Build directory: $builddir" + + pushd $builddir || exit 1 + cmake -DCMAKE_INSTALL_PREFIX=${preorg_dir} ${preorg_dir} || exit 1 + make install || exit 1 + popd || exit 1 +else + echo "WARNING: CMake is not available, so the CMake interface will not be installed. Check that's what you expected!" +fi # need to do some reogranising for the ups product mkdir -p ${tmpdir}/${reponame}/python/dunestyle/matplotlib mkdir -p ${tmpdir}/${reponame}/python/dunestyle/root -mv ${tmpdir}/${reponame}-preorg/src/matplotlib/stylelib ${tmpdir}/${reponame}/ -mv ${tmpdir}/${reponame}-preorg/src/root/cpp/include ${tmpdir}/${reponame}/ -mv ${tmpdir}/${reponame}-preorg/src/__init__.py ${tmpdir}/${reponame}/python/dunestyle/ -mv ${tmpdir}/${reponame}-preorg/src/matplotlib/python/* ${tmpdir}/${reponame}/python/dunestyle/matplotlib -mv ${tmpdir}/${reponame}-preorg/src/root/python/* ${tmpdir}/${reponame}/python/dunestyle/root -mv ${tmpdir}/${reponame}-preorg/examples ${tmpdir}/${reponame}/ -mv ${tmpdir}/${reponame}-preorg/ups/ ${tmpdir}/${reponame}/ -rm -rf ${tmpdir}/${reponame}-preorg +mv ${preorg_dir}/src/matplotlib/stylelib ${tmpdir}/${reponame}/ +mv ${preorg_dir}/src/root/cpp/include ${tmpdir}/${reponame}/ +mv ${preorg_dir}/src/__init__.py ${tmpdir}/${reponame}/python/dunestyle/ +mv ${preorg_dir}/src/matplotlib/python/* ${tmpdir}/${reponame}/python/dunestyle/matplotlib +mv ${preorg_dir}/src/root/python/* ${tmpdir}/${reponame}/python/dunestyle/root +mv ${preorg_dir}/examples ${tmpdir}/${reponame}/ +mv ${preorg_dir}/ups/ ${tmpdir}/${reponame}/ +mv ${preorg_dir}/share/ ${tmpdir}/${reponame}/ +rm -rf ${preorg_dir} proddir=${path}/${reponame} dest=${proddir}/${version}/NULL From c7fb85bb52a09e1fe1de9c2be7926fa62332625b Mon Sep 17 00:00:00 2001 From: Jeremy Wolcott Date: Wed, 19 Mar 2025 11:53:47 -0400 Subject: [PATCH 6/9] only try to build executable if ROOT is available --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 419c35d..f043116 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,6 @@ cmake_minimum_required(VERSION 3.12) project(DUNEPlotStyle VERSION 01.01 LANGUAGES CXX) -find_package(ROOT REQUIRED) - add_library(DUNEPlotStyle INTERFACE) target_include_directories(DUNEPlotStyle INTERFACE $ @@ -19,10 +17,12 @@ install(TARGETS DUNEPlotStyle LIBRARY DESTINATION lib/ PUBLIC_HEADER DESTINATION include/) -add_executable(DUNEPlotStyleExample examples/root/cpp/example.C) -target_link_libraries(DUNEPlotStyleExample DUNEPlotStyle ROOT::Core ROOT::Hist ROOT::Gpad ROOT::Postscript) -install(TARGETS DUNEPlotStyleExample) - +find_package(ROOT) +if (ROOT_FOUND) + add_executable(DUNEPlotStyleExample examples/root/cpp/example.C) + target_link_libraries(DUNEPlotStyleExample DUNEPlotStyle ROOT::Core ROOT::Hist ROOT::Gpad ROOT::Postscript) + install(TARGETS DUNEPlotStyleExample) +endif() include(CMakePackageConfigHelpers) write_basic_package_version_file( From 4efe6d9836d3d2abf7b2a64e1b543fd7911631dc Mon Sep 17 00:00:00 2001 From: Jeremy Wolcott Date: Wed, 19 Mar 2025 14:29:54 -0400 Subject: [PATCH 7/9] missed one of the export location swaps --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f043116..6a2bd28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,7 @@ configure_package_config_file( "${PROJECT_BINARY_DIR}/DUNEPlotStyleConfig.cmake" INSTALL_DESTINATION share/cmake/DUNEPlotStyle ) -install(EXPORT DUNEPlotStyleTargets DESTINATION lib/cmake/DUNEPlotStyle) +install(EXPORT DUNEPlotStyleTargets DESTINATION share/cmake/DUNEPlotStyle) install(FILES "${PROJECT_BINARY_DIR}/DUNEPlotStyleConfigVersion.cmake" "${PROJECT_BINARY_DIR}/DUNEPlotStyleConfig.cmake" DESTINATION share/cmake/DUNEPlotStyle) \ No newline at end of file From c9cf9e2e2f8e45c8b9cbc289e284742c909fb1bc Mon Sep 17 00:00:00 2001 From: Jeremy Wolcott Date: Wed, 19 Mar 2025 14:30:13 -0400 Subject: [PATCH 8/9] use a more canonical CMAKE_PREFIX_PATH --- ups/dune_plot_style.table | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ups/dune_plot_style.table b/ups/dune_plot_style.table index a355d46..c30e0c6 100644 --- a/ups/dune_plot_style.table +++ b/ups/dune_plot_style.table @@ -18,4 +18,4 @@ ACTION=SETUP PathPrepend(PYTHONPATH, ${UPS_PROD_DIR}/python) PathPrepend(MPLCONFIGDIR, ${UPS_PROD_DIR}/stylelib/) PathPrepend(ROOT_INCLUDE_PATH, ${UPS_PROD_DIR}/include) - PathPrepend(CMAKE_PREFIX_PATH, ${UPS_PROD_DIR}/share/cmake) + PathPrepend(CMAKE_PREFIX_PATH, ${UPS_PROD_DIR}) # CMake will search in {path}/share/cmake/ From 4632f16e3e207ea935afd27905f5d447058244b5 Mon Sep 17 00:00:00 2001 From: Jeremy Wolcott Date: Wed, 19 Mar 2025 14:42:03 -0400 Subject: [PATCH 9/9] fix up some UPS things so that install works --- ups/make_dune_plot_style_ups_product.sh | 30 +++++++++---------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/ups/make_dune_plot_style_ups_product.sh b/ups/make_dune_plot_style_ups_product.sh index 77f7a7a..fee9b46 100644 --- a/ups/make_dune_plot_style_ups_product.sh +++ b/ups/make_dune_plot_style_ups_product.sh @@ -22,7 +22,7 @@ usage() { # setup # ----------------------------------------------------------------------------- -if [ ${#@} != 1 ]; then +if [ ${#@} -lt 1 ] || [ ${#@} -gt 2 ]; then usage fi @@ -67,23 +67,17 @@ echo "-------------------------------------------" ups active echo "-------------------------------------------" -# check if the first argument is a valid path -if [ -d "${tmpdir}" ]; then - echo "${tmpdir} already exists! Cannot do clean checkout!" - echo "Aborting" - exit 1 -fi # pull the latest version of the git repo and put it in the product directory # ----------------------------------------------------------------------------- # clone to temp directory -git clone -b ${version} git@github.com:DUNE/${reponame}.git ${tmpdir}/${reponame}-preorg preorg_dir="${tmpdir}/${reponame}-preorg" +git clone -b ${version} git@github.com:DUNE/${reponame}.git ${preorg_dir} # the exported CMake package files need to be autogenerated by running CMake if which cmake > /dev/null 2>&1; then - builddir="$(mktemp --directory --tmpdir ${tmpdir} cmake-build.XXXXXXXXXX)" + builddir="$(mktemp --directory ${tmpdir}/cmake-build.XXXXXXXXXX)" echo "Running CMake to generate CMake package files." echo "Build directory: $builddir" @@ -110,7 +104,7 @@ mv ${preorg_dir}/share/ ${tmpdir}/${reponame}/ rm -rf ${preorg_dir} proddir=${path}/${reponame} -dest=${proddir}/${version}/NULL +dest=${proddir}/${version} echo "$reponame will be created in $dest" @@ -156,22 +150,18 @@ echo "Updating table file" sed -i -e "s:XXVERSIONXX:${version}:" \ ${ups_table} -echo "Declaring product ${reponame} with version ${version} to UPS." +echo +echo "Declaring product ${reponame} with version ${version} to UPS:" # declare to ups -ups declare -f NULL -z ${path} -c \ - -r ${path}/${reponame}/${version}/ \ - -m ${reponame}.table \ - ${reponame} ${version} - -# I am sure there's a nicer way to do this but for now... -mv ${path}/${reponame}/${version}.version ${path}/${reponame}/NULL -mkdir ${path}/${reponame}/${version}.version/ -mv ${path}/${reponame}/NULL ${path}/${reponame}/${version}.version/ +cmd="ups declare -f NULL -z ${path} -c -r ${path}/${reponame}/${version} -m ${path}/${reponame}/${version}/ups/${reponame}.table ${reponame} ${version}" +echo "$cmd" +eval $cmd retval=$? test $retval -ne 0 && echo "Error! 'ups declare' returned non-zero - BAILING" && exit 1 rm -rf ${tmpdir} +echo echo "Done"