Skip to content

Commit

Permalink
Updated the build process so that the CTEM executable gets installed …
Browse files Browse the repository at this point in the history
…into the environment's bin folder
  • Loading branch information
daminton committed Feb 20, 2024
1 parent b0e64a2 commit c143ab0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
43 changes: 27 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
##################################################
# Define the project and the depencies that it has
##################################################
CMAKE_MINIMUM_REQUIRED(VERSION 3.6.0...3.27.1)
CMAKE_MINIMUM_REQUIRED(VERSION 3.24.0...3.27.1)
SET(SKBUILD_PROJECT_NAME "ctem" CACHE STRING "Name of project set by scikit-build")

# Get version stored in text file
FILE(READ "version.txt" VERSION)
PROJECT(CTEM LANGUAGES C Fortran VERSION ${VERSION})
PROJECT(${SKBUILD_PROJECT_NAME} LANGUAGES C Fortran VERSION ${VERSION})

IF (CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
SET(COMPILER_OPTIONS "Intel" CACHE STRING "Compiler identified as Intel")
Expand All @@ -39,30 +40,40 @@ ENDIF()
# Ensure scikit-build modules
FIND_PACKAGE(Python COMPONENTS Interpreter Development.Module REQUIRED)

# Add our local modules to the module path
FILE(TO_CMAKE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" LOCAL_MODULE_PATH)
LIST(APPEND CMAKE_MODULE_PATH ${LOCAL_MODULE_PATH})

# 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")
SET(MOD "${CMAKE_SOURCE_DIR}/include")
SET(PY "${CMAKE_SOURCE_DIR}/ctem")

# Make sure paths are correct for Unix or Windows style
FILE(TO_CMAKE_PATH ${SRC} SRC)
FILE(TO_CMAKE_PATH ${LIB} LIB)
FILE(TO_CMAKE_PATH ${BIN} BIN)
FILE(TO_CMAKE_PATH ${MOD} MOD)
FILE(TO_CMAKE_PATH ${PY} PY)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN})
INCLUDE(GNUInstallDirs)
IF (SKBUILD)
SET(INSTALL_BINDIR ${SKBUILD_SCRIPTS_DIR})
SET(INSTALL_LIBDIR ${SKBUILD_DATA_DIR}/lib)
SET(INSTALL_INCLUDEDIR ${SKBUILD_HEADERS_DIR})
SET(INSTALL_PYPROJ ${SKBUILD_PLATLIB_DIR}/${SKBUILD_PROJECT_NAME})
IF (APPLE)
SET(CMAKE_INSTALL_RPATH "@loader_path;${CMAKE_BINARY_DIR}/bin")
ELSEIF (LINUX)
SET(CMAKE_INSTALL_RPATH "@ORIGIN;${CMAKE_BINARY_DIR}/bin")
ENDIF ()
ELSE ()
SET(INSTALL_PYPROJ ${PY})
SET(INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR})
SET(INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
SET(INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR})
ENDIF ()

SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# Have the .mod files placed in the lib folder
SET(CMAKE_Fortran_MODULE_DIRECTORY ${MOD})
SET(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod)

# Add our local modules to the module path
FILE(TO_CMAKE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" LOCAL_MODULE_PATH)
LIST(APPEND CMAKE_MODULE_PATH ${LOCAL_MODULE_PATH})

# Set the name of the ctem library
SET(CTEM_LIBRARY ctem)
Expand Down
12 changes: 4 additions & 8 deletions ctem/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,10 @@ def __init__(self, param_file="ctem.in", isnew=True):
}

# Get the location of the CTEM executable
self.ctem_executable = Path(currentdir) / "CTEM"
if not self.ctem_executable.exists():
print(f"CTEM driver not found at {self.ctem_executable}. Trying package directory..")
self.ctem_executable = Path(_pyfile).parent.parent.parent / "bin" / "CTEM"
if not self.ctem_executable.exists():
warnings.warn(f"Cannot find the CTEM driver {str(self.ctem_executable)}", stacklevel=2)
self.ctem_executable = None

self.ctem_executable = shutil.which("CTEM")
if not self.ctem_executable:
warnings.warn(f"Cannot find the CTEM driver {str(self.ctem_executable)}", stacklevel=2)
self.ctem_executable = None

self.user = util.read_user_input(self.user)

Expand Down
1 change: 0 additions & 1 deletion examples/quasimc-global/CTEM

This file was deleted.

8 changes: 4 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ ELSE()
SET(CMAKE_INSTALL_PREFIX /usr/local)
ENDIF(WIN32)
INSTALL(TARGETS ${CTEM_DRIVER} ${CTEM_LIBRARY}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
INCLUDES DESTINATION include
RUNTIME DESTINATION ${INSTALL_BINDIR}
LIBRARY DESTINATION ${INSTALL_LIBDIR}
ARCHIVE DESTINATION ${INSTALL_LIBDIR}
INCLUDES DESTINATION ${INSTALL_INCLUDEDIR}
)

0 comments on commit c143ab0

Please sign in to comment.