Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Python interface #71

Draft
wants to merge 94 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
cc044de
Move table loading responsibility to individual fluxes
austinschneider Jun 4, 2024
fa04cb2
__repr__ and __str__ for InteractionSignature
austinschneider Jun 5, 2024
322d987
Whitespace
austinschneider Jun 5, 2024
8b5bbcd
load_module function
austinschneider Jun 5, 2024
ad97eef
Sketch loading logic for DarkNews
austinschneider Jun 5, 2024
226746d
Sketch DN decay logic and fix some obvious issues in the DN xs logic
austinschneider Jun 6, 2024
e88fee6
Return cross sections and decays
austinschneider Jun 6, 2024
c19596f
Introspect package version in __init__.py
austinschneider Jun 6, 2024
79f1b34
Start writing logic to generically load resources
austinschneider Jun 6, 2024
d5bbec4
Remove material model path method
austinschneider Aug 27, 2024
c9a09d1
Needs functools
austinschneider Aug 28, 2024
844e0cd
import struct. Properly return the module from sys.modules. Call exec…
austinschneider Aug 28, 2024
5940dae
docstrings, type hints, and variable names
austinschneider Aug 28, 2024
e33c191
Move cross sections. Fix string formatting
austinschneider Aug 29, 2024
1642d85
cross_Section -> processes
austinschneider Aug 29, 2024
34976e9
Refactor _get_model_path. Add support for top-level loaders
austinschneider Aug 29, 2024
16a7b61
Fix imports. loader -> logger
austinschneider Aug 29, 2024
b81b555
Fix imports
austinschneider Aug 29, 2024
c9dc192
Fix imports. loader -> logger. Instance checking instead of type chec…
austinschneider Aug 29, 2024
fa099a4
Avoid repeated use of np.append
austinschneider Aug 29, 2024
5fbf8e4
Override logging in our own copy of ModelContainer
austinschneider Aug 29, 2024
811780d
Check for DarkNews.ModelContainer.configure_logger in case it is remo…
austinschneider Aug 29, 2024
0b6f53d
Move detector files
austinschneider Aug 30, 2024
8a39ee4
Move detector files into subfolders
austinschneider Aug 30, 2024
6c7d346
Add load_* methods to siren.utilities
austinschneider Aug 30, 2024
0493255
Refactor model path search to just handle folders. Add special load_ …
austinschneider Aug 30, 2024
b59d9d6
Need to defined is_configured ahead of time
austinschneider Aug 30, 2024
8cb75a5
Pass nuclear targets to ModelContainer. Typo "s"
austinschneider Aug 30, 2024
a271cff
Inherit from a common Interaction class to enable a more concise cons…
austinschneider Aug 30, 2024
a2a3dbb
load_process returns maps from particle type to interactions
austinschneider Sep 1, 2024
5492b69
Loader for CSMS splines
austinschneider Sep 1, 2024
ea69003
Move resources
austinschneider Sep 2, 2024
7e5e5f1
un-capitalize folders
austinschneider Sep 2, 2024
55d8dc6
First pass at Injector wrapper
austinschneider Sep 12, 2024
e9443fb
Remvoe the holder
austinschneider Sep 12, 2024
e01cdca
particle type properties for the processes
austinschneider Sep 12, 2024
6e8a5b1
New access methods for process subclasses
austinschneider Sep 12, 2024
23c169a
Add more accessor method for processes
austinschneider Sep 12, 2024
c97cd10
Additional setters and getters
austinschneider Sep 12, 2024
b4e7f6f
Set primary type when setting interactions
austinschneider Sep 12, 2024
4885486
Additional setters and getters
austinschneider Sep 12, 2024
3b62df2
Produce a random seed by default. Getter for seed
austinschneider Sep 12, 2024
61dabf3
Rework Injector wrapper with @property
austinschneider Sep 12, 2024
324699c
Fix some obvious runtime issues
austinschneider Sep 12, 2024
9cecedb
Replace Injector with python wrapper
austinschneider Sep 12, 2024
aae1f78
Fiducial volume utilities
austinschneider Sep 12, 2024
d1902ef
Setter for number of events. Fix initialization checks
austinschneider Sep 12, 2024
6fd09b9
Remove requirement for target_types
austinschneider Sep 12, 2024
bf999b8
Add constructor with contents to pybindings
austinschneider Sep 12, 2024
990e474
Move examples
austinschneider Sep 14, 2024
1b34751
Utilities for string manipulation (mainly inserting tabs)
austinschneider Sep 14, 2024
bb2776d
A few pythonic changes to dataclasses pybindings. Moving ParticleType…
austinschneider Sep 14, 2024
d02b3b7
Add bindings for ParticleID
austinschneider Sep 14, 2024
41768b9
Clean up ParticleID __str__ and __repr__. Implement != operator
austinschneider Sep 14, 2024
ef147b6
Use lambda in favor of separate function pointer
austinschneider Sep 14, 2024
5d8339a
__str__ and __repr__ for InteractionRecord
austinschneider Sep 14, 2024
e7aeb09
to_str --> to_repr
austinschneider Sep 14, 2024
83e609b
__str__ and __repr__ for CrossSectionDistributionRecord and Secondary…
austinschneider Sep 14, 2024
19778c4
Specify namespace for args of forward declared output functions.
austinschneider Sep 14, 2024
764f63d
Add output functions as friends. More specific namespaces.
austinschneider Sep 14, 2024
4c298f1
__str__ and __repr__ for PrimaryDistributionRecord
austinschneider Sep 14, 2024
aee5431
__str__ and __repr__ for Particle
austinschneider Sep 14, 2024
a597bcb
Move detector files
austinschneider Sep 15, 2024
4cc6e93
Fix paths in visualization to match updated directory structure
austinschneider Sep 15, 2024
1a35e9d
Moving paper plots
austinschneider Sep 15, 2024
fb0bdab
primary_type should be an argument
austinschneider Sep 15, 2024
253954a
Add wrapper for Weighter
austinschneider Sep 15, 2024
ceae573
Re-write the DIS_ATLAS example with the new interface. Still need to …
austinschneider Sep 15, 2024
1622a4a
Utilities for exploring and getting docs
austinschneider Sep 15, 2024
0d41fb1
Rename and fix T2K_NEAR flux script to work with new directory struct…
austinschneider Sep 15, 2024
87a76bc
Enable access to resources through the module / tab-complete
austinschneider Sep 16, 2024
b2eda5e
Add file paths to detector docs
austinschneider Sep 16, 2024
254eb2d
Expose resource loader functions in the resources submodule
austinschneider Sep 16, 2024
bc0a31c
Don't require a version folder if there is a top level loader
austinschneider Sep 18, 2024
2477439
Update DIS_DUNE
austinschneider Sep 19, 2024
a5cb6df
Remove position dist from physical dists
austinschneider Sep 19, 2024
35c05c5
DIS_IceCube
austinschneider Sep 19, 2024
f48fdb3
Fix method name
austinschneider Sep 19, 2024
8bf11d7
Remove old function def. Load detector models correctly.
austinschneider Sep 19, 2024
5ebb901
Fix sampling
austinschneider Sep 19, 2024
1f0cd47
DipolePortal_CCM
austinschneider Sep 19, 2024
7a34462
Add ParticleIDs in InteractionRecord to pybindings
marichavest Oct 11, 2024
00164a1
Updates to cmake
austinschneider Oct 12, 2024
6e56833
FPIC for rk_static
austinschneider Oct 12, 2024
404562c
Update pyproject.toml
austinschneider Oct 12, 2024
3ca8e2d
Remove extension
austinschneider Oct 15, 2024
6adc857
Remove methods that are not needed in the python interface
austinschneider Oct 15, 2024
25c4c7e
Add functionality for injecting an unlimited number of events.
austinschneider Oct 15, 2024
f74be46
Fix semicolons in pybindings
austinschneider Oct 16, 2024
82e4905
Dev/serialization (#85)
austinschneider Oct 23, 2024
840da1f
Get example 1 working
nickkamp1 Oct 24, 2024
6210de4
starting to get second example working. adding functionality to save …
nickkamp1 Oct 24, 2024
b3ef5ca
Support for Interaction class
austinschneider Dec 17, 2024
83fe87b
Interaction pybindings
austinschneider Dec 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
url = https://github.com/austinschneider/delabella.git
[submodule "vendor/photospline"]
path = vendor/photospline
url = https://github.com/austinschneider/photospline.git
url = https://github.com/icecube/photospline.git
[submodule "vendor/NamedType"]
path = vendor/NamedType
url = https://github.com/joboccara/NamedType.git
127 changes: 103 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
cmake_minimum_required(VERSION 3.3.2 FATAL_ERROR)
cmake_policy(VERSION 3.3.2)
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
cmake_policy(VERSION 3.20)

if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_POLICY_DEFAULT_CMP0042 NEW)
cmake_policy(SET CMP0042 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0068 NEW)
cmake_policy(SET CMP0068 NEW)
set(MACOSX TRUE)
endif()

