Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Rearranged and tweaked until I finally have a working scikit-build setup
Browse files Browse the repository at this point in the history
  • Loading branch information
MintoDA1 authored and MintoDA1 committed Aug 9, 2023
1 parent 80fcb85 commit 24c9333
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 65 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ IF (NOT SKBUILD)
MESSAGE(STATUS "Looking in ${SKBLD_DIR}/resources/cmake for CMake modules")
ENDIF()

SET(PYTHON_EXTENSION_MODULE_SUFFIX ".${Python3_SOABI}" CACHE STRING "Suffix for python extension modules")

# 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)
Expand Down Expand Up @@ -68,7 +66,8 @@ SET(CMAKE_Fortran_MODULE_DIRECTORY ${MOD})

# The source for the SWIFTEST binary and have it placed in the bin folder
ADD_SUBDIRECTORY(${SRC} ${BIN})
ADD_SUBDIRECTORY(${SRC}/bindings)

ADD_SUBDIRECTORY(${PY})
# # Set up test directory
# ENABLE_TESTING()
# ADD_SUBDIRECTORY(${TEST})
Expand Down
3 changes: 1 addition & 2 deletions cmake/Modules/FindNETCDF.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ find_library(NETCDF_FORTRAN_LIBRARY NAMES netcdff HINTS ENV NETCDF_FORTRAN_HOME
find_library(NETCDF_LIBRARY NAMES netcdf HINTS ENV NETCDF_FORTRAN_HOME ENV LD_LIBRARY_PATH)

set(NETCDF_FOUND TRUE)
set(NETCDF_INCLUDE_DIRS ${NETCDF_INCLUDE_DIR})
# Note for posterity: When building static libraries, NETCDF_FORTRAN_LIBRARY must come *before* NETCDF_LIBRARY. Otherwise you get a bunch of "undefined reference to" errors
set(NETCDF_LIBRARIES ${NETCDF_FORTRAN_LIBRARY} ${NETCDF_LIBRARY})
set(NETCDF_LIBRARIES ${NETCDF_FORTRAN_LIBRARY} ${NETCDF_LIBRARY} CACHE STRING "NetCDF libraries")

mark_as_advanced(NETCDF_LIBRARY NETCDF_FORTRAN_LIBRARY NETCDF_INCLUDE_DIR)
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"""

from skbuild import setup
from Cython.Build import cythonize
import os

with open('version.txt') as version_file:
version = version_file.read().strip()
Expand Down Expand Up @@ -43,4 +45,5 @@
'astroquery>=0.4.6',
'tqdm>=4.65.0',
],
packages=['swiftest'])
packages=['swiftest'],
)
40 changes: 18 additions & 22 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,24 @@ ENDIF ()
# Turn preprocessor on for all files
SET_SOURCE_FILES_PROPERTIES(${SWIFTEST_src} ${DRIVER_src} PROPERTIES Fortran_PREPROCESS ON)


#Set strict vs fast math flags
STRING(TOUPPER "${CMAKE_BUILD_TYPE}" BT)
IF(BT STREQUAL "RELEASE" OR BT STREQUAL "PROFILE")
SET_PROPERTY(SOURCE ${STRICT_MATH_FILES} APPEND_STRING PROPERTY COMPILE_FLAGS "${STRICTMATH_FLAGS}")
SET_PROPERTY(SOURCE ${FAST_MATH_FILES} APPEND_STRING PROPERTY COMPILE_FLAGS "${FASTMATH_FLAGS}")
ENDIF()

IF(BT STREQUAL "DEBUG")
ADD_DEFINITIONS(-DDEBUG)
ELSEIF(BT STREQUAL "PROFILE")
ADD_DEFINITIONS(-DPROFILE)
ENDIF()

#####################################################
# Add the needed libraries and special compiler flags
#####################################################

# Create a library from the source files, except the driver
SET(SWIFTEST_LIBRARY swiftest)
ADD_LIBRARY(${SWIFTEST_LIBRARY} ${SWIFTEST_src})
Expand All @@ -144,10 +162,6 @@ ADD_LIBRARY(${SWIFTEST_LIBRARY} ${SWIFTEST_src})
SET(SWIFTEST_DRIVER swiftest_driver)
ADD_EXECUTABLE(${SWIFTEST_DRIVER} ${DRIVER_src})

#####################################################
# Add the needed libraries and special compiler flags
#####################################################

TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PUBLIC ${SWIFTEST_LIBRARY} ${NETCDF_FORTRAN_LIBRARIES} ${NETCDF_LIBRARIES} $ENV{LIBS})

IF(USE_OPENMP)
Expand All @@ -162,24 +176,6 @@ IF(USE_COARRAY)
SET_PROPERTY(TARGET ${SWIFTEST_LIBRARY} ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY LINK_FLAGS "${Coarray_Fortran_FLAGS} ")
ENDIF(USE_COARRAY)

STRING(REPLACE ";" " " SWIFTEST_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS} -L${LIB} ${CMAKE_LINK_LIBRARY_FLAG}${SWIFTEST_LIBRARY} ${NETCDF_FORTRAN_LIBRARIES} ${NETCDF_LIBRARIES} $ENV{LIBS}")
SET(SWIFTEST_LINK_FLAGS "${SWIFTEST_LINK_FLAGS}" CACHE STRING "Link flags to pass to setup.py")

GET_TARGET_PROPERTY(SWIFTEST_INCLUDE_DIR ${SWIFTEST_DRIVER} INCLUDE_DIRECTORIES)
SET(SWIFTEST_INCLUDE_DIR "${SWIFTEST_INCLUDE_DIR}" CACHE STRING "Include directory needed for linking the library to an executable")

#Set strict vs fast math flags
STRING(TOUPPER "${CMAKE_BUILD_TYPE}" BT)
IF(BT STREQUAL "RELEASE" OR BT STREQUAL "PROFILE")
SET_PROPERTY(SOURCE ${STRICT_MATH_FILES} APPEND_STRING PROPERTY COMPILE_FLAGS "${STRICTMATH_FLAGS}")
SET_PROPERTY(SOURCE ${FAST_MATH_FILES} APPEND_STRING PROPERTY COMPILE_FLAGS "${FASTMATH_FLAGS}")
ENDIF()

IF(BT STREQUAL "DEBUG")
ADD_DEFINITIONS(-DDEBUG)
ELSEIF(BT STREQUAL "PROFILE")
ADD_DEFINITIONS(-DPROFILE)
ENDIF()

# Check to see if the compiler allows for local-spec in do concurrent statements. Set a preprocessor variable if it does
IF (USE_OPENMP)
Expand Down
Empty file removed src/bindings/__init__.py
Empty file.
1 change: 0 additions & 1 deletion src/bindings/bindings.h

This file was deleted.

17 changes: 0 additions & 17 deletions src/bindings/bindings.pyx

This file was deleted.

22 changes: 6 additions & 16 deletions src/bindings/CMakeLists.txt → swiftest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,12 @@ IF(${PYTHON_VERSION_MAJOR} EQUAL 3
ADD_COMPILE_OPTIONS("-Wno-deprecated-declarations")
ENDIF()

SET(SWIFTEST_BINDINGS swiftest_bindings)
SET(SWIFTEST_BINDINGS _bindings)

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
ADD_CYTHON_TARGET(${SWIFTEST_BINDINGS} bindings.pyx)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${MOD})
ADD_CYTHON_TARGET(${SWIFTEST_BINDINGS})
ADD_LIBRARY(${SWIFTEST_BINDINGS} MODULE ${SWIFTEST_BINDINGS})
TARGET_LINK_LIBRARIES(${SWIFTEST_BINDINGS} ${SWIFTEST_LIBRARY} ${SWIFTEST_LIBRARY} ${NETCDF_FORTRAN_LIBRARIES} ${NETCDF_LIBRARIES} $ENV{LIBS})
#MESSAGE(STATUS "Module linked libraries\nswiftest: ${SWIFTEST_LIBRARY}\nnetcdf: ${NETCDF_LIBRARIES}\nLIBS: $ENV{LIBS}")
TARGET_LINK_LIBRARIES(${SWIFTEST_BINDINGS} swiftest ${NETCDF_LIBRARIES} $ENV{LIBS})
PYTHON_EXTENSION_MODULE(${SWIFTEST_BINDINGS})
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()
INSTALL(TARGETS ${SWIFTEST_BINDINGS} LIBRARY DESTINATION swiftest)
6 changes: 3 additions & 3 deletions swiftest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
If not, see: https://www.gnu.org/licenses.
"""

from swiftest.constants import *
from swiftest.simulation_class import Simulation
from swiftest.swiftest_bindings import driver
from .constants import *
from .simulation_class import Simulation
from ._bindings import driver

0 comments on commit 24c9333

Please sign in to comment.