From 8a435cbe9b8b6c04b9d72c13b520616ae997b10e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=B6jdh?= Date: Mon, 28 Oct 2024 16:26:14 +0100 Subject: [PATCH] WIP --- CMakeLists.txt | 145 ++++++++++++++++++++++++++++++++-- cmake/package_config.cmake | 35 ++++++++ cmake/project-config.cmake.in | 26 ++++++ conda-recipe/build.sh | 18 +++++ conda-recipe/copy_lib.sh | 19 +++++ conda-recipe/meta.yaml | 101 +++++++++++++++++++++++ docs/CMakeLists.txt | 15 ++-- docs/src/ClusterFinder.rst | 4 +- docs/src/Dtype.rst | 4 +- docs/src/File.rst | 4 +- docs/src/Frame.rst | 4 +- docs/src/NDArray.rst | 4 +- docs/src/NDView.rst | 4 +- docs/src/Pedestal.rst | 4 +- docs/src/VarClusterFinder.rst | 4 +- docs/src/index.rst | 8 +- docs/src/pyFile.rst | 11 +++ src/CMakeLists.txt | 8 +- 18 files changed, 393 insertions(+), 25 deletions(-) create mode 100644 cmake/package_config.cmake create mode 100644 cmake/project-config.cmake.in create mode 100644 conda-recipe/build.sh create mode 100644 conda-recipe/copy_lib.sh create mode 100644 conda-recipe/meta.yaml create mode 100644 docs/src/pyFile.rst diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fae609..7cab865 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,19 @@ -cmake_minimum_required(VERSION 3.12) - -set(CMAKE_CXX_STANDARD 17) #TODO! Global or per target? -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) +cmake_minimum_required(VERSION 3.14) project(aare - VERSION 0.1 + VERSION 1.0.0 DESCRIPTION "Data processing library for PSI detectors" HOMEPAGE_URL "https://github.com/slsdetectorgroup/aare" LANGUAGES C CXX ) -cmake_policy(SET CMP0135 NEW) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +if (${CMAKE_VERSION} VERSION_GREATER "3.24") + cmake_policy(SET CMP0135 NEW) #Fetch content download timestamp +endif() cmake_policy(SET CMP0079 NEW) include(GNUInstallDirs) @@ -61,6 +63,15 @@ if(AARE_FETCH_ZMQ) GIT_REPOSITORY https://github.com/zeromq/libzmq.git GIT_TAG v4.3.4 ) + # Disable unwanted options from libzmq + set(BUILD_TESTS OFF CACHE BOOL "Switch off libzmq test build") + set(BUILD_SHARED OFF CACHE BOOL "Switch off libzmq shared libs") + set(WITH_PERF_TOOL OFF CACHE BOOL "") + set(ENABLE_CPACK OFF CACHE BOOL "") + set(ENABLE_CLANG OFF CACHE BOOL "") + set(ENABLE_CURVE OFF CACHE BOOL "") + set(ENABLE_DRAFTS OFF CACHE BOOL "") + # TODO! Verify that this is what we want to do in aare # Using GetProperties and Populate to be able to exclude zmq # from install (not possible with FetchContent_MakeAvailable(libzmq)) @@ -89,8 +100,34 @@ else() find_package(fmt 6 REQUIRED) endif() +#TODO! Add options for nlohmann_json as well find_package(nlohmann_json 3.11.3 REQUIRED) + +include(GNUInstallDirs) + +# If conda build, always set lib dir to 'lib' +if($ENV{CONDA_BUILD}) + set(CMAKE_INSTALL_LIBDIR "lib") +endif() + +# Set lower / upper case project names +string(TOUPPER "${PROJECT_NAME}" PROJECT_NAME_UPPER) +string(TOLOWER "${PROJECT_NAME}" PROJECT_NAME_LOWER) + + +# Set targets export name (used by slsDetectorPackage and dependencies) +set(TARGETS_EXPORT_NAME "${PROJECT_NAME_LOWER}-targets") +set(namespace "aare::") + +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) + +# Check if project is being used directly or via add_subdirectory +set(AARE_MASTER_PROJECT OFF) +if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set(AARE_MASTER_PROJECT ON) +endif() + add_library(aare_compiler_flags INTERFACE) target_compile_features(aare_compiler_flags INTERFACE cxx_std_17) @@ -185,7 +222,94 @@ if(AARE_TESTS) add_subdirectory(tests) endif() -add_subdirectory(src) +###------------------------------------------------------------------------------MAIN LIBRARY +###------------------------------------------------------------------------------------------ + +set(PUBLICHEADERS + include/aare/ClusterFinder.hpp + include/aare/defs.hpp + include/aare/Dtype.hpp + include/aare/File.hpp + include/aare/FileInterface.hpp + include/aare/Frame.hpp + include/aare/json.hpp + include/aare/NDArray.hpp + include/aare/NDView.hpp + include/aare/NumpyFile.hpp + include/aare/NumpyHelpers.hpp + include/aare/Pedestal.hpp + include/aare/RawFile.hpp + include/aare/SubFile.hpp + include/aare/VarClusterFinder.hpp + +) + + +set(SourceFiles + ${CMAKE_CURRENT_SOURCE_DIR}/src/defs.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/Dtype.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/Frame.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/File.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/NumpyFile.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/RawFile.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/SubFile.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/NumpyHelpers.cpp +) + + +add_library(aare_core STATIC ${SourceFiles}) +target_include_directories(aare_core PUBLIC + "$" + "$" +) + +target_link_libraries(aare_core PUBLIC fmt::fmt PRIVATE aare_compiler_flags nlohmann_json::nlohmann_json) + +set_target_properties(aare_core PROPERTIES + # ARCHIVE_OUTPUT_NAME SlsDetectorStatic + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} + PUBLIC_HEADER "${PUBLICHEADERS}" +) + +if (AARE_PYTHON_BINDINGS) + set_property(TARGET aare_core PROPERTY POSITION_INDEPENDENT_CODE ON) +endif() + +if(AARE_TESTS) + set(TestSources + ${CMAKE_CURRENT_SOURCE_DIR}/src/defs.test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/Dtype.test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/Frame.test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/NDArray.test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/NDView.test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/ClusterFinder.test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/Pedestal.test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/NumpyFile.test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/NumpyHelpers.test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/RawFile.test.cpp + + ) + target_sources(tests PRIVATE ${TestSources} ) +endif() + + + +###------------------------------------------------------------------------------------------ +###------------------------------------------------------------------------------------------ + + +if(AARE_MASTER_PROJECT) + install(TARGETS aare_core aare_compiler_flags + EXPORT "${TARGETS_EXPORT_NAME}" + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/aare + ) +endif() + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(CMAKE_INSTALL_RPATH $ORIGIN) +set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) #Overall target to link to when using the library @@ -236,3 +360,8 @@ add_custom_target( VERBATIM ) +if(AARE_MASTER_PROJECT) + set(CMAKE_INSTALL_DIR "share/cmake/${PROJECT_NAME}") + set(PROJECT_LIBRARIES slsSupportShared slsDetectorShared slsReceiverShared) + include(cmake/package_config.cmake) +endif() \ No newline at end of file diff --git a/cmake/package_config.cmake b/cmake/package_config.cmake new file mode 100644 index 0000000..7070908 --- /dev/null +++ b/cmake/package_config.cmake @@ -0,0 +1,35 @@ +# This cmake code creates the configuration that is found and used by +# find_package() of another cmake project + +# get lower and upper case project name for the configuration files + +# configure and install the configuration files +include(CMakePackageConfigHelpers) + +configure_package_config_file( + "${CMAKE_SOURCE_DIR}/cmake/project-config.cmake.in" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME_LOWER}-config.cmake" + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME_LOWER} + PATH_VARS CMAKE_INSTALL_DIR) + +write_basic_package_version_file( + "${PROJECT_BINARY_DIR}/${PROJECT_NAME_LOWER}-config-version.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) + +install(FILES + "${PROJECT_BINARY_DIR}/${PROJECT_NAME_LOWER}-config.cmake" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME_LOWER}-config-version.cmake" + COMPONENT devel + DESTINATION ${CMAKE_INSTALL_DIR} +) + + +if (PROJECT_LIBRARIES OR PROJECT_STATIC_LIBRARIES) + install( + EXPORT "${TARGETS_EXPORT_NAME}" + FILE ${PROJECT_NAME_LOWER}-targets.cmake + DESTINATION ${CMAKE_INSTALL_DIR} + ) +endif () diff --git a/cmake/project-config.cmake.in b/cmake/project-config.cmake.in new file mode 100644 index 0000000..38f8e21 --- /dev/null +++ b/cmake/project-config.cmake.in @@ -0,0 +1,26 @@ +# Config file for @PROJECT_NAME_LOWER@ +# +# It defines the following variables: +# +# @PROJECT_NAME_UPPER@_INCLUDE_DIRS - include directory +# @PROJECT_NAME_UPPER@_LIBRARIES - all dynamic libraries +# @PROJECT_NAME_UPPER@_STATIC_LIBRARIES - all static libraries + +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) + +set(SLS_USE_HDF5 "@SLS_USE_HDF5@") + + +find_dependency(Threads) + +# Add optional dependencies here +if (SLS_USE_HDF5) + find_dependency(HDF5) +endif () + +set_and_check(@PROJECT_NAME_UPPER@_CMAKE_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_DIR@") + +include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") +check_required_components("@PROJECT_NAME@") diff --git a/conda-recipe/build.sh b/conda-recipe/build.sh new file mode 100644 index 0000000..32bba50 --- /dev/null +++ b/conda-recipe/build.sh @@ -0,0 +1,18 @@ +mkdir build +mkdir install +cd build +cmake .. \ + -DCMAKE_PREFIX_PATH=$CONDA_PREFIX \ + -DCMAKE_INSTALL_PREFIX=install \ + -DAARE_SYSTEM_LIBRARIES=ON \ + -DAARE_TESTS=ON \ + -DAARE_PYTHON_BINDINGS=ON \ + -DCMAKE_BUILD_TYPE=Release \ + + +NCORES=$(getconf _NPROCESSORS_ONLN) +echo "Building using: ${NCORES} cores" +cmake --build . -- -j${NCORES} +cmake --build . --target install + +CTEST_OUTPUT_ON_FAILURE=1 ctest -j 1 \ No newline at end of file diff --git a/conda-recipe/copy_lib.sh b/conda-recipe/copy_lib.sh new file mode 100644 index 0000000..d234cad --- /dev/null +++ b/conda-recipe/copy_lib.sh @@ -0,0 +1,19 @@ +mkdir -p $PREFIX/lib +mkdir -p $PREFIX/bin +mkdir -p $PREFIX/include/aare + + +#Shared and static libraries +cp build/install/lib/* $PREFIX/lib/ + +#Binaries +# cp build/install/bin/sls_detector_acquire $PREFIX/bin/. +# cp build/install/bin/sls_detector_get $PREFIX/bin/. +# cp build/install/bin/sls_detector_put $PREFIX/bin/. +# cp build/install/bin/sls_detector_help $PREFIX/bin/. +# cp build/install/bin/slsReceiver $PREFIX/bin/. +# cp build/install/bin/slsMultiReceiver $PREFIX/bin/. + + +cp build/install/include/aare/* $PREFIX/include/sls +cp -rv build/install/share $PREFIX \ No newline at end of file diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml new file mode 100644 index 0000000..30bd2e9 --- /dev/null +++ b/conda-recipe/meta.yaml @@ -0,0 +1,101 @@ + + +package: + name: aare_software + version: {{ environ.get('GIT_DESCRIBE_TAG', '') }} + +source: + - path: .. + +build: + number: 0 + binary_relocation: True + rpaths: + - lib/ + +requirements: + build: + - {{ compiler('c') }} + - {{compiler('cxx')}} + - cmake + # - qt 5.* + # - xorg-libx11 + # - xorg-libice + # - xorg-libxext + # - xorg-libsm + # - xorg-libxau + # - xorg-libxrender + # - xorg-libxfixes + # - {{ cdt('mesa-libgl-devel') }} # [linux] + # - {{ cdt('mesa-libegl-devel') }} # [linux] + # - {{ cdt('mesa-dri-drivers') }} # [linux] + # - {{ cdt('libselinux') }} # [linux] + # - {{ cdt('libxdamage') }} # [linux] + # - {{ cdt('libxxf86vm') }} # [linux] + # - expat + + host: + - libstdcxx-ng + - libgcc-ng + # - xorg-libx11 + # - xorg-libice + # - xorg-libxext + # - xorg-libsm + # - xorg-libxau + # - xorg-libxrender + # - xorg-libxfixes + # - expat + + run: + - libstdcxx-ng + - libgcc-ng + + +outputs: + - name: aarelib + script: copy_lib.sh + + requirements: + build: + - {{ compiler('c') }} + - {{compiler('cxx')}} + - libstdcxx-ng + - libgcc-ng + + + run: + - libstdcxx-ng + - libgcc-ng + + # - name: aare + + # script: build_pylib.sh + + # requirements: + # build: + # - python + # - {{ compiler('c') }} + # - {{compiler('cxx')}} + # - {{ pin_subpackage('slsdetlib', exact=True) }} + # - setuptools + # - pybind11=2.11 + + # host: + # - python + # - {{ pin_subpackage('slsdetlib', exact=True) }} + # - pybind11=2.11 + + + # run: + # - libstdcxx-ng + # - libgcc-ng + # - python + # - numpy + # - {{ pin_subpackage('slsdetlib', exact=True) }} + + + # test: + # imports: + # - slsdet + + \ No newline at end of file diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 8090817..e906a26 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -13,13 +13,14 @@ set(SPHINX_BUILD ${CMAKE_CURRENT_BINARY_DIR}) set(SPHINX_SOURCE_FILES src/index.rst src/NDArray.rst -# src/NDView.rst -# src/File.rst -# src/Frame.rst -# src/Dtype.rst -# src/ClusterFinder.rst -# src/Pedestal.rst -# src/VarClusterFinder.rst + src/NDView.rst + src/File.rst + src/Frame.rst + src/Dtype.rst + src/ClusterFinder.rst + src/Pedestal.rst + src/VarClusterFinder.rst + src/pyFile.rst ) foreach(filename ${SPHINX_SOURCE_FILES}) diff --git a/docs/src/ClusterFinder.rst b/docs/src/ClusterFinder.rst index 1411dbd..9c9e29e 100644 --- a/docs/src/ClusterFinder.rst +++ b/docs/src/ClusterFinder.rst @@ -2,4 +2,6 @@ ClusterFinder ============= -.. doxygenfile:: ClusterFinder.hpp \ No newline at end of file +.. doxygenclass:: aare::ClusterFinder + :members: + :undoc-members: \ No newline at end of file diff --git a/docs/src/Dtype.rst b/docs/src/Dtype.rst index 130c853..02841f0 100644 --- a/docs/src/Dtype.rst +++ b/docs/src/Dtype.rst @@ -2,4 +2,6 @@ Dtype ============= -.. doxygenfile:: Dtype.hpp \ No newline at end of file +.. doxygenclass:: aare::Dtype + :members: + :undoc-members: \ No newline at end of file diff --git a/docs/src/File.rst b/docs/src/File.rst index 06bab14..ddce281 100644 --- a/docs/src/File.rst +++ b/docs/src/File.rst @@ -2,4 +2,6 @@ File ============= -.. doxygenfile:: File.hpp \ No newline at end of file +.. doxygenclass:: aare::File + :members: + :undoc-members: \ No newline at end of file diff --git a/docs/src/Frame.rst b/docs/src/Frame.rst index fba075c..3b70916 100644 --- a/docs/src/Frame.rst +++ b/docs/src/Frame.rst @@ -2,4 +2,6 @@ Frame ============= -.. doxygenfile:: Frame.hpp \ No newline at end of file +.. doxygenclass:: aare::Frame + :members: + :undoc-members: \ No newline at end of file diff --git a/docs/src/NDArray.rst b/docs/src/NDArray.rst index d4c4760..8f42684 100644 --- a/docs/src/NDArray.rst +++ b/docs/src/NDArray.rst @@ -2,4 +2,6 @@ NDArray ============= -.. doxygenfile:: NDArray.hpp \ No newline at end of file +.. doxygenclass:: aare::NDArray + :members: + :undoc-members: \ No newline at end of file diff --git a/docs/src/NDView.rst b/docs/src/NDView.rst index bcd6c00..bb0eda9 100644 --- a/docs/src/NDView.rst +++ b/docs/src/NDView.rst @@ -2,4 +2,6 @@ NDView ============= -.. doxygenfile:: NDView.hpp \ No newline at end of file +.. doxygenclass:: aare::NDView + :members: + :undoc-members: \ No newline at end of file diff --git a/docs/src/Pedestal.rst b/docs/src/Pedestal.rst index ca991c3..0e35281 100644 --- a/docs/src/Pedestal.rst +++ b/docs/src/Pedestal.rst @@ -2,4 +2,6 @@ Pedestal ============= -.. doxygenfile:: Pedestal.hpp \ No newline at end of file +.. doxygenclass:: aare::Pedestal + :members: + :undoc-members: \ No newline at end of file diff --git a/docs/src/VarClusterFinder.rst b/docs/src/VarClusterFinder.rst index e3839bd..be2e5cb 100644 --- a/docs/src/VarClusterFinder.rst +++ b/docs/src/VarClusterFinder.rst @@ -2,4 +2,6 @@ VarClusterFinder ==================== -.. doxygenfile:: VarClusterFinder.hpp \ No newline at end of file +.. doxygenclass:: aare::VarClusterFinder + :members: + :undoc-members: \ No newline at end of file diff --git a/docs/src/index.rst b/docs/src/index.rst index e6ee9b4..8bed321 100644 --- a/docs/src/index.rst +++ b/docs/src/index.rst @@ -16,4 +16,10 @@ AARE Dtype ClusterFinder Pedestal - VarClusterFinder \ No newline at end of file + VarClusterFinder + +.. toctree:: + :caption: Python API + :maxdepth: 1 + + pyFile diff --git a/docs/src/pyFile.rst b/docs/src/pyFile.rst new file mode 100644 index 0000000..5c180d0 --- /dev/null +++ b/docs/src/pyFile.rst @@ -0,0 +1,11 @@ + +File +======== + +.. py:currentmodule:: aare + +.. autoclass:: File + :members: + :undoc-members: + :show-inheritance: + :inherited-members: \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 351be37..2428c4f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,7 +13,13 @@ set(SourceFiles add_library(aare_core STATIC ${SourceFiles}) -target_include_directories(aare_core PUBLIC ${CMAKE_SOURCE_DIR}/include) +target_include_directories(aare_core PUBLIC + "$" + "$" +) + + + target_link_libraries(aare_core PUBLIC fmt::fmt PRIVATE aare_compiler_flags nlohmann_json::nlohmann_json) if (AARE_PYTHON_BINDINGS)