Skip to content

Commit

Permalink
WIP: Fix cibuildwheel build
Browse files Browse the repository at this point in the history
The build with `cibuildwheel` has been fixed.
  • Loading branch information
gmloose committed Mar 18, 2024
1 parent 4ed64d7 commit e5cc983
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 10 deletions.
73 changes: 66 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}
)
Expand All @@ -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}
)
Expand All @@ -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}
)
Expand All @@ -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}
)
Expand All @@ -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}
)
Expand All @@ -89,10 +133,25 @@ add_library(_tables MODULE
src/pyms.cc
)
target_include_directories(_tables PRIVATE
${Boost_INCLUDE_DIRS}
${Casacore_INCLUDE_DIRS}
${Python_INCLUDE_DIRS}
)
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)
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
requires = [
"build",
"cmake>=3.18",
"ninja",
"oldest-supported-numpy",
"scikit-build>=0.13",
"setuptools",
Expand All @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit e5cc983

Please sign in to comment.