diff --git a/CMakeLists.txt b/CMakeLists.txt index d375d3d13..8444f239a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,12 +11,12 @@ ################################################## # Define the project and the depencies that it has ################################################## - CMAKE_MINIMUM_REQUIRED(VERSION 3.20.1) # Get version stored in text file FILE(READ "version.txt" VERSION) PROJECT(swiftest VERSION ${VERSION} LANGUAGES C Fortran) +MESSAGE(STATUS "CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}\nPROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}\n") # The following section is modified from Numpy f2py documentation IF(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) @@ -24,8 +24,8 @@ IF(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) ENDIF() # Ensure scikit-build modules +FIND_PACKAGE(Python3 COMPONENTS Interpreter Development REQUIRED) IF (NOT SKBUILD) - FIND_PACKAGE(Python3 COMPONENTS Interpreter Development REQUIRED) EXECUTE_PROCESS( COMMAND "${Python3_EXECUTABLE}" -c "import os, skbuild; print(os.path.dirname(skbuild.__file__))" @@ -38,16 +38,20 @@ ENDIF() SET(PYTHON_EXTENSION_MODULE_SUFFIX ".${Python3_SOABI}" CACHE STRING "Suffix for python extension modules") -INCLUDE(CTest) +# Detect when building against a conda environment set the _using_conda variable +# for use both in this file and in the parent +GET_FILENAME_COMPONENT(_python_bin_dir ${Python3_EXECUTABLE} DIRECTORY) +IF(EXISTS "${_python_bin_dir}/../conda-meta") + MESSAGE("-- Detected conda environment, setting INSTALL_RPATH_USE_LINK_PATH") + SET(_using_conda On) +ELSE() + SET(_using_conda Off) +ENDIF() # Add our local modules to the module path LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/") -############################################################ -# Define the actual files and folders that make up the build -############################################################ - -# Define some directories +# Define some directories that are important to the build SET(SRC ${CMAKE_SOURCE_DIR}/src) SET(LIB ${CMAKE_SOURCE_DIR}/lib) SET(BIN ${CMAKE_SOURCE_DIR}/bin) diff --git a/distclean.cmake b/distclean.cmake index f85a44027..2ff89059d 100644 --- a/distclean.cmake +++ b/distclean.cmake @@ -19,6 +19,8 @@ ELSE() SET(TOPDIR "${CMAKE_SOURCE_DIR}") ENDIF() +SET(SKBUILD_DIR "_skbuild") + MACRO(GET_PARENT_DIRECTORIES search_string return_list grandparents) FILE(GLOB_RECURSE new_list ${search_string}) SET(dir_list "") @@ -61,6 +63,7 @@ SET(DEL ${TOPDIRECTORIES} ${CMAKEFILES} ${CMAKETESTING} ${CMAKETESTFILES} + ${SKBUILD_DIR} ) # If we are not in the build dir, delete that as well diff --git a/pyproject.toml b/pyproject.toml index aec44a1e3..f0b5f8b60 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,6 +3,7 @@ requires = [ "setuptools>=42", "scikit-build>=0.13", "cmake>=3.20.1", + "cython>=3.0.0", "ninja", ] build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/setup.py b/setup.py index a587f2421..a2175d937 100644 --- a/setup.py +++ b/setup.py @@ -11,27 +11,10 @@ """ from skbuild import setup -from setuptools import find_packages #, Extension -#from Cython.Build import cythonize -import os -# Build the pybindings extension that allows us to run the Fortran driver as a Python module. -# root_dir = os.path.join(,'bindings') -# include_dirs = "" -# include_dirs = include_dirs.split() -# include_dirs.append(root_dir) -# link_flags = "" -# link_flags = link_flags.split() - -# pybindings_extension = [Extension('swiftest.bindings', -# [os.path.join(root_dir,'bindings.pyx')], -# extra_compile_args=['-fPIC', '-O3'], -# extra_link_args=link_flags, -# include_dirs=include_dirs, -# package_data={"": [os.path.join(root_dir,'bindings.h')]} -# )] with open('version.txt') as version_file: version = version_file.read().strip() + setup(name='swiftest', version=version, author='David A. Minton', @@ -39,7 +22,13 @@ url='https://github.itap.purdue.edu/MintonGroup/swiftest', python_requires=">3.8", license="GPLv3", - #ext_modules = cythonize(pybindings_extension), + cmake_args=[ + '-DCMAKE_BUILD_TYPE=RELEASE', + '-DMACHINE_CODE_VALUE="generic"', + '-DUSE_COARRAY:BOOL=OFF', + '-DUSE_OPENMP:BOOL=ON', + '-DBUILD_SHARED_LIBS:BOOL=OFF' + ], install_requires= [ 'numpy>=1.24.3', 'pandas>=1.5.3', @@ -54,4 +43,4 @@ 'astroquery>=0.4.6', 'tqdm>=4.65.0', ], - packages=find_packages()) + packages=['swiftest']) diff --git a/src/bindings/CMakeLists.txt b/src/bindings/CMakeLists.txt index 1fec84b18..f72f75ba4 100644 --- a/src/bindings/CMakeLists.txt +++ b/src/bindings/CMakeLists.txt @@ -1,5 +1,9 @@ # Use the old method to get Python packages, as that's what scikit-build uses CMAKE_POLICY(SET CMP0148 OLD) + +SET(CYTHON_FLAGS + "--directive binding=True,boundscheck=False,wraparound=False,embedsignature=True,always_allow_keywords=True" + CACHE STRING "The directives for Cython compilation.") FIND_PACKAGE(PythonInterp REQUIRED) FIND_PACKAGE(Cython REQUIRED) FIND_PACKAGE(PythonExtensions REQUIRED) @@ -14,19 +18,6 @@ IF(${PYTHON_VERSION_MAJOR} EQUAL 3 ADD_COMPILE_OPTIONS("-Wno-deprecated-declarations") ENDIF() - -# Detect when building against a conda environment set the _using_conda variable -# for use both in this file and in the parent -GET_FILENAME_COMPONENT(_python_bin_dir ${PYTHON_EXECUTABLE} DIRECTORY) -IF(EXISTS "${_python_bin_dir}/../conda-meta") - MESSAGE("-- Detected conda environment, setting INSTALL_RPATH_USE_LINK_PATH") - SET(_using_conda On) - SET(_using_conda On PARENT_SCOPE) -ELSE() - SET(_using_conda Off) - SET(_using_conda Off PARENT_SCOPE) -ENDIF() - SET(SWIFTEST_BINDINGS swiftest_bindings) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) @@ -34,4 +25,15 @@ ADD_CYTHON_TARGET(${SWIFTEST_BINDINGS} bindings.pyx) ADD_LIBRARY(${SWIFTEST_BINDINGS} MODULE ${SWIFTEST_BINDINGS}) TARGET_LINK_LIBRARIES(${SWIFTEST_BINDINGS} ${SWIFTEST_LIBRARY} ${SWIFTEST_LIBRARY} ${NETCDF_FORTRAN_LIBRARIES} ${NETCDF_LIBRARIES} $ENV{LIBS}) PYTHON_EXTENSION_MODULE(${SWIFTEST_BINDINGS}) -INSTALL(TARGETS ${SWIFTEST_BINDINGS} LIBRARY DESTINATION ${PY}) \ No newline at end of file +INSTALL(TARGETS ${SWIFTEST_BINDINGS} DESTINATION swiftest) + +IF(APPLE) + SET_TARGET_PROPERTIES(${SWIFTEST_BINDINGS} PROPERTIES INSTALL_RPATH "@loader_path") +ELSE() + SET_TARGET_PROPERTIES(${SWIFTEST_BINDINGS} PROPERTIES INSTALL_RPATH "\$ORIGIN") +ENDIF() + +IF(_using_conda OR DEFINED ENV{CIBUILDWHEEL}) + MESSAGE(STATUS "Conda detected. Setting INSTALL_RPATH_USE_LINK_PATH to True") + SET_TARGET_PROPERTIES(${SWIFTEST_BINDINGS} PROPERTIES INSTALL_RPATH_USE_LINK_PATH True) +ENDIF() \ No newline at end of file diff --git a/swiftest/__init__.py b/swiftest/__init__.py index 8933c9d49..8d382b20a 100644 --- a/swiftest/__init__.py +++ b/swiftest/__init__.py @@ -9,6 +9,6 @@ If not, see: https://www.gnu.org/licenses. """ -from constants import * -from simulation_class import Simulation -from swiftest_bindings import driver \ No newline at end of file +from swiftest.constants import * +from swiftest.simulation_class import Simulation +from swiftest.swiftest_bindings import driver \ No newline at end of file