Expand All @@ -11,13 +15,14 @@ SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake ${CMAKE_CURRENT_LIST_DIR}/
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")

set(CIBUILDWHEEL $ENV{CIBUILDWHEEL})
set(CIBUILDWHEEL "$ENV{CIBUILDWHEEL}")
message(STATUS "CIBUILDWHEEL: ${CIBUILDWHEEL}")
if(${CIBUILDWHEEL})
set(CI_INSTALL_PREFIX $ENV{CI_INSTALL_PREFIX})
if(CIBUILDWHEEL STREQUAL "1")
set(CI_INSTALL_PREFIX "$ENV{CI_INSTALL_PREFIX}")
message(STATUS "CI_INSTALL_PREFIX: ${CI_INSTALL_PREFIX}")
endif()


# parse pyproject.toml for the version
include(pyproject)

Expand All @@ -31,21 +36,57 @@ SET(CMAKE_CXX_STANDARD 14)
SET(CMAKE_C_STANDARD 99)

# set the build type and appropriate flags
option(CMAKE_BUILD_TYPE "" "Release")
set(_FLAGS "-O2 -Wall -fPIC")
set(_FLAGS_DEBUG "-g -O0 -Wall -fPIC")
set(_FLAGS_RELEASE "-O2 -Wall -fPIC -s")
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(_FLAGS "${_FLAGS} -stdlib=libc++")
set(_FLAGS_DEBUG "${_FLAGS_DEBUG} -stdlib=libc++")
set(_FLAGS_RELEASE "${_FLAGS_RELEASE} -stdlib=libc++")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
set(CMAKE_CXX_FLAGS ${_FLAGS})
set(CMAKE_CXX_FLAGS_DEBUG ${_FLAGS_DEBUG})
set(CMAKE_CXX_FLAGS_RELEASE ${_FLAGS_RELEASE})

