From 88e2ba4cf4274ce3dfbeb6b6d66b1f92afa308fe Mon Sep 17 00:00:00 2001
From: Erik Jensen <ej@phys.au.dk>
Date: Sun, 12 Feb 2023 14:56:13 +0100
Subject: [PATCH] update to "Modern CMake"

---
 CMakeLists.txt                 | 101 +++----------
 README.md                      |  46 +++++-
 VERSION                        |   1 +
 cleanup.sh                     |   2 -
 cmake/FindAUSALIB.cmake        |  27 ----
 cmake/FindROOT.cmake           | 268 ---------------------------------
 cmake/FindRapidJSON.cmake      |  97 ------------
 cmake/FindUnitTest++.cmake     |  46 ------
 cmake/dependencies.cmake       |   1 +
 cmake/install_targets.cmake    |  40 +++++
 cmake/target_definitions.cmake |  13 ++
 cmake/vklibConfig.cmake.in     |  15 ++
 compile.sh                     |   7 -
 include/vklib/VKRawReader.h    |   1 -
 include/vklib/VKSortedWriter.h |   1 -
 include/vklib/VKSorter.h       |   1 -
 sort.cpp                       |   3 +-
 test/VKRawReaderTest.cpp       |   1 -
 test/VKSortedWriterTest.cpp    |   1 -
 test/VKSorterTest.cpp          |   1 -
 20 files changed, 126 insertions(+), 547 deletions(-)
 create mode 100644 VERSION
 delete mode 100755 cleanup.sh
 delete mode 100644 cmake/FindAUSALIB.cmake
 delete mode 100644 cmake/FindROOT.cmake
 delete mode 100644 cmake/FindRapidJSON.cmake
 delete mode 100644 cmake/FindUnitTest++.cmake
 create mode 100644 cmake/dependencies.cmake
 create mode 100644 cmake/install_targets.cmake
 create mode 100644 cmake/target_definitions.cmake
 create mode 100644 cmake/vklibConfig.cmake.in
 delete mode 100755 compile.sh

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9030387..5619260 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,89 +1,22 @@
-cmake_minimum_required(VERSION 2.8)
+# Note for developers: PROJECT_VERSION is set in the file named "VERSION"
+# at the root of the project. You are encouraged to increment this once in
+# a while, if you feel like it, when pushing an update to the repository.
+# In CMake, project versioning has the following syntax:
+#     MAJOR[.MINOR[.PATCH[.TWEAK]]]
+cmake_minimum_required(VERSION 3.15)
 project(vklib)
+file(READ ${CMAKE_SOURCE_DIR}/VERSION CMAKE_PROJECT_VERSION) # set vklib project version
 
