diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fdfb20..aebaf07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,23 +1,63 @@ cmake_minimum_required(VERSION 3.18) project(python-casacore) -find_package(PkgConfig REQUIRED) -pkg_check_modules(Casacore REQUIRED casacore) -# find_package(Casacore REQUIRED) - find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) -find_package(PythonExtensions REQUIRED) if(SKBUILD) message(STATUS "The project is built using scikit-build") +else() + # If skbuild is not the driver; include its utilities in CMAKE_MODULE_PATH + execute_process( + COMMAND "${Python_EXECUTABLE}" + -c "import os, skbuild; print(os.path.dirname(skbuild.__file__))" + OUTPUT_VARIABLE SKBLD_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE STATUS + ) + if(NOT STATUS EQUAL 0) + message(FATAL_ERROR + "You need scikit-build to build python-casacore.\n" + "Use `pip install scikit-build` to install it.\n" + ) + endif() + list(APPEND CMAKE_MODULE_PATH "${SKBLD_DIR}/resources/cmake") + message(STATUS "Looking in ${SKBLD_DIR}/resources/cmake for CMake modules") endif() -message(STATUS "Python_INCLUDE_DIRS=${Python_INCLUDE_DIRS}") +# Scikit-build extensions +find_package(PythonExtensions REQUIRED) + +# Find Casacore and its dependencies +find_package(PkgConfig REQUIRED) +pkg_check_modules(Casacore REQUIRED casacore) +find_package(Boost REQUIRED COMPONENTS python) + +# If environment variable CASACORE_DATA is set, it is assumed that it points to the +# directory containing the casacore data files. Create a symlink to that directory. +if (DEFINED ENV{CASACORE_DATA}) + execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink + $ENV{CASACORE_DATA} ${CMAKE_SOURCE_DIR}/casacore/data + RESULT_VARIABLE STATUS + ERROR_VARIABLE STDERR + ) + if(NOT STATUS EQUAL 0) + message(FATAL_ERROR "Failed to create symlink.\n${STDERR}") + else() + # message(STATUS "Data files in $ENV{CASACORE_DATA} will be included in the python-casacore package") + message(STATUS "Created symlink: ${CMAKE_SOURCE_DIR}/casacore/data -> $ENV{CASACORE_DATA}") + endif() +else() + message(WARNING + "Environment variable CASACORE_DATA is not defined. " + "Casacore data files will not be included in the python-casacore package." + ) +endif() add_library(_fitting MODULE src/fit.cc src/fitting.cc) -target_include_directories(_fitting PRIVATE +target_include_directories(_fitting PRIVATE + ${Boost_INCLUDE_DIRS} ${Casacore_INCLUDE_DIRS} ${Python_INCLUDE_DIRS} ) @@ -31,6 +71,7 @@ add_library(_functionals MODULE src/functionals.cc ) target_include_directories(_functionals PRIVATE + ${Boost_INCLUDE_DIRS} ${Casacore_INCLUDE_DIRS} ${Python_INCLUDE_DIRS} ) @@ -44,6 +85,7 @@ add_library(_images MODULE src/pyimages.cc ) target_include_directories(_images PRIVATE + ${Boost_INCLUDE_DIRS} ${Casacore_INCLUDE_DIRS} ${Python_INCLUDE_DIRS} ) @@ -57,6 +99,7 @@ add_library(_measures MODULE src/pymeasures.cc ) target_include_directories(_measures PRIVATE + ${Boost_INCLUDE_DIRS} ${Casacore_INCLUDE_DIRS} ${Python_INCLUDE_DIRS} ) @@ -72,6 +115,7 @@ add_library(_quanta MODULE src/quantvec.cc ) target_include_directories(_quanta PRIVATE + ${Boost_INCLUDE_DIRS} ${Casacore_INCLUDE_DIRS} ${Python_INCLUDE_DIRS} ) @@ -89,6 +133,7 @@ add_library(_tables MODULE src/pyms.cc ) target_include_directories(_tables PRIVATE + ${Boost_INCLUDE_DIRS} ${Casacore_INCLUDE_DIRS} ${Python_INCLUDE_DIRS} ) @@ -96,3 +141,17 @@ target_link_directories(_tables PRIVATE ${Casacore_LIBRARY_DIRS}) target_link_libraries(_tables ${Casacore_LIBRARIES}) python_extension_module(_tables) install(TARGETS _tables LIBRARY DESTINATION casacore/tables) + + +add_library(_tConvert MODULE + tests/tConvert.cc +) +target_include_directories(_tConvert PRIVATE + ${Boost_INCLUDE_DIRS} + ${Casacore_INCLUDE_DIRS} + ${Python_INCLUDE_DIRS} +) +target_link_directories(_tConvert PRIVATE ${Casacore_LIBRARY_DIRS}) +target_link_libraries(_tConvert ${Casacore_LIBRARIES}) +python_extension_module(_tConvert) +install(TARGETS _tConvert LIBRARY DESTINATION casacore) diff --git a/pyproject.toml b/pyproject.toml index 054c6bd..5092184 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,6 +2,7 @@ requires = [ "build", "cmake>=3.18", + "ninja", "oldest-supported-numpy", "scikit-build>=0.13", "setuptools", @@ -12,8 +13,9 @@ requires = [ build = "cp3{7,8,9,10,11,12}-*_x86_64" build-verbosity = 1 environment = """ \ - CFLAGS="-I/usr/include/cfitsio" \ - LD_LIBRARY_PATH=/opt/boost/lib \ + BOOST_ROOT="/opt/boost" \ + CXXFLAGS="-I/usr/include/cfitsio" \ + LD_LIBRARY_PATH="${BOOST_ROOT}/lib" \ """ test-command = "cd {package}/tests && pytest" test-requires = "pytest" diff --git a/setup.py b/setup.py index 7a9ff81..520be58 100755 --- a/setup.py +++ b/setup.py @@ -310,7 +310,8 @@ def create_symlink(src_dir, dest_dir): # not a symlink, then no attempt is made to create a symlink; the contents of # `casacore/data` will be used instead. package_data={ - "casacore.data": [create_symlink(os.getenv("CASACORE_DATA"), "casacore/data")] + # "casacore.data": [create_symlink(os.getenv("CASACORE_DATA"), "casacore/data")] + "casacore.data": ["casacore/data"] }, # ext_modules=get_extensions(), # cmdclass={'build_ext': my_build_ext},