function(apply_siren_compile_options target)
# Check if the target is an INTERFACE target
get_target_property(target_type ${target} TYPE)
get_target_property(target_imported ${target} IMPORTED)

if("${target_type}" STREQUAL "INTERFACE_LIBRARY")
# Apply compile options to INTERFACE target
target_compile_options(${target} INTERFACE
-O2
-Wall
-fPIC
$<$<CONFIG:Debug>:-g>
$<$<CONFIG:Debug>:-O0>
$<$<CONFIG:Release>:-O2>
$<$<AND:$<COMPILE_LANG_AND_ID:CXX,GNU>,$<CONFIG:Release>>:-s>
$<$<COMPILE_LANG_AND_ID:CXX,Clang>:-stdlib=libc++>
)
elseif(target_imported)
# Apply compile options to non-INTERFACE target (PRIVATE or PUBLIC)
target_compile_options(${target} INTERFACE
-O2
-Wall
-fPIC
$<$<CONFIG:Debug>:-g>
$<$<CONFIG:Debug>:-O0>
$<$<CONFIG:Release>:-O2>
$<$<AND:$<COMPILE_LANG_AND_ID:CXX,GNU>,$<CONFIG:Release>>:-s>
$<$<COMPILE_LANG_AND_ID:CXX,Clang>:-stdlib=libc++>
)
else()
# Apply compile options to non-INTERFACE target (PRIVATE or PUBLIC)
target_compile_options(${target} PRIVATE
-O2
-Wall
-fPIC
$<$<CONFIG:Debug>:-g>
$<$<CONFIG:Debug>:-O0>
$<$<CONFIG:Release>:-O2>
$<$<AND:$<COMPILE_LANG_AND_ID:CXX,GNU>,$<CONFIG:Release>>:-s>
$<$<COMPILE_LANG_AND_ID:CXX,Clang>:-stdlib=libc++>
)
endif()
endfunction()


