Latest changes (#100)

This commit is contained in:
Erik Fröjdh 2024-11-18 15:42:37 +01:00 committed by GitHub
commit 99e829fd06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 152 additions and 31 deletions

View File

@ -21,7 +21,11 @@ include(FetchContent)
#Set default build type if none was specified #Set default build type if none was specified
include(cmake/helpers.cmake) include(cmake/helpers.cmake)
default_build_type("Release") default_build_type("Release")
set_std_fs_lib()
message(STATUS "Extra linking to fs lib:${STD_FS_LIB}")
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
@ -113,8 +117,17 @@ if (AARE_FETCH_FMT)
GIT_PROGRESS TRUE GIT_PROGRESS TRUE
USES_TERMINAL_DOWNLOAD TRUE USES_TERMINAL_DOWNLOAD TRUE
) )
set(FMT_INSTALL ON CACHE BOOL "")
# set(FMT_CMAKE_DIR "")
FetchContent_MakeAvailable(fmt) FetchContent_MakeAvailable(fmt)
set_property(TARGET fmt PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET fmt PROPERTY POSITION_INDEPENDENT_CODE ON)
install(TARGETS fmt
EXPORT ${project}-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
else() else()
find_package(fmt 6 REQUIRED) find_package(fmt 6 REQUIRED)
endif() endif()
@ -125,7 +138,16 @@ if (AARE_FETCH_JSON)
json json
URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
) )
set(JSON_Install ON CACHE BOOL "")
FetchContent_MakeAvailable(json) FetchContent_MakeAvailable(json)
set(NLOHMANN_JSON_TARGET_NAME nlohmann_json)
install(
TARGETS nlohmann_json
EXPORT "${TARGETS_EXPORT_NAME}"
)
message(STATUS "target: ${NLOHMANN_JSON_TARGET_NAME}")
else() else()
find_package(nlohmann_json 3.11.3 REQUIRED) find_package(nlohmann_json 3.11.3 REQUIRED)
endif() endif()
@ -292,7 +314,15 @@ target_include_directories(aare_core PUBLIC
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
) )
target_link_libraries(aare_core PUBLIC fmt::fmt PRIVATE aare_compiler_flags nlohmann_json::nlohmann_json) target_link_libraries(
aare_core
PUBLIC
fmt::fmt
nlohmann_json::nlohmann_json
${STD_FS_LIB} # from helpers.cmake
PRIVATE
aare_compiler_flags
)
set_target_properties(aare_core PROPERTIES set_target_properties(aare_core PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
@ -389,8 +419,8 @@ add_custom_target(
VERBATIM VERBATIM
) )
# if(AARE_MASTER_PROJECT) if(AARE_MASTER_PROJECT)
# set(CMAKE_INSTALL_DIR "share/cmake/${PROJECT_NAME}") set(CMAKE_INSTALL_DIR "share/cmake/${PROJECT_NAME}")
# set(PROJECT_LIBRARIES slsSupportShared slsDetectorShared slsReceiverShared) set(PROJECT_LIBRARIES aare-core aare-compiler-flags )
# include(cmake/package_config.cmake) include(cmake/package_config.cmake)
# endif() endif()

View File

@ -4,3 +4,43 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE ${val} CACHE STRING "Build type (default ${val})" FORCE) set(CMAKE_BUILD_TYPE ${val} CACHE STRING "Build type (default ${val})" FORCE)
endif() endif()
endfunction() endfunction()
function(set_std_fs_lib)
# from pybind11
# Check if we need to add -lstdc++fs or -lc++fs or nothing
if(DEFINED CMAKE_CXX_STANDARD AND CMAKE_CXX_STANDARD LESS 17)
set(STD_FS_NO_LIB_NEEDED TRUE)
elseif(MSVC)
set(STD_FS_NO_LIB_NEEDED TRUE)
else()
file(
WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
"#include <filesystem>\nint main(int argc, char ** argv) {\n std::filesystem::path p(argv[0]);\n return p.string().length();\n}"
)
try_compile(
STD_FS_NO_LIB_NEEDED ${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
COMPILE_DEFINITIONS -std=c++17)
try_compile(
STD_FS_NEEDS_STDCXXFS ${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
COMPILE_DEFINITIONS -std=c++17
LINK_LIBRARIES stdc++fs)
try_compile(
STD_FS_NEEDS_CXXFS ${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
COMPILE_DEFINITIONS -std=c++17
LINK_LIBRARIES c++fs)
endif()
if(${STD_FS_NEEDS_STDCXXFS})
set(STD_FS_LIB stdc++fs PARENT_SCOPE)
elseif(${STD_FS_NEEDS_CXXFS})
set(STD_FS_LIB c++fs PARENT_SCOPE)
elseif(${STD_FS_NO_LIB_NEEDED})
set(STD_FS_LIB "" PARENT_SCOPE)
else()
message(WARNING "Unknown C++17 compiler - not passing -lstdc++fs")
set(STD_FS_LIB "")
endif()
endfunction()

View File

@ -12,8 +12,10 @@ include(CMakeFindDependencyMacro)
set(SLS_USE_HDF5 "@SLS_USE_HDF5@") set(SLS_USE_HDF5 "@SLS_USE_HDF5@")
# List dependencies
find_dependency(Threads) find_dependency(Threads)
find_dependency(fmt)
find_dependency(nlohmann_json)
# Add optional dependencies here # Add optional dependencies here
if (SLS_USE_HDF5) if (SLS_USE_HDF5)

19
docs/src/Consume.rst Normal file
View File

@ -0,0 +1,19 @@
Use from C++
========================
There are a few different way to use aare in your C++ project. Which one you choose
depends on how you intend to work with the library and how you manage your dependencies.
Install and use cmake with find_package(aare)
-------------------------------------------------
https://github.com/slsdetectorgroup/aare-examples
.. include:: _install.rst
Use as a submodule
-------------------
Coming soon...

View File

@ -1,8 +1,17 @@
****************
Installation Installation
=============== ****************
.. attention ::
- https://cliutils.gitlab.io/modern-cmake/README.html
conda/mamaba conda/mamaba
~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~
This is the recommended way to install aare. Using a package manager makes it easy to
switch between versions and is (one of) the most convenient way to install up to date
dependencies on older distributions.
.. note :: .. note ::
@ -16,8 +25,11 @@ conda/mamaba
conda install aare=2024.11.11.dev0 -c slsdetectorgroup conda install aare=2024.11.11.dev0 -c slsdetectorgroup
cmake (development install) cmake build (development install)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you are working on aare or want to test our a version that doesn't yet have
a conda package. Build using cmake and then run from the build folder.
.. code-block:: bash .. code-block:: bash
@ -32,30 +44,23 @@ cmake (development install)
make -j4 make -j4
# add the build folder to your PYTHONPATH # add the build folder to your PYTHONPATH and then you should be able to
# import aare in python
cmake install and use in your C++ project cmake build + install and use in your C++ project
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: bash .. warning ::
#build and install aare When building aare with default settings we also include fmt and nlohmann_json.
git clone git@github.com:slsdetectorgroup/aare.git --branch=v1 #or using http... Installation to a custom location is highly recommended.
mkdir build
cd build
#configure using cmake
cmake ../aare -DCMAKE_INSTALL_PREFIX=/where/to/put/aare
#build (replace 4 with the number of threads you want to use)
make -j4
#install
make install
#Now configure your project .. note ::
cmake .. -DCMAKE_PREFIX_PATH=SOME_PATH
It is also possible to install aare with conda and then use in your C++ project.
.. include:: _install.rst
cmake options cmake options

23
docs/src/_install.rst Normal file
View File

@ -0,0 +1,23 @@
.. code-block:: bash
#build and install aare
git clone git@github.com:slsdetectorgroup/aare.git --branch=developer #or using http...
mkdir build
cd build
#configure using cmake
cmake ../aare -DCMAKE_INSTALL_PREFIX=/where/to/put/aare
#build (replace 4 with the number of threads you want to use)
make -j4
#install
make install
#Go to your project
cd /your/project/source
#Now configure your project
mkdir build
cd build
cmake .. -DCMAKE_PREFIX_PATH=SOME_PATH

View File

@ -8,10 +8,12 @@ AARE
.. toctree:: .. toctree::
:caption: Installation :caption: Installation
:maxdepth: 1 :maxdepth: 3
Installation Installation
Requirements Requirements
Consume