diff --git a/CMakeLists.txt b/CMakeLists.txt index f6cd01b..b830e93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright 2022 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh -# This file is part of Swiftest. +# Copyright 2024 - The Minton Group at Purdue University +# This file is part of CTEM # Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License # as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. # Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty @@ -17,6 +17,34 @@ SET(SKBUILD_PROJECT_NAME "ctem" CACHE STRING "Name of project set by scikit-buil # Get version stored in text file FILE(READ "version.txt" VERSION) PROJECT(${SKBUILD_PROJECT_NAME} LANGUAGES C Fortran VERSION ${VERSION}) +SET(SKBUILD_SCRIPTS_DIR "${CMAKE_SOURCE_DIR}/bin" CACHE STRING "Install location of binary executable") + +IF (SKBUILD) + set(ENV_PREFIX "$ENV{PREFIX}") + string(REPLACE "" "${ENV_PREFIX}" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") +ENDIF () + +IF(DEFINED ENV{CIBUILDWHEEL}) + SET(CIBUILDWHEEL ON) +ENDIF() + +# Check for a Fortran compiler +IF(DEFINED ENV{FC}) + SET(CMAKE_Fortran_COMPILER $ENV{FC} CACHE STRING "Fortran compiler") +ELSE() + # If FC is not set, search for the Fortran compilers in the specified order. + FIND_PROGRAM(Fortran_COMPILER + NAMES gfortran-14 gfortran-13 gfortran-12 gfortran ifort mpiifort + DOC "Fortran compiler") + + # If a compiler is found, set it as the Fortran compiler. + IF(Fortran_COMPILER) + SET(CMAKE_Fortran_COMPILER ${Fortran_COMPILER} CACHE STRING "Fortran compiler") + ELSE() + MESSAGE(FATAL_ERROR "No suitable Fortran compiler was found.") + ENDIF() +ENDIF() +MESSAGE(STATUS "Using Fortran compiler: ${CMAKE_Fortran_COMPILER}") IF (CMAKE_Fortran_COMPILER_ID MATCHES "^Intel") SET(COMPILER_OPTIONS "Intel" CACHE STRING "Compiler identified as Intel") @@ -49,15 +77,16 @@ FILE(TO_CMAKE_PATH ${PY} PY) 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 () + SET(INSTALL_BINDIR ${INSTALL_PYPROJ}) + IF (CIBUILDWHEEL) + SET(INSTALL_LIBDIR ${CMAKE_BINARY_DIR}/lib) + SET(CMAKE_INSTALL_RPATH "${CMAKE_BINARY_DIR}/bin") + ELSE() + SET(INSTALL_LIBDIR ${INSTALL_BINDIR}) + SET(CMAKE_INSTALL_RPATH "${INSTALL_LIBDIR}") + ENDIF() + SET(INSTALL_INCLUDEDIR ${SKBUILD_HEADERS_DIR}) ELSE () SET(INSTALL_PYPROJ ${PY}) SET(INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR}) @@ -65,6 +94,11 @@ ELSE () SET(INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}) ENDIF () +MESSAGE(STATUS "INSTALL_BINDIR: ${INSTALL_BINDIR}") +MESSAGE(STATUS "INSTALL_LIBDIR: ${INSTALL_LIBDIR}") +MESSAGE(STATUS "INSTALL_INCLUDEDIR: ${INSTALL_INCLUDEDIR}") +MESSAGE(STATUS "INSTALL_PYPROJ: ${INSTALL_PYPROJ}") +MESSAGE(STATUS "CMAKE_INSTALL_RPATH: ${CMAKE_INSTALL_RPATH}") SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # Have the .mod files placed in the lib folder @@ -74,8 +108,21 @@ SET(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod) FILE(TO_CMAKE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" LOCAL_MODULE_PATH) LIST(APPEND CMAKE_MODULE_PATH ${LOCAL_MODULE_PATH}) +MESSAGE(STATUS "CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR}) +##################################### +# Tell how to install this executable +##################################### +IF(CMAKE_SYSTEM_NAME STREQUAL "Windows") + SET(CMAKE_INSTALL_PREFIX "C:\\Program Files\\swiftest") + FILE(TO_CMAKE_PATH ${CMAKE_INSTALL_PREFIX} CMAKE_INSTALL_PREFIX) + SET(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Path for install") +ELSE() + SET(CMAKE_INSTALL_PREFIX /usr/local CACHE PATH "Path for install") +ENDIF() + + # Set the name of the ctem library -SET(CTEM_LIBRARY ctem) +SET(CTEM_LIBRARY ${SKBUILD_PROJECT_NAME}) # The source for the CTEM binary and have it placed in the bin folder ADD_SUBDIRECTORY(${SRC} ${BIN}) diff --git a/ctem/cli.py b/ctem/cli.py new file mode 100644 index 0000000..289a75a --- /dev/null +++ b/ctem/cli.py @@ -0,0 +1,44 @@ +import os +import pty +import subprocess +import sys + + +def main(binary_name="CTEM"): + """Executes the binary located in the package root, passing along any command-line arguments, and streams the output to the terminal in real-time, handling progress bars correctly by using a pseudo-terminal.""" + + # Determine the path to the binary relative to this script + package_root = os.path.dirname(os.path.abspath(__file__)) + binary_path = os.path.join(package_root, binary_name) + + # sys.argv[1:] contains all the arguments passed to the script, excluding the script name itself + args = [binary_path] + sys.argv[1:] + + # Use pty to spawn the process and create a pseudo-terminal + main_fd, subordinate_fd = pty.openpty() + + # Spawn the subprocess + proc = subprocess.Popen(args, stdin=subordinate_fd, stdout=subordinate_fd, stderr=subordinate_fd, close_fds=True) + + # Close the subordinate file descriptor in the parent process + os.close(subordinate_fd) + + # Read the output from the main file descriptor + while True: + try: + output = os.read(main_fd, 1024).decode() + if output: + sys.stdout.write(output) + sys.stdout.flush() + else: + break + except OSError: + break + + # Wait for the subprocess to finish + proc.wait() + + return + +if __name__ == "__main__": + main() diff --git a/pyproject.toml b/pyproject.toml index 323ed85..4abceb8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "ctem" -version = "2024.2.0" +version = "2024.6.0" authors=[ {name = 'David A. Minton', email='daminton@purdue.edu'}, {name = 'James E. Richardson'}, @@ -35,6 +35,9 @@ dependencies = [ [project.urls] Repository = 'https://github.itap.purdue.edu/MintonGroup/ctem' +[project.scripts] +CTEM = "ctem.cli:main" + [build-system] requires = [ "scikit-build-core", diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bc1aebc..d6eb1f0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright 2023 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh -# This file is part of Swiftest. +# Copyright 2024 - The Minton Group at Purdue University +# This file is part of CTEM # Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License # as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. # Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty diff --git a/version.txt b/version.txt index 032892e..35639dd 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2024.2.0 \ No newline at end of file +2024.6.0 \ No newline at end of file