# override install locations when building python extensions
if(DEFINED SKBUILD)
if(DEFINED SKBUILD_PLATLIB_DIR)
cmake_path(RELATIVE_PATH SKBUILD_HEADERS_DIR BASE_DIRECTORY ${SKBUILD_PLATLIB_DIR} OUTPUT_VARIABLE CMAKE_INSTALL_INCLUDEDIR)
cmake_path(RELATIVE_PATH SKBUILD_PLATLIB_DIR BASE_DIRECTORY ${SKBUILD_PLATLIB_DIR} OUTPUT_VARIABLE CMAKE_INSTALL_LIBDIR)
message(STATUS "Setting include dir to: ${CMAKE_INSTALL_INCLUDEDIR}")
Expand All @@ -63,12 +104,46 @@ include(pybind11)

# load project dependencies
include(rk)
if(TARGET rk_static)
apply_siren_compile_options(rk_static)
endif()
if(TARGET rk_shared)
apply_siren_compile_options(rk_shared)
endif()
include(cereal)
if(TARGET cereal)
apply_siren_compile_options(cereal)
endif()
include(delabella)
if(TARGET delabella_static)
apply_siren_compile_options(delabella_static)
endif()
if(TARGET delabella_shared)
apply_siren_compile_options(delabella_shared)
endif()
include(CFITSIO)
if(TARGET CFITSIO)
apply_siren_compile_options(CFITSIO)
endif()
include(photospline)
if(TARGET photospline)
apply_siren_compile_options(photospline)
target_link_libraries(photospline PUBLIC CFITSIO)
endif()
include(googletest)
if(TARGET gtest)
apply_siren_compile_options(gtest)
endif()
if(TARGET gtest_main)
apply_siren_compile_options(gtest_main)
endif()
if(TARGET gmock)
apply_siren_compile_options(gmock)
endif()
include(NamedType)
if(TARGET NamedType)
apply_siren_compile_options(NamedType)
endif()

# load macros for googletest
include(testing)
Expand All @@ -87,8 +162,9 @@ add_subdirectory(projects/injection)
# define the target library
add_library(SIREN SHARED)
set_property(TARGET SIREN PROPERTY POSITION_INDEPENDENT_CODE ON)
apply_siren_compile_options(SIREN)