-# Tell cmake where to look for cmake modules.
-set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake")
+# Fetch custom CMake scripts commonly used across AUSA projects
+include(FetchContent)
+FetchContent_Declare(cmake_common GIT_REPOSITORY https://gitlab.au.dk/ausa/cmake_common.git)
+FetchContent_MakeAvailable(cmake_common)
 
-# Lets write modern C++
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+# Procure required and optional packages
+include(cmake/dependencies.cmake)
 
+# Define project targets, specify their dependencies, prepare their linkage, etc.
+include(cmake/target_definitions.cmake)
 
-############################################
-##          Define IDSlib target          ##
-############################################
-include_directories(include)
-
-# Find files to compile
-file(GLOB_RECURSE HEADERS "include/*")
-file(GLOB_RECURSE SOURCE  "source/*.cpp")
-
-add_library(vklib ${HEADERS} ${SOURCE} ${GIT_FILE})
-
-add_executable(vksort sort.cpp)
-
-
-############################################
-##              Dependencies              ##
-############################################
-
-# Variable for holding dependant libraries
-set(LIBRARIES "")
-
-# Include AUSAlib. Look in cmake/FindAUSALIB.cmake for how the specify location
-find_package(AUSALIB REQUIRED)
-if (AUSALIB_FOUND)
-	include_directories(${AUSALIB_INCLUDES})
-	list(APPEND LIBRARIES ${AUSALIB_LIBRARIES})
-endif (AUSALIB_FOUND)
-
-# Include ROOT
-find_package(ROOT REQUIRED)
-if (ROOT_FOUND)
-	include_directories(${ROOT_INCLUDE_DIR})
-	link_directories(${ROOT_LIBRARY_DIR})
-	list(APPEND LIBRARIES ${ROOT_LIBRARIES} Spectrum MathMore Proof TreePlayer)
-endif(ROOT_FOUND)
-
-message (STATUS ${ROOT_INCLUDE_DIR})
-
-
-# Add libraries to target
-target_link_libraries(vklib ${LIBRARIES})
-target_link_libraries(vksort vklib ${LIBRARIES})
-
-
-#########################################
-##        Unit testing          ##
-#########################################
-find_package(UnitTest++)
-
-if(UNITTEST_FOUND)
-  message(STATUS "Compiling unit test")
-  file(GLOB_RECURSE TEST_SRC
-          "test/*.h"
-          "test/*.cpp")
-  add_executable(vktest ${TEST_SRC})
-  target_link_libraries(vktest debug ${UNITTEST_DEBUG_LIBRARIES} general ${UNITTEST_LIBRARIES})
-  target_link_libraries(vktest vklib ${LIBRARIES})
-else(UNITTEST_FOUND)
-  message(STATUS "Not compilin unit tests. Add libunittest++-dev to your system if you want this")
-endif(UNITTEST_FOUND)
-
-
-#########################################
-##        Installation target          ##
-#########################################
-
-# Installation target
-INSTALL(TARGETS vklib
-		RUNTIME DESTINATION bin
-		LIBRARY DESTINATION lib
-		ARCHIVE DESTINATION lib
-		)
-
-install(DIRECTORY include/vklib DESTINATION include)
-
-INSTALL(TARGETS vksort
-		RUNTIME DESTINATION bin
-		)
-
+# Define and prepare installation targets
+include(cmake/install_targets.cmake)
diff --git a/README.md b/README.md
index 98a0ef3..87617e0 100644
--- a/README.md
+++ b/README.md
@@ -1,19 +1,49 @@
 # VKSort
 
-This project installs the software **vksort** originally authored by 
-[Oliver Kirsebom in 2017](https://gitlab.au.dk/ausa/oliskir/vksort)
-for use at the Veikon Kone spectrometer at the JYFL laboratory in Findland.
+This project installs the software **vksort** originally authored by
+Oliver Kirsebom in 2017 (see commit `24f8b49b` from January 2018 and earlier)
+for use at the Veikon Kone spectrometer at the JYFL laboratory in Finland.
 
-The software sorts [CAEN MC²Analyzer](https://www.caen.it/products/mc2analyzer/) 
-*List Mode data* based on a time coincidence gate and saves the sorted output to a 
+The software sorts [CAEN MC²Analyzer](https://www.caen.it/products/mc2analyzer/)
+*List Mode data* based on a time coincidence gate and saves the sorted output to a
 ROOT tree.
 
 ### Installation
 
-The prerequisites for installing the software are 
+The prerequisites for installing the software are
 * CMake
 * ROOT
 * AUSAlib
 
-The software is installed by running the script `compile.sh` in the root directory 
-of the project.
+The software is installed by running the following commands from the root of the project
+
+```shell
+mkdir build
+cd build
+cmake ..
+cmake --build .
+sudo cmake --install .
+```
+
+### Usage
+
+After installation, the executable `vksort` can be run from anywhere.
+
+By default, `vksort` expects the presence of a file `config.txt` wherever it is run.
+This file specifies the path to a directory -- called `data` in the config file -- in which the subdirectories `raw` and `sorted` should already exist.
+
+The `raw` subdirectory is to contain List Mode data files of the form `XXXX_chYYY.txt` where `XXXX` is a zero-padded digit string of length 4 indicating a given run number, and `YYY` is a zero-padded digit string of length 3 indicating a given channel of the run.
+The `sorted` subdirectory will contain corresponding ROOT files of the form `sXXXX_00.root` when `vksort` has been run successfully.
+
+In addition, the file `config.txt` also specifies mappings of channel ids to file paths containing calibration coefficients.
+These paths are relative to the `data` directory.
+
+See the file `config.txt` and files `calib/ch*.calib` provided with the source code for an example of this.
+
+After installation, run
+
+```shell
+vksort --help
+```
+
+to see the program's usage and all the tunable parameters of the program.
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..b123147
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+1.1
\ No newline at end of file
diff --git a/cleanup.sh b/cleanup.sh
deleted file mode 100755
index 26ee46f..0000000
--- a/cleanup.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/bash
-rm -rf CMakeCache.txt CMakeFiles libidslib.a cmake_install.cmake libvklib.a Makefile vksort
diff --git a/cmake/FindAUSALIB.cmake b/cmake/FindAUSALIB.cmake
deleted file mode 100644
index 01a7872..0000000
--- a/cmake/FindAUSALIB.cmake
+++ /dev/null
@@ -1,27 +0,0 @@
-# Tries to determine the location of AUSAlib.
-# It will try to look in the systems include/lib paths
-#
-# You have two options if you want to have a local build of AUSAlib.
-#
-# 1) Set these two environment variables
-#  AUSALIB_INC_DIR  Include directory
-#  AUSALIB_LIB_DIR  Directory containing the build library
-#
-# 2) Set this single environment variable
-#  AUSALIBPATH      Path that should contain libAUSA.a and ausa/AUSA.h directly or inside include
-
-if (AUSALIB_INCLUDES)
-    # Already in cache, be silent
-    set (AUSALIB_FIND_QUIETLY TRUE)
-endif (AUSALIB_INCLUDES)
-
-find_path (AUSALIB_INCLUDES ausa/AUSA.h
-        HINTS $ENV{AUSALIBPATH}/include ENV AUSALIB_INC_DIR ENV AUSALIBPATH)
-
-find_library(AUSALIB_LIBRARIES AUSA
-        HINTS ENV AUSALIB_LIB_DIR ENV AUSALIBPATH)
-
-# Handle the QUIETLY and REQUIRED arguments and set AUSALIB_FOUND to TRUE if
-# all listed variables are TRUE
-include (FindPackageHandleStandardArgs)
-find_package_handle_standard_args (AUSALIB DEFAULT_MSG AUSALIB_LIBRARIES AUSALIB_INCLUDES)
\ No newline at end of file
diff --git a/cmake/FindROOT.cmake b/cmake/FindROOT.cmake
deleted file mode 100644
index 9c7e580..0000000
--- a/cmake/FindROOT.cmake
+++ /dev/null
@@ -1,268 +0,0 @@
-# - Find ROOT instalation
-# This module tries to find the ROOT installation on your system.
-# It tries to find the root-config script which gives you all the needed information.
-# If the system variable ROOTSYS is set this is straight forward.
-# If not the module uses the pathes given in ROOT_CONFIG_SEARCHPATH.
-# If you need an other path you should add this path to this varaible.  
-# The root-config script is then used to detect basically everything else.
-# This module defines a number of key variables and macros.
-
-# F.Uhlig@gsi.de (fairroot.gsi.de)
-
-
-MESSAGE(STATUS "Looking for Root...")
-
-SET(ROOT_CONFIG_SEARCHPATH
-  ${SIMPATH}/tools/root/bin
-  $ENV{ROOTSYS}/bin
-)
-
-SET(ROOT_DEFINITIONS "")
-
-SET(ROOT_INSTALLED_VERSION_TOO_OLD FALSE)
-
-SET(ROOT_CONFIG_EXECUTABLE ROOT_CONFIG_EXECUTABLE-NOTFOUND)
-
-FIND_PROGRAM(ROOT_CONFIG_EXECUTABLE NAMES root-config PATHS
-   ${ROOT_CONFIG_SEARCHPATH})
-    
-IF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
-  MESSAGE( FATAL_ERROR "ROOT not installed in the searchpath and ROOTSYS is not set. Please
- set ROOTSYS or add the path to your ROOT installation in the Macro FindROOT.cmake in the
- subdirectory cmake/modules.")
-ELSE (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
-  STRING(REGEX REPLACE "(^.*)/bin/root-config" "\\1" ../test ${ROOT_CONFIG_EXECUTABLE})
-  SET( ENV{ROOTSYS} ${test})
-  set( ROOTSYS ${test})
-ENDIF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")  
-
- 
-IF (ROOT_CONFIG_EXECUTABLE)
-   
-  SET(ROOT_FOUND FALSE)
-
-  EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE} ARGS "--version" OUTPUT_VARIABLE ROOTVERSION)
-
-  MESSAGE(STATUS "Looking for Root... - found $ENV{ROOTSYS}/bin/root")
-  MESSAGE(STATUS "Looking for Root... - version ${ROOTVERSION} ")   
-
-  # we need at least version 5.00/00
-  IF (NOT ROOT_MIN_VERSION)
-    SET(ROOT_MIN_VERSION "5.00/00")
-  ENDIF (NOT ROOT_MIN_VERSION)
-   
-  # now parse the parts of the user given version string into variables
-  STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+" "\\1" req_root_major_vers "${ROOT_MIN_VERSION}")
-  STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" req_root_minor_vers "${ROOT_MIN_VERSION}")
-  STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+)" "\\1" req_root_patch_vers "${ROOT_MIN_VERSION}")
-   
-  # and now the version string given by qmake
-  STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+.*" "\\1" found_root_major_vers "${ROOTVERSION}")
-  STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" found_root_minor_vers "${ROOTVERSION}")
-  STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+).*" "\\1" found_root_patch_vers "${ROOTVERSION}")
-
-  IF (found_root_major_vers LESS 5)
-    MESSAGE( FATAL_ERROR "Invalid ROOT version \"${ROOTERSION}\", at least major version 4 is required, e.g. \"5.00/00\"")
-  ENDIF (found_root_major_vers LESS 5)
-
-  # compute an overall version number which can be compared at once
-  MATH(EXPR req_vers "${req_root_major_vers}*10000 + ${req_root_minor_vers}*100 + ${req_root_patch_vers}")
-  MATH(EXPR found_vers "${found_root_major_vers}*10000 + ${found_root_minor_vers}*100 + ${found_root_patch_vers}")
-   
-  IF (found_vers LESS req_vers)
-    SET(ROOT_FOUND FALSE)
-    SET(ROOT_INSTALLED_VERSION_TOO_OLD TRUE)
-  ELSE (found_vers LESS req_vers)
-    SET(ROOT_FOUND TRUE)
-  ENDIF (found_vers LESS req_vers)
-
-ENDIF (ROOT_CONFIG_EXECUTABLE)
-
-
-IF (ROOT_FOUND)
-
-  # ask root-config for the library dir
-  # Set ROOT_LIBRARY_DIR
-
-  EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
-    ARGS "--libdir"
-    OUTPUT_VARIABLE ROOT_LIBRARY_DIR_TMP )
-
-  IF(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
-    SET(ROOT_LIBRARY_DIR ${ROOT_LIBRARY_DIR_TMP} )
-  ELSE(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
-    MESSAGE("Warning: ROOT_CONFIG_EXECUTABLE reported ${ROOT_LIBRARY_DIR_TMP} as library path,")
-    MESSAGE("Warning: but ${ROOT_LIBRARY_DIR_TMP} does NOT exist, ROOT must NOT be installed correctly.")
-  ENDIF(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
-    
-  # ask root-config for the binary dir
-  EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE}
-    ARGS "--bindir"
-    OUTPUT_VARIABLE root_bins )
-  SET(ROOT_BINARY_DIR ${root_bins})
-
-  # ask root-config for the include dir
-  EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
-    ARGS "--incdir" 
-    OUTPUT_VARIABLE root_headers )
-  SET(ROOT_INCLUDE_DIR ${root_headers})
-      # CACHE INTERNAL "")
-
-  # ask root-config for the library varaibles
-  EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
-#    ARGS "--noldflags --noauxlibs --libs" 
-    ARGS "--glibs" 
-    OUTPUT_VARIABLE root_flags )
-
-#  STRING(REGEX MATCHALL "([^ ])+"  root_libs_all ${root_flags})
-#  STRING(REGEX MATCHALL "-L([^ ])+"  root_library ${root_flags})
-#  REMOVE_FROM_LIST(root_flags "${root_libs_all}" "${root_library}")
-
-  SET(ROOT_LIBRARIES ${root_flags})
-
-  # Make variables changeble to the advanced user
-  MARK_AS_ADVANCED( ROOT_LIBRARY_DIR ROOT_INCLUDE_DIR ROOT_DEFINITIONS)
-
-  # Set ROOT_INCLUDES
-  SET( ROOT_INCLUDES ${ROOT_INCLUDE_DIR})
-
-  SET(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${ROOT_LIBRARY_DIR})
-
-  #######################################
-  #
-  #       Check the executables of ROOT 
-  #          ( rootcint ) 
-  #
-  #######################################
-
-  FIND_PROGRAM(ROOT_CINT_EXECUTABLE
-    NAMES rootcint
-    PATHS ${ROOT_BINARY_DIR}
-    NO_DEFAULT_PATH
-    )
-
-ENDIF (ROOT_FOUND)
-
-
-
-  ###########################################
-  #
-  #       Macros for building ROOT dictionary
-  #
-  ###########################################
-
-MACRO (ROOT_GENERATE_DICTIONARY_OLD )
- 
-   set(INFILES "")    
-
-   foreach (_current_FILE ${ARGN})
-
-     IF (${_current_FILE} MATCHES "^.*\\.h$")
-       IF (${_current_FILE} MATCHES "^.*Link.*$")
-         set(LINKDEF_FILE ${_current_FILE})
-       ELSE (${_current_FILE} MATCHES "^.*Link.*$")
-         set(INFILES ${INFILES} ${_current_FILE})
-       ENDIF (${_current_FILE} MATCHES "^.*Link.*$")
-     ELSE (${_current_FILE} MATCHES "^.*\\.h$")
-       IF (${_current_FILE} MATCHES "^.*\\.cxx$")
-         set(OUTFILE ${_current_FILE})
-       ELSE (${_current_FILE} MATCHES "^.*\\.cxx$")
-         set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})   
-       ENDIF (${_current_FILE} MATCHES "^.*\\.cxx$")
-     ENDIF (${_current_FILE} MATCHES "^.*\\.h$")
-     
-   endforeach (_current_FILE ${ARGN})
-   
-#  MESSAGE("INFILES: ${INFILES}")
-#  MESSAGE("OutFILE: ${OUTFILE}")
-#  MESSAGE("LINKDEF_FILE: ${LINKDEF_FILE}")
-#  MESSAGE("INCLUDE_DIRS: ${INCLUDE_DIRS}")
-
-   STRING(REGEX REPLACE "(^.*).cxx" "\\1.h" bla "${OUTFILE}")
-#   MESSAGE("BLA: ${bla}")
-   SET (OUTFILES ${OUTFILE} ${bla})
-
-   ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
-      COMMAND ${ROOT_CINT_EXECUTABLE}
-      ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES})
-
-#   MESSAGE("ROOT_CINT_EXECUTABLE has created the dictionary ${OUTFILE}")
-
-ENDMACRO (ROOT_GENERATE_DICTIONARY_OLD)
-
-  ###########################################
-  #
-  #       Macros for building ROOT dictionary
-  #
-  ###########################################
-
-MACRO (ROOT_GENERATE_DICTIONARY INFILES LINKDEF_FILE OUTFILE INCLUDE_DIRS_IN)
- 
-  set(INCLUDE_DIRS)
-
-  foreach (_current_FILE ${INCLUDE_DIRS_IN})
-    set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})   
-  endforeach (_current_FILE ${INCLUDE_DIRS_IN})
- 
-
-#  MESSAGE("INFILES: ${INFILES}")
-#  MESSAGE("OutFILE: ${OUTFILE}")
-#  MESSAGE("LINKDEF_FILE: ${LINKDEF_FILE}")
-#  MESSAGE("INCLUDE_DIRS: ${INCLUDE_DIRS}")
-
-  STRING(REGEX REPLACE "^(.*)\\.(.*)$" "\\1.h" bla "${OUTFILE}")
-#  MESSAGE("BLA: ${bla}")
-  SET (OUTFILES ${OUTFILE} ${bla})
-
-
-  if (CMAKE_SYSTEM_NAME MATCHES Linux)
-    ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
-       COMMAND LD_LIBRARY_PATH=${ROOT_LIBRARY_DIR} ROOTSYS=${ROOTSYS} ${ROOT_CINT_EXECUTABLE}
-       ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES} ${LINKDEF_FILE})
-  else (CMAKE_SYSTEM_NAME MATCHES Linux)
-    if (CMAKE_SYSTEM_NAME MATCHES Darwin)
-      ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
-       COMMAND DYLD_LIBRARY_PATH=${ROOT_LIBRARY_DIR} ROOTSYS=${ROOTSYS} ${ROOT_CINT_EXECUTABLE}
-       ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES} ${LINKDEF_FILE})
-    endif (CMAKE_SYSTEM_NAME MATCHES Darwin)
-  endif (CMAKE_SYSTEM_NAME MATCHES Linux)
-
-ENDMACRO (ROOT_GENERATE_DICTIONARY)
-
-MACRO (GENERATE_ROOT_TEST_SCRIPT SCRIPT_FULL_NAME)
-
-  get_filename_component(path_name ${SCRIPT_FULL_NAME} PATH)
-  get_filename_component(file_extension ${SCRIPT_FULL_NAME} EXT)
-  get_filename_component(file_name ${SCRIPT_FULL_NAME} NAME_WE)
-  set(shell_script_name "${file_name}.sh")
-
-  #MESSAGE("PATH: ${path_name}")
-  #MESSAGE("Ext: ${file_extension}")
-  #MESSAGE("Name: ${file_name}")
-  #MESSAGE("Shell Name: ${shell_script_name}")
-
-  string(REPLACE ..
-         ${PROJECT_BINARY_DIR} new_path ${path_name}
-        )
-
-  #MESSAGE("New PATH: ${new_path}")
-
-  file(MAKE_DIRECTORY ${new_path}/data)
-
-  CONVERT_LIST_TO_STRING(${LD_LIBRARY_PATH})
-  set(MY_LD_LIBRARY_PATH ${output})
-  set(my_script_name ${SCRIPT_FULL_NAME})
-
-  if(CMAKE_SYSTEM MATCHES Darwin)
-    configure_file(${PROJECT_SOURCE_DIR}/cmake/scripts/root_macro_macos.sh.in
-                   ${new_path}/${shell_script_name}
-                  )
-  else(CMAKE_SYSTEM MATCHES Darwin)
-    configure_file(${PROJECT_SOURCE_DIR}/cmake/scripts/root_macro.sh.in
-                   ${new_path}/${shell_script_name}
-                  )
-  endif(CMAKE_SYSTEM MATCHES Darwin)
-
-  EXEC_PROGRAM(/bin/chmod ARGS "u+x  ${new_path}/${shell_script_name}")
-
-ENDMACRO (GENERATE_ROOT_TEST_SCRIPT)
diff --git a/cmake/FindRapidJSON.cmake b/cmake/FindRapidJSON.cmake
deleted file mode 100644
index 7a0bf47..0000000
--- a/cmake/FindRapidJSON.cmake
+++ /dev/null
@@ -1,97 +0,0 @@
-# Copyright (c) 2011 Milo Yip (miloyip@gmail.com)
-# Copyright (c) 2013 Rafal Jeczalik (rjeczalik@gmail.com)
-# Distributed under the MIT License (see license.txt file)
-
-# -----------------------------------------------------------------------------------
-#
-# Finds the rapidjson library
-#
-# -----------------------------------------------------------------------------------
-#
-# Variables used by this module, they can change the default behaviour.
-# Those variables need to be either set before calling find_package
-# or exported as environment variables before running CMake:
-#
-# RAPIDJSON_INCLUDEDIR - Set custom include path, useful when rapidjson headers are
-#                        outside system paths
-# RAPIDJSON_USE_SSE2   - Configure rapidjson to take advantage of SSE2 capabilities
-# RAPIDJSON_USE_SSE42  - Configure rapidjson to take advantage of SSE4.2 capabilities
-#
-# -----------------------------------------------------------------------------------
-#
-# Variables defined by this module:
-#
-# RAPIDJSON_FOUND        - True if rapidjson was found
-# RAPIDJSON_INCLUDE_DIRS - Path to rapidjson include directory
-# RAPIDJSON_CXX_FLAGS    - Extra C++ flags required for compilation with rapidjson
-#
-# -----------------------------------------------------------------------------------
-#
-# Example usage:
-#
-#  set(RAPIDJSON_USE_SSE2 ON)
-#  set(RAPIDJSON_INCLUDEDIR "/opt/github.com/rjeczalik/rapidjson/include")
-#
-#  find_package(rapidjson REQUIRED)
-#
-#  include_directories("${RAPIDJSON_INCLUDE_DIRS}")
-#  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${RAPIDJSON_CXX_FLAGS}")
-#  add_executable(foo foo.cc)
-#
-# -----------------------------------------------------------------------------------
-
-foreach(opt RAPIDJSON_INCLUDEDIR RAPIDJSON_USE_SSE2 RAPIDJSON_USE_SSE42)
-  if(${opt} AND DEFINED ENV{${opt}} AND NOT ${opt} STREQUAL "$ENV{${opt}}")
-    message(WARNING "Conflicting ${opt} values: ignoring environment variable and using CMake cache entry.")
-  elseif(DEFINED ENV{${opt}} AND NOT ${opt})
-    set(${opt} "$ENV{${opt}}")
-  endif()
-endforeach()
-
-find_path(
-  RAPIDJSON_INCLUDE_DIRS
-  NAMES rapidjson/rapidjson.h
-  PATHS ${RAPIDJSON_INCLUDEDIR}
-  DOC "Include directory for the rapidjson library."
-)
-
-mark_as_advanced(RAPIDJSON_INCLUDE_DIRS)
-
-if(RAPIDJSON_INCLUDE_DIRS)
-  set(RAPIDJSON_FOUND TRUE)
-endif()
-
-mark_as_advanced(RAPIDJSON_FOUND)
-
-if(RAPIDJSON_USE_SSE42)
-  set(RAPIDJSON_CXX_FLAGS "-DRAPIDJSON_SSE42")
-  if(MSVC)
-    set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} /arch:SSE4.2")
-  else()
-    set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} -msse4.2")
-  endif()
-else()
-  if(RAPIDJSON_USE_SSE2)
-    set(RAPIDJSON_CXX_FLAGS "-DRAPIDJSON_SSE2")
-    if(MSVC)
-      set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} /arch:SSE2")
-    else()
-      set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} -msse2")
-    endif()
-  endif()
-endif()
-
-mark_as_advanced(RAPIDJSON_CXX_FLAGS)
-
-if(RAPIDJSON_FOUND)
-  if(NOT rapidjson_FIND_QUIETLY)
-    message(STATUS "Found rapidjson header files in ${RAPIDJSON_INCLUDE_DIRS}")
-    if(DEFINED RAPIDJSON_CXX_FLAGS)
-      message(STATUS "Found rapidjson C++ extra compilation flags: ${RAPIDJSON_CXX_FLAGS}")
-    endif()
-  endif()
-elseif(rapidjson_FIND_REQUIRED)
-    message(FATAL_ERROR "Could not find rapidjson")
-else()
-  message(STATUS "Optional package rapidjson was not found")
-endif()
diff --git a/cmake/FindUnitTest++.cmake b/cmake/FindUnitTest++.cmake
deleted file mode 100644
index 7f22230..0000000
--- a/cmake/FindUnitTest++.cmake
+++ /dev/null
@@ -1,46 +0,0 @@
-#
-# Find the UnitTest++ includes and library
-#
-# This module defines
-# UNITTEST_INCLUDE_DIR, where to find tiff.h, etc.
-# UNITTEST_LIBRARIES, the libraries to link against to use UnitTest++.
-# UNITTEST_FOUND, If false, do not try to use UnitTest++.
-
-# also defined, but not for general use are
-# UNITTEST_LIBRARY, where to find the UnitTest++ library.
-# UNITTEST_DEBUG_LIBRARY, where to find the UnitTest++ library in debug mode.
-
-FIND_PATH(UNITTEST_INCLUDE_DIR unittest++/UnitTest++.h
-  /usr/local/include
-  /usr/include
-)
-
-# With Win32, important to have both
-IF(WIN32)
-  FIND_LIBRARY(UNITTEST_LIBRARY UnitTest++
-               ${UNITTEST_INCLUDE_DIR}/../lib
-               /usr/local/lib
-               /usr/lib)
-  FIND_LIBRARY(UNITTEST_DEBUG_LIBRARY UnitTest++d
-               ${UNITTEST_INCLUDE_DIR}/../lib
-               /usr/local/lib
-               /usr/lib)
-ELSE(WIN32)
-  # On unix system, debug and release have the same name
-  FIND_LIBRARY(UNITTEST_LIBRARY UnitTest++
-               ${UNITTEST_INCLUDE_DIR}/../lib
-               /usr/local/lib
-               /usr/lib)
-  FIND_LIBRARY(UNITTEST_DEBUG_LIBRARY UnitTest++
-               ${UNITTEST_INCLUDE_DIR}/../lib
-               /usr/local/lib
-               /usr/lib)
-ENDIF(WIN32)
-
-IF(UNITTEST_INCLUDE_DIR)
-  IF(UNITTEST_LIBRARY)
-    SET(UNITTEST_FOUND "YES")
-    SET(UNITTEST_LIBRARIES ${UNITTEST_LIBRARY} ${CMAKE_DL_LIBS})
-    SET(UNITTEST_DEBUG_LIBRARIES ${UNITTEST_DEBUG_LIBRARY} ${CMAKE_DL_LIBS})
-  ENDIF(UNITTEST_LIBRARY)
-ENDIF(UNITTEST_INCLUDE_DIR)
\ No newline at end of file
diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake
new file mode 100644
index 0000000..ff4f148
--- /dev/null
+++ b/cmake/dependencies.cmake
@@ -0,0 +1 @@
+find_package(AUSALIB REQUIRED) # AUSAlib provides everything else
diff --git a/cmake/install_targets.cmake b/cmake/install_targets.cmake
new file mode 100644
index 0000000..53697fb
--- /dev/null
+++ b/cmake/install_targets.cmake
@@ -0,0 +1,40 @@
+# SO versioning
+set_target_properties(vk PROPERTIES SOVERSION ${PROJECT_VERSION})
+
+# Make the install targets
+install(TARGETS vk vksort
+        EXPORT vklibTargets         # note: preliminary step to exporting the library
+        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib
+        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bin
+        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib)
+# Install headers and resources as well, preserving directory hierarchy
+install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/vklib/ # use https://cmake.org/cmake/help/latest/command/target_sources.html#file-sets when CMake version >= 3.23 can be expected
+        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vklib
+        COMPONENT include)
+# For use with print_install_digest() at bottom of file
+list(APPEND INSTALL_COMPONENTS lib bin include)
+list(APPEND INSTALL_PATHS ${CMAKE_INSTALL_LIBDIR} ${CMAKE_INSTALL_BINDIR}
+        ${CMAKE_INSTALL_INCLUDEDIR}/vklib)
+
+# Export targets -- i.e. make find_package() work in other CMake projects
+set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}) # generic name, allowing easy reuse of vklibConfig.cmake.in
+set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}) # generic name, allowing easy reuse of vklibConfig.cmake.in
+install(EXPORT vklibTargets DESTINATION ${PROJECT_CMAKEDIR} NAMESPACE vklib:: COMPONENT dev)
+add_library(vklib::vk ALIAS vk) # this is good practice; using the library internally (e.g. in this CMakeLists.txt file) and externally (as an exported namespace, to be imported) is equivalent
+add_executable(vklib::vksort ALIAS vksort)
+include(CMakePackageConfigHelpers)
+write_basic_package_version_file(${PROJECT_BINARY_DIR}/${PROJECT_CMAKEDIR}/${PROJECT_NAME}ConfigVersion.cmake
+        VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion)
+configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
+        ${PROJECT_BINARY_DIR}/${PROJECT_CMAKEDIR}/${PROJECT_NAME}Config.cmake
+        INSTALL_DESTINATION ${PROJECT_CMAKEDIR}
+        PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR)
+install(FILES ${PROJECT_BINARY_DIR}/${PROJECT_CMAKEDIR}/${PROJECT_NAME}Config.cmake
+        ${PROJECT_BINARY_DIR}/${PROJECT_CMAKEDIR}/${PROJECT_NAME}ConfigVersion.cmake
+        DESTINATION ${PROJECT_CMAKEDIR} COMPONENT dev)
+# For use with print_install_digest() at bottom of file
+list(APPEND INSTALL_COMPONENTS dev)
+list(APPEND INSTALL_PATHS ${PROJECT_CMAKEDIR})
+
+# Report components to be installed to user
+print_install_digest("${INSTALL_COMPONENTS}" "${INSTALL_PATHS}") # Custom function
\ No newline at end of file
diff --git a/cmake/target_definitions.cmake b/cmake/target_definitions.cmake
new file mode 100644
index 0000000..b22eaae
--- /dev/null
+++ b/cmake/target_definitions.cmake
@@ -0,0 +1,13 @@
+# Prepare library 'vk'
+file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_SOURCE_DIR} CONFIGURE_DEPENDS "source/*.cpp")
+file(GLOB_RECURSE HEADERS RELATIVE ${CMAKE_SOURCE_DIR} CONFIGURE_DEPENDS "include/vklib/*.h")
+add_library(vk ${SOURCES} ${HEADERS})
+target_link_libraries(vk PUBLIC AUSA::AUSA)
+target_include_directories(vk PUBLIC $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
+        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
+
+# Prepare executable 'vksort'
+add_executable(vksort sort.cpp)
+target_link_libraries(vksort PRIVATE vk)
+target_include_directories(vksort PRIVATE $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
+        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
\ No newline at end of file
diff --git a/cmake/vklibConfig.cmake.in b/cmake/vklibConfig.cmake.in
new file mode 100644
index 0000000..0dfc961
--- /dev/null
+++ b/cmake/vklibConfig.cmake.in
@@ -0,0 +1,15 @@
+@PACKAGE_INIT@
+include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake)
+
+set_and_check(@PROJECT_NAME@_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
+set_and_check(@PROJECT_NAME@_LIBRARY_DIR "@PACKAGE_LIB_INSTALL_DIR@")
+
+include(CMakeFindDependencyMacro)
+# dependency => required
+find_dependency(AUSALIB)
+# package => optional
+# --- no optional packages here ---
+check_required_components(vk vksort)
+
+include(FindPackageMessage)
+find_package_message(@PROJECT_NAME@ "Found @PROJECT_NAME@: ${@PROJECT_NAME@_LIBRARY_DIR}" "[${@PROJECT_NAME@_LIBRARY_DIR}][${@PROJECT_NAME@_INCLUDE_DIR}]")
\ No newline at end of file
diff --git a/compile.sh b/compile.sh
deleted file mode 100755
index 8c286e1..0000000
--- a/compile.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/bash
-sh ./cleanup.sh
-mkdir -vp sorted raw
-echo "Place your data files with name ####_ch###.txt (#s being digits) in this directory, then run vksort from the parent directory." > raw/info.txt
-cmake ./
-make -j4
-echo "Library vksort compiled. Run \`./vksort --help\` to proceed."
diff --git a/include/vklib/VKRawReader.h b/include/vklib/VKRawReader.h
index 18387a2..555c123 100644
--- a/include/vklib/VKRawReader.h
+++ b/include/vklib/VKRawReader.h
@@ -3,7 +3,6 @@
 #define VK_RAW_READER_H
 
 #include <vector>   // vector
-#include <ausa/util/memory>
 #include <memory>
 
 #include <TSystem.h>
diff --git a/include/vklib/VKSortedWriter.h b/include/vklib/VKSortedWriter.h
index af66257..0a8a514 100644
--- a/include/vklib/VKSortedWriter.h
+++ b/include/vklib/VKSortedWriter.h
@@ -10,7 +10,6 @@
 #include <TFile.h>
 
 #include <vector>   // vector
-#include <ausa/util/memory>
 #include <memory>
 
 
diff --git a/include/vklib/VKSorter.h b/include/vklib/VKSorter.h
index 4051c42..020455b 100644
--- a/include/vklib/VKSorter.h
+++ b/include/vklib/VKSorter.h
@@ -8,7 +8,6 @@
 #include <TRandom3.h>
 
 #include <vector>   // vector
-#include <ausa/util/memory>
 #include <memory>
 
 
diff --git a/sort.cpp b/sort.cpp
index 5acf21f..713e705 100644
--- a/sort.cpp
+++ b/sort.cpp
@@ -3,7 +3,6 @@
 #include "vklib/VKRawReader.h"
 
 #include <string>
-#include <memory>
 #include <stdexcept>
 #include <iostream>
 #include <utility>
@@ -12,7 +11,7 @@
 #include <algorithm>    // std::find
 #include <fstream>
 
-#include <ausa/util/memory>
+#include <memory>
 #include <ausa/util/FileUtil.h>
 #include <ausa/util/StringUtil.h>
 
diff --git a/test/VKRawReaderTest.cpp b/test/VKRawReaderTest.cpp
index 9364169..6007bec 100644
--- a/test/VKRawReaderTest.cpp
+++ b/test/VKRawReaderTest.cpp
@@ -1,6 +1,5 @@
 
 #include <unittest++/UnitTest++.h>
-#include <ausa/util/memory> 
 #include <memory>
 #include <iostream>
 
diff --git a/test/VKSortedWriterTest.cpp b/test/VKSortedWriterTest.cpp
index cf3e617..8ddbbf5 100644
--- a/test/VKSortedWriterTest.cpp
+++ b/test/VKSortedWriterTest.cpp
@@ -1,6 +1,5 @@
 
 #include <unittest++/UnitTest++.h>
-#include <ausa/util/memory> 
 #include <memory>
 #include <iostream>
 #include <stdio.h>
diff --git a/test/VKSorterTest.cpp b/test/VKSorterTest.cpp
index 9ee6bfc..659dbd7 100644
--- a/test/VKSorterTest.cpp
+++ b/test/VKSorterTest.cpp
@@ -1,6 +1,5 @@
 
 #include <unittest++/UnitTest++.h>
-#include <ausa/util/memory> 
 #include <memory>
 #include <iostream>
 #include <stdio.h>
-- 
GitLab