diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..6a2bd28 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,41 @@ +cmake_minimum_required(VERSION 3.12) +project(DUNEPlotStyle VERSION 01.01 LANGUAGES CXX) + +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/) + +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( + "${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 share/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 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 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 diff --git a/ups/dune_plot_style.table b/ups/dune_plot_style.table index 8624f3b..c30e0c6 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}) # CMake will search in {path}/share/cmake/ diff --git a/ups/make_dune_plot_style_ups_product.sh b/ups/make_dune_plot_style_ups_product.sh index a5a28ae..fee9b46 100644 --- a/ups/make_dune_plot_style_ups_product.sh +++ b/ups/make_dune_plot_style_ups_product.sh @@ -3,31 +3,33 @@ # 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 } # setup # ----------------------------------------------------------------------------- -if [ ${#@} != 1 ]; then +if [ ${#@} -lt 1 ] || [ ${#@} -gt 2 ]; then usage 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,42 +37,74 @@ 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 "-------------------------------------------" ups active echo "-------------------------------------------" -# check if the first argument is a valid path -if [ -d "${tmpdir}" ]; then - echo "${tmpdir} is 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}/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 +dest=${proddir}/${version} echo "$reponame will be created in $dest" @@ -116,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"