if(${MACOSX})
if(DEFINED MACOSX AND MACOSX)
if(CMAKE_VERSION VERSION_LESS 3.13)
target_link_libraries(SIREN PUBLIC "$<$<PLATFORM_ID:Darwin>:LINKER:-undefined,dynamic_lookup>")
else()
Expand Down Expand Up @@ -128,11 +204,11 @@ target_link_libraries(SIREN
endif()

# define the install path normally or for python package
if(DEFINED SKBUILD)
if(DEFINED SKBUILD_PLATLIB_DIR)
set_target_properties(SIREN PROPERTIES
BUILD_WITH_INSTALL_RPATH FALSE
LINK_FLAGS "-Wl,-rpath,\\\$ORIGIN")
if(${CIBUILDWHEEL})
if(DEFINED CIBUILDWHEEL AND CIBUILDWHEEL)
message(STATUS "Setting SIREN install lib dir to: ${CI_INSTALL_PREFIX}/lib")
message(STATUS "Setting SIREN install include dir to: ${CI_INSTALL_PREFIX}/include")
install(TARGETS SIREN
Expand Down Expand Up @@ -183,7 +259,7 @@ else()
endif()

# optionally package runtime dependencies
if((DEFINED SKBUILD) AND (PACKAGE_SHARED_DEPS))
if((DEFINED SKBUILD_PLATLIB_DIR) AND (PACKAGE_SHARED_DEPS))
install(CODE "set(SIREN_LIB_FILE \"${PROJECT_BINARY_DIR}/${CMAKE_SHARED_MODULE_PREFIX}SIREN${CMAKE_SHARED_MODULE_SUFFIX}\")")
install(CODE "set(PYTHON_DEP_LIB_DESTINATION \"${SKBUILD_PLATLIB_DIR}/siren.libs/\")")
install(CODE [[
Expand All @@ -209,7 +285,7 @@ if((DEFINED SKBUILD) AND (PACKAGE_SHARED_DEPS))
endif()

# install the python extensions
if(DEFINED SKBUILD)
if(DEFINED SKBUILD_PLATLIB_DIR)
install(TARGETS utilities
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/siren)
install(TARGETS math
Expand Down Expand Up @@ -241,15 +317,18 @@ write_basic_package_version_file(
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
export(EXPORT ${PROJECT_NAME}Config FILE ${PROJECT_NAME}Config.cmake)
export(EXPORT ${PROJECT_NAME}Config FILE "${PROJECT_NAME}Config.cmake"
NAMESPACE ${PROJECT_NAME}::)

# Make importable from install location
set(_config_dir share/${PROJECT_NAME}/cmake)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${_config_dir}
)
install(EXPORT ${PROJECT_NAME}Config
DESTINATION ${_config_dir}
FILE "${PROJECT_NAME}Config.cmake"
NAMESPACE ${PROJECT_NAME}::
DESTINATION "${_config_dir}"
)

MESSAGE("")
Expand Down
152 changes: 101 additions & 51 deletions cmake/Packages/CFITSIO.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,105 @@
# CFITSIO_LDFLAGS #
################################################################################

SET (CFITSIO_FIND_QUIETLY TRUE)
SET (CFITSIO_FIND_REQUIRED TRUE)

IF (NOT CFITSIO_FOUND)

# Search user environment for headers, then default paths; extract version
FIND_PATH (CFITSIO_INCLUDE_DIR fitsio.h
PATHS $ENV{CFITSIOROOT}/include
NO_DEFAULT_PATH)
FIND_PATH (CFITSIO_INCLUDE_DIR fitsio.h)
if(CFITSIO_INCLUDE_DIR)
GET_FILENAME_COMPONENT (CFITSIOROOT ${CFITSIO_INCLUDE_DIR} PATH)
else()
FIND_PATH (CFITSIO_INCLUDE_DIR cfitsio/fitsio.h
PATHS $ENV{CFITSIOROOT}/include
)
SET(CFITSIO_INCLUDE_DIR "${CFITSIO_INCLUDE_DIR}/cfitsio" CACHE PATH "Path to cfitsio headers" FORCE)
endif()

SET (CFITSIO_VERSION 0)
IF (CFITSIO_INCLUDE_DIR)
FILE (READ "${CFITSIO_INCLUDE_DIR}/fitsio.h" _cfitsio_VERSION)
STRING (REGEX REPLACE ".*define CFITSIO_VERSION ([0-9]+\\.[0-9]+).*" "\\1"
CFITSIO_VERSION "${_cfitsio_VERSION}")
ENDIF (CFITSIO_INCLUDE_DIR)

# Search user environment for libraries, then default paths
FIND_LIBRARY (CFITSIO_LIBRARIES NAMES cfitsio
PATHS $ENV{CFITSIOROOT}/lib
NO_DEFAULT_PATH)
FIND_LIBRARY (CFITSIO_LIBRARIES NAMES cfitsio)
GET_FILENAME_COMPONENT (CFITSIO_LIB_DIR ${CFITSIO_LIBRARIES} PATH)

# Set CFITSIO_FOUND and error out if cfitsio is not found
INCLUDE (FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS (CFITSIO
DEFAULT_MSG CFITSIO_LIBRARIES CFITSIO_INCLUDE_DIR)
ADD_DEFINITIONS ("-I${CFITSIO_INCLUDE_DIR}")

IF (CFITSIO_FOUND)
# Set flags and print a status message
MESSAGE (STATUS "CFITSIO version ${CFITSIO_VERSION} found:")

SET (CFITSIO_CPPFLAGS "-I${CFITSIO_INCLUDE_DIR}")
SET (CFITSIO_LDFLAGS "${CFITSIO_LIBRARIES}")

MESSAGE (STATUS " * includes: ${CFITSIO_INCLUDE_DIR}")
MESSAGE (STATUS " * libs: ${CFITSIO_LIBRARIES}")
ENDIF (CFITSIO_FOUND)

ENDIF (NOT CFITSIO_FOUND)
include(FindPackageHandleStandardArgs)

set(CFITSIO_FIND_QUIETLY TRUE)
set(CFITSIO_FIND_REQUIRED TRUE)

if (NOT CFITSIO_FOUND)
# Manually parse CPLUS_INCLUDE_PATH to add paths to search
if (DEFINED ENV{CPLUS_INCLUDE_PATH})
string(REPLACE ":" ";" CFITSIO_INCLUDE_SEARCH_PATH_LIST "$ENV{CPLUS_INCLUDE_PATH}")
else()
set(CFITSIO_INCLUDE_SEARCH_PATH_LIST "")
endif()

list(PREPEND CFITSIO_INCLUDE_SEARCH_PATH_LIST
$ENV{CFITSIOROOT}/include
)

# Search user environment for headers, then default paths; extract version
find_path(CFITSIO_INCLUDE_DIR fitsio.h
PATHS ${CFITSIO_INCLUDE_SEARCH_PATH_LIST}
NO_DEFAULT_PATH
)
if(NOT CFITSIO_INCLUDE_DIR)
unset(CFITSIO_INCLUDE_DIR)
find_path(CFITSIO_INCLUDE_DIR fitsio.h)
endif()

if(NOT CFITSIO_INCLUDE_DIR)
unset(CFITSIO_INCLUDE_DIR)
find_path(CFITSIO_INCLUDE_DIR cfitsio/fitsio.h
PATHS ${CFITSIO_INCLUDE_SEARCH_PATH_LIST}
NO_DEFAULT_PATH
)
if(CFITSIO_INCLUDE_DIR)
set(CFITSIO_INCLUDE_DIR "${CFITSIO_INCLUDE_DIR}/cfitsio" CACHE PATH "Path to cfitsio headers" FORCE)
endif()
endif()

if(NOT CFITSIO_INCLUDE_DIR)
unset(CFITSIO_INCLUDE_DIR)
find_path(CFITSIO_INCLUDE_DIR cfitsio/fitsio.h)
if(CFITSIO_INCLUDE_DIR)
set(CFITSIO_INCLUDE_DIR "${CFITSIO_INCLUDE_DIR}/cfitsio" CACHE PATH "Path to cfitsio headers" FORCE)
endif()
endif()

if (CFITSIO_INCLUDE_DIR AND EXISTS "${CFITSIO_INCLUDE_DIR}/fitsio.h")
get_filename_component(CFITSIOROOT ${CFITSIO_INCLUDE_DIR} PATH)
set(CFITSIO_VERSION 0)
file(STRINGS "${CFITSIO_INCLUDE_DIR}/fitsio.h" _cfitsio_VERSION REGEX "#define CFITSIO_VERSION[ \t]+([0-9]+\.[0-9]+)")
string(REGEX REPLACE ".*#define CFITSIO_VERSION[ \t]+([0-9]+\.[0-9]+).*" "\\1" CFITSIO_VERSION "${_cfitsio_VERSION}")
else()
set(CFITSIO_INCLUDE_DIR "CFITSIO_INCLUDE_DIR-NOTFOUND")
endif()

if (DEFINED ENV{LD_LIBRARY_PATH})
string(REPLACE ":" ";" CFITSIO_LIBRARY_SEARCH_PATH_LIST "$ENV{LD_LIBRARY_PATH}")
else()
set(CFITSIO_LIBRARY_SEARCH_PATH_LIST "")
endif()

# Search user environment for libraries, then default paths
find_library(CFITSIO_LIBRARIES cfitsio
PATHS ${CFITSIO_LIBRARY_SEARCH_PATH_LIST}
NO_DEFAULT_PATH
)

if(NOT CFITSIO_LIBRARIES)
find_library(CFITSIO_LIBRARIES NAMES cfitsio)
endif()

if (CFITSIO_LIBRARIES)
get_filename_component(CFITSIO_LIB_DIR ${CFITSIO_LIBRARIES} PATH)
else()
set(CFITSIO_LIBRARIES "CFITSIO_LIBRARIES-NOTFOUND")
endif()

# Set CFITSIO_FOUND and error out if cfitsio is not found
find_package_handle_standard_args(CFITSIO
REQUIRED_VARS CFITSIO_LIBRARIES CFITSIO_INCLUDE_DIR
VERSION_VAR CFITSIO_VERSION
)

if (CFITSIO_FOUND)
# Set flags and print a status message
message(STATUS "CFITSIO version ${CFITSIO_VERSION} found:")

set(CFITSIO_CPPFLAGS "-I${CFITSIO_INCLUDE_DIR}")
set(CFITSIO_LDFLAGS "${CFITSIO_LIBRARIES}")

message(STATUS " * includes: ${CFITSIO_INCLUDE_DIR}")
message(STATUS " * libs: ${CFITSIO_LIBRARIES}")

add_library(CFITSIO SHARED IMPORTED)
target_include_directories(CFITSIO INTERFACE ${CFITSIO_INCLUDE_DIR})
set_target_properties(CFITSIO PROPERTIES
IMPORTED_LOCATION ${CFITSIO_LIBRARIES})
else()
message(WARNING "CFITSIO not found. Please ensure CFITSIO is installed and the environment variables CFITSIOROOT, CPLUS_INCLUDE_PATH, LIBRARY_PATH, and LD_LIBRARY_PATH are set correctly.")
endif()
endif()

6 changes: 4 additions & 2 deletions projects/dataclasses/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ target_include_directories(SIREN_dataclasses PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SIREN/dataclasses/>
)

target_link_libraries(SIREN_dataclasses PUBLIC
target_link_libraries(SIREN_dataclasses
PUBLIC
photospline
SIREN_serialization
SIREN_utilities
SIREN_serialization
SIREN_math
)
apply_siren_compile_options(SIREN_dataclasses)

install(DIRECTORY "${PROJECT_SOURCE_DIR}/projects/dataclasses/public/"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
Expand Down
Loading
Loading