-
Notifications
You must be signed in to change notification settings - Fork 154
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
BLD: Add CMake build using scikit-build-core #242
Merged
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
d323dc0
BLD: Initial try at pyproject.toml
DWesl 8322c42
BLD,BUG: Fix pyproject.toml configuration and remove setup.py duplica…
DWesl 5c169eb
FIX: Require a setuptools version that understands the configuration.
DWesl ca51e70
BLD: Start working on a CMake build.
DWesl e88a5bd
BLD: Initial Scikit-build attempt.
DWesl d18ecf5
STY: Remove execute permissions from python modules.
DWesl 4686af4
BLD: First attempt at OpenMP.
DWesl ad35d87
CI: Update CI for CMake build, and add 3.12
DWesl 937e164
CI: Check the installed package.
DWesl ddcf9eb
CI: Fix Python 3.12 install and package install check
DWesl 05657f8
FIX: Try to get checks working.
DWesl 0df03d8
BLD: Let skbuild handle install dirs when available.
DWesl 0d38af9
FIX: Fix syntax in CMake variable reference.
DWesl a962d9f
CI,DBG: Only run ldd on so files.
DWesl 028ec66
FIX: Ensure grep knows the patterns are fixed strings.
DWesl 3b9abc9
CI,DBG: Remove debug section.
DWesl 8944514
FIX: Fix install directory for fortran extension module.
DWesl dd8ead2
BLD: Move requirements.txt to pyproject.toml
DWesl b3557c3
BLD: Do not expect f2py to produce ${modname}-f2pywrappers2.f90
DWesl 0038273
DOC: Note that this should work on Python 3.12
DWesl b940960
Merge branch 'develop' of NCAR/wrf-python into cmake-build
DWesl e1f530e
Merge branch 'cmake-build' of DWesl/wrf-python into cmake-build
DWesl 51cea52
Merge branch 'develop' into cmake-build
DWesl 9654ada
BLD: Pin NumPy<2
DWesl 7944265
BLD: Make CMake OpenMP linkage public.
DWesl 9f84088
BLD: Pin build-time NumPy >=2, unpin run-time numpy
DWesl e41f75e
BUG: Fix spelling of Python_EXECUTABLE in CMakeLists.txt
DWesl 379691d
BUG: Include the f90 wrapper file in the compilation.
DWesl b5fdd5f
FIX: Fix syntax in CMakeLists.txt
DWesl 4bde3cf
BLD: Pin numpy<1.26.3
DWesl 0eed892
ENH: Add a function to module wrf_constants so f2py includes it
DWesl 607cf30
ENH: Add a function to module omp_constants so f2py includes it
DWesl 1c20f4a
FIX: Fix where in module functions go
DWesl ef93ca6
BUG: Fix where in module functions go
DWesl f914a85
ENH: Make have_wrf_constants a subroutine
DWesl 46cf6b3
BLD: Remove pin on NumPy version
DWesl 9b712c8
CI,DBG: Re-add debug section to CI
DWesl faeda9d
CI,BUG: Try to fix debug section.
DWesl bb4ff8e
CI,BUG: Try to get ls ${installed_files} working.
DWesl 80265d6
CI,BUG: Don't run ldd until after python import
DWesl c9573de
BLD,BUG: Try a different suffix for extension modules
DWesl f9f690f
CI,ENH: conda package build renamed to python-build
DWesl e502213
Merge branch 'develop' of NCAR/wrf-python into cmake-build
DWesl 97643e7
BLD: Update python_version to >=3.9 in pyproject.toml
DWesl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
### setup project ### | ||
# https://numpy.org/doc/stable/f2py/buildtools/skbuild.html | ||
cmake_minimum_required(VERSION 3.18) | ||
|
||
project(${SKBUILD_PROJECT_NAME} | ||
VERSION ${SKBUILD_PROJECT_VERSION} | ||
DESCRIPTION "Utilities for reading WRF output" | ||
LANGUAGES C Fortran | ||
) | ||
|
||
# Safety net | ||
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) | ||
message( | ||
FATAL_ERROR | ||
"In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.\n" | ||
) | ||
endif() | ||
|
||
find_package(Python COMPONENTS Interpreter Development.Module NumPy REQUIRED) | ||
|
||
# Ensure scikit-build modules | ||
if (NOT SKBUILD) | ||
# Kanged --> https://github.com/Kitware/torch_liberator/blob/master/CMakeLists.txt | ||
# 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 | ||
) | ||
list(APPEND CMAKE_MODULE_PATH "${SKBLD_DIR}/resources/cmake") | ||
message(STATUS "Looking in ${SKBLD_DIR}/resources/cmake for CMake modules") | ||
endif() | ||
|
||
# Grab the variables from a local Python installation | ||
# NumPy headers | ||
# F2PY headers | ||
execute_process( | ||
COMMAND "${Python_EXECUTABLE}" | ||
-c "import numpy.f2py; print(numpy.f2py.get_include())" | ||
OUTPUT_VARIABLE F2PY_INCLUDE_DIR | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
|
||
find_package(OpenMP COMPONENTS Fortran) | ||
set_source_files_properties(fortran/ompgen.F90 PROPERTIES Fortran_PREPROCESS ON) | ||
# TODO: Figure out the conditionals for running the C Preprocessor on Fortran files | ||
# I think the main thing to be changed is -E -cpp | ||
# Intel is -fpp -save-temps or /fpp on Windows | ||
# or call fpp instead of the fortran compiler to get it to stop after preprocessing | ||
if (${OpenMP_Fortran_FOUND}) | ||
# This would probably be cleaner if I shoved it in the subdirectory | ||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/fortran") | ||
add_executable(sizes "${CMAKE_SOURCE_DIR}/fortran/build_help/omp_sizes.f90") | ||
target_link_libraries(sizes PUBLIC OpenMP::OpenMP_Fortran) | ||
add_custom_command( | ||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/fortran/ompgen.F90" | ||
DEPENDS "${CMAKE_SOURCE_DIR}/fortran/ompgen.F90.template" | ||
${CMAKE_SOURCE_DIR}/fortran/build_help/sub_sizes.py | ||
sizes | ||
COMMAND | ||
${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/fortran/build_help/sub_sizes.py | ||
${CMAKE_SOURCE_DIR}/fortran/ompgen.F90.template | ||
${CMAKE_CURRENT_BINARY_DIR}/fortran/ompgen.F90 | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" | ||
) | ||
add_custom_command( | ||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/fortran/omp.f90" | ||
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/fortran/ompgen.F90" | ||
COMMAND ${CMAKE_Fortran_COMPILER} -E "${CMAKE_CURRENT_BINARY_DIR}/fortran/ompgen.F90" | ||
-o "${CMAKE_CURRENT_BINARY_DIR}/fortran/omp.f90" ${OpenMP_Fortran_FLAGS} -cpp | ||
) | ||
else() | ||
add_custom_command( | ||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/fortran/omp.f90" | ||
DEPENDS "${CMAKE_SOURCE_DIR}/fortran/ompgen.F90" | ||
COMMAND ${CMAKE_Fortran_COMPILER} -E fortran/ompgen.F90 -o fortran/omp.f90 -cpp | ||
) | ||
endif() | ||
|
||
# Prepping the module | ||
set(f2py_module_name "_wrffortran") | ||
set(fortran_src_files | ||
"${CMAKE_SOURCE_DIR}/fortran/wrf_constants.f90" | ||
"${CMAKE_SOURCE_DIR}/fortran/wrf_testfunc.f90" | ||
"${CMAKE_SOURCE_DIR}/fortran/wrf_user.f90" | ||
"${CMAKE_SOURCE_DIR}/fortran/rip_cape.f90" | ||
"${CMAKE_SOURCE_DIR}/fortran/wrf_cloud_fracf.f90" | ||
"${CMAKE_SOURCE_DIR}/fortran/wrf_fctt.f90" | ||
"${CMAKE_SOURCE_DIR}/fortran/wrf_user_dbz.f90" | ||
"${CMAKE_SOURCE_DIR}/fortran/wrf_relhl.f90" | ||
"${CMAKE_SOURCE_DIR}/fortran/calc_uh.f90" | ||
"${CMAKE_SOURCE_DIR}/fortran/wrf_user_latlon_routines.f90" | ||
"${CMAKE_SOURCE_DIR}/fortran/wrf_pvo.f90" | ||
"${CMAKE_SOURCE_DIR}/fortran/eqthecalc.f90" | ||
"${CMAKE_SOURCE_DIR}/fortran/wrf_rip_phys_routines.f90" | ||
"${CMAKE_SOURCE_DIR}/fortran/wrf_pw.f90" | ||
"${CMAKE_SOURCE_DIR}/fortran/wrf_vinterp.f90" | ||
"${CMAKE_SOURCE_DIR}/fortran/wrf_wind.f90" | ||
"${CMAKE_CURRENT_BINARY_DIR}/fortran/omp.f90") | ||
set(python_src_files | ||
"${CMAKE_SOURCE_DIR}/src/wrf/__init__.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/api.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/cache.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/computation.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/config.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/constants.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/contrib.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/coordpair.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/decorators.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/destag.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/extension.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_cape.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_cloudfrac.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_ctt.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_dbz.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_dewpoint.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_geoht.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_helicity.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_latlon.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_omega.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_precip.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_pressure.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_pw.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_rh.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_slp.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_temp.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_terrain.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_times.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_uvmet.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_vorticity.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/g_wind.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/geobnds.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/interp.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/interputils.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/latlonutils.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/metadecorators.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/projection.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/projutils.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/py3compat.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/routines.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/specialdec.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/units.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/util.py" | ||
"${CMAKE_SOURCE_DIR}/src/wrf/version.py" | ||
) | ||
set(f2py_module_c "${f2py_module_name}module.c") | ||
|
||
# Target for enforcing dependencies | ||
add_custom_target(genpyf | ||
DEPENDS "${fortran_src_files}" | ||
) | ||
add_custom_command( | ||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${f2py_module_c}" | ||
"${CMAKE_CURRENT_BINARY_DIR}/${f2py_module_name}-f2pywrappers.f" | ||
"${CMAKE_CURRENT_BINARY_DIR}/${f2py_module_name}-f2pywrappers2.f90" | ||
COMMAND ${Python_EXECUTABLE} -m "numpy.f2py" | ||
-m "${f2py_module_name}" | ||
--lower # Important | ||
${fortran_src_files} | ||
DEPENDS "${fortran_src_files}" # Fortran source | ||
) | ||
|
||
Python_add_library(${f2py_module_name} MODULE | ||
"${CMAKE_CURRENT_BINARY_DIR}/${f2py_module_c}" | ||
"${CMAKE_CURRENT_BINARY_DIR}/${f2py_module_name}-f2pywrappers.f" | ||
"${CMAKE_CURRENT_BINARY_DIR}/${f2py_module_name}-f2pywrappers2.f90" | ||
"${F2PY_INCLUDE_DIR}/fortranobject.c" | ||
"${fortran_src_files}") | ||
|
||
target_include_directories(${f2py_module_name} PUBLIC | ||
${F2PY_INCLUDE_DIR} | ||
${Python_NumPy_INCLUDE_DIRS} | ||
${Python_INCLUDE_DIRS}) | ||
set_target_properties(${f2py_module_name} PROPERTIES SUFFIX ".${Python_SOABI}${CMAKE_SHARED_MODULE_SUFFIX}") | ||
set_target_properties(${f2py_module_name} PROPERTIES PREFIX "") | ||
|
||
# https://scikit-build-core.readthedocs.io/en/latest/getting_started.html | ||
target_link_libraries(${f2py_module_name} PRIVATE Python::NumPy) | ||
if (${OpenMP_Fortran_FOUND}) | ||
target_link_libraries(${f2py_module_name} PUBLIC OpenMP::OpenMP_Fortran) | ||
endif() | ||
|
||
# Linker fixes | ||
if (UNIX) | ||
if (APPLE) | ||
set_target_properties(${f2py_module_name} PROPERTIES | ||
LINK_FLAGS '-Wl,-dylib,-undefined,dynamic_lookup') | ||
else() | ||
set_target_properties(${f2py_module_name} PROPERTIES | ||
LINK_FLAGS '-Wl,--allow-shlib-undefined') | ||
endif() | ||
endif() | ||
|
||
add_dependencies(${f2py_module_name} genpyf) | ||
|
||
if (NOT SKBUILD) | ||
string(REGEX REPLACE "^/(usr/(local/)?)?" "" Python_SITEARCH_INSTALL ${Python_SITEARCH}) | ||
string(REGEX REPLACE "^/(usr/(local/)?)?" "" Python_SITELIB_INSTALL ${Python_SITELIB}) | ||
# string(SUBSTRING ${Python_SITEARCH} 1 -1 Python_SITEARCH_INSTALL) | ||
# string(SUBSTRING ${Python_SITELIB} 1 -1 Python_SITELIB_INSTALL) | ||
|
||
install(TARGETS ${f2py_module_name} DESTINATION "${Python_SITEARCH_INSTALL}/wrf/") | ||
install(FILES ${python_src_files} DESTINATION "${Python_SITELIB_INSTALL}/wrf/") | ||
install(FILES src/wrf/data/psadilookup.dat DESTINATION "${Python_SITELIB_INSTALL}/wrf") | ||
else() | ||
# https://scikit-build-core.readthedocs.io/en/latest/cmakelists.html#install-directories | ||
install(TARGETS ${f2py_module_name} DESTINATION "${SKBUILD_PLATLIB_DIR}/wrf/") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be good to look into this for Windows at least, but I think that can happen after getting this merged. Maybe along with some testing for Windows.