Skip to content

Commit

Permalink
Added some template CMake files and cleaned up the ignore files a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
MintoDA1 authored and MintoDA1 committed Sep 8, 2023
1 parent e8bfe70 commit cbee67b
Show file tree
Hide file tree
Showing 76 changed files with 4,958 additions and 4,824 deletions.
12 changes: 10 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Whitelist ignore file: Ignore everything that isn't explicitly included
*
!*/
!ctem/**
!examples/**
!/src/**
!src/**
!cmake/**
!**/.gitignore
!*.f90
!*.py
!*.cmake
!README.md
!ctem.in
!craterlist.in
Expand All @@ -13,5 +17,9 @@
!NPFextrap.dat
!FassettCounts.txt
!NonMareNonSpa-Highlands.csv

!CMakeLists.txt
!version.txt
*.mod
**/.idea
**/__pycache__

78 changes: 78 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2022 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh
# This file is part of Swiftest.
# 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
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with Swiftest.
# If not, see: https://www.gnu.org/licenses.

# CMake project file for Swiftest
##################################################
# Define the project and the depencies that it has
##################################################
CMAKE_MINIMUM_REQUIRED(VERSION 3.6.0...3.27.1)

# Get version stored in text file
FILE(READ "version.txt" 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")
ELSEIF (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
SET(COMPILER_OPTIONS "GNU" CACHE STRING "Compiler identified as gfortran")
ELSE ()
MESSAGE(FATAL_ERROR "Compiler ${CMAKE_Fortran_COMPILER_ID} not recognized!")
ENDIF ()

# Set some options the user may choose
OPTION(USE_COARRAY "Use Coarray Fortran for parallelization of test particles" OFF)
OPTION(USE_OPENMP "Use OpenMP for parallelization" ON)
OPTION(USE_SIMD "Use SIMD vectorization" ON)
OPTION(BUILD_SHARED_LIBS "Build using shared libraries" OFF)

# The following section is modified from Numpy f2py documentation
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()

# 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})

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

# Set the name of the ctem library
SET(CTEM_LIBRARY ctem)

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

ADD_SUBDIRECTORY(${PY})

# Add a distclean target to the Makefile
ADD_CUSTOM_TARGET(distclean
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_SOURCE_DIR}/distclean.cmake"
)
117 changes: 117 additions & 0 deletions cmake/Modules/FindCoarray_Fortran.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Copyright 2022 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh
# This file is part of Swiftest.
# 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
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with Swiftest.
# If not, see: https://www.gnu.org/licenses.

# - Finds Coarray support
# This module can be used to detect Coarray support in a compiler.
# If the compiler supports Coarray, the flags required to compile with
# coarray support are set.
#
# This module was modified from the standard FindOpenMP module to find Fortran
# flags.
#
# The following variables are set:
# Coarray_Fortran_FLAGS - flags to add to the Fortran compiler for Coarray
# support. In general, you must use these at both
# compile- and link-time.
# OMP_NUM_PROCS - the max number of processors available to Coarray

#=============================================================================

INCLUDE (FindPackageHandleStandardArgs)

STRING(TOUPPER "${CMAKE_BUILD_TYPE}" BT)
IF(BT STREQUAL "DEBUG")
IF (COMPILER_OPTIONS STREQUAL "Intel")
SET (Coarray_Fortran_FLAG_CANDIDATES
#Intel
"-coarray=single"
#Intel windows
"/Qcoarray:single"
#Empty, if compiler automatically accepts coarray
" "
)
ELSEIF (COMPILER_OPTIONS STREQUAL "GNU")
SET (Coarray_Fortran_FLAG_CANDIDATES
#Gnu
"-fcoarray=single"
#Empty, if compiler automatically accepts coarray
" "
)
ENDIF()
ELSE()
IF (COMPILER_OPTIONS STREQUAL "Intel")
SET (Coarray_Fortran_FLAG_CANDIDATES
#Intel
"-coarray=distributed"
#Intel windows
"/Qcoarray:distributed"
#Empty, if compiler automatically accepts coarray
" "
)
ELSEIF (COMPILER_OPTIONS STREQUAL "GNU")
SET (Coarray_Fortran_FLAG_CANDIDATES
#Gnu
"-fcoarray=lib -lcaf_mpi"
#Empty, if compiler automatically accepts coarray
" "
)
ENDIF()


IF (DEFINED Coarray_Fortran_FLAGS)
SET (Coarray_Fortran_FLAG_CANDIDATES)
ENDIF (DEFINED Coarray_Fortran_FLAGS)

# check fortran compiler. also determine number of processors
FOREACH (FLAG ${Coarray_Fortran_FLAG_CANDIDATES})
SET (SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
SET (CMAKE_REQUIRED_FLAGS "${FLAG}")
UNSET (Coarray_FLAG_DETECTED CACHE)
MESSAGE (STATUS "Try Coarray Fortran flag = [${FLAG}]")
FILE (WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCoarray.f90"
"
program TestCoarray
integer, codimension[*] :: i
write(*,'(I2)',ADVANCE='NO') num_images()
end program TestCoarray
")
SET (MACRO_CHECK_FUNCTION_DEFINITIONS
"-DCoarray_FLAG_DETECTED ${CMAKE_REQUIRED_FLAGS}")
TRY_RUN (Coarray_RUN_FAILED Coarray_FLAG_DETECTED ${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCoarray.f90
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
COMPILE_OUTPUT_VARIABLE OUTPUT
RUN_OUTPUT_VARIABLE OMP_NUM_PROCS_INTERNAL)
IF (Coarray_FLAG_DETECTED)
FILE (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Determining if the Fortran compiler supports Coarray passed with "
"the following output:\n${OUTPUT}\n\n")
SET (Coarray_FLAG_DETECTED 1)
IF (Coarray_RUN_FAILED)
MESSAGE (FATAL_ERROR "Coarray found, but test code did not run")
ENDIF (Coarray_RUN_FAILED)
SET (Coarray_Fortran_FLAGS_INTERNAL "${FLAG}")
BREAK ()
ELSE ()
FILE (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if the Fortran compiler supports Coarray failed with "
"the following output:\n${OUTPUT}\n\n")
SET (Coarray_FLAG_DETECTED 0)
ENDIF (Coarray_FLAG_DETECTED)
ENDFOREACH (FLAG ${Coarray_Fortran_FLAG_CANDIDATES})

SET (Coarray_Fortran_FLAGS "${Coarray_Fortran_FLAGS_INTERNAL}"
CACHE STRING "Fortran compiler flags for Coarray parallization")

# handle the standard arguments for FIND_PACKAGE
FIND_PACKAGE_HANDLE_STANDARD_ARGS (Coarray_Fortran DEFAULT_MSG
Coarray_Fortran_FLAGS)

MARK_AS_ADVANCED(Coarray_Fortran_FLAGS)
88 changes: 88 additions & 0 deletions cmake/Modules/FindCython.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#.rst:
#
# Find ``cython`` executable.
#
# This module will set the following variables in your project:
#
# ``CYTHON_EXECUTABLE``
# path to the ``cython`` program
#
# ``CYTHON_VERSION``
# version of ``cython``
#
# ``CYTHON_FOUND``
# true if the program was found
#
# For more information on the Cython project, see https://cython.org/.
#
# *Cython is a language that makes writing C extensions for the Python language
# as easy as Python itself.*
#
#=============================================================================
# Copyright 2011 Kitware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================

# Use the Cython executable that lives next to the Python executable
# if it is a local installation.
if(Python_EXECUTABLE)
get_filename_component(_python_path ${Python_EXECUTABLE} PATH)
elseif(Python3_EXECUTABLE)
get_filename_component(_python_path ${Python3_EXECUTABLE} PATH)
elseif(DEFINED PYTHON_EXECUTABLE)
get_filename_component(_python_path ${PYTHON_EXECUTABLE} PATH)
endif()

if(DEFINED _python_path)
find_program(CYTHON_EXECUTABLE
NAMES cython cython.bat cython3
HINTS ${_python_path}
DOC "path to the cython executable")
else()
find_program(CYTHON_EXECUTABLE
NAMES cython cython.bat cython3
DOC "path to the cython executable")
endif()

if(CYTHON_EXECUTABLE)
set(CYTHON_version_command ${CYTHON_EXECUTABLE} --version)

execute_process(COMMAND ${CYTHON_version_command}
OUTPUT_VARIABLE CYTHON_version_output
ERROR_VARIABLE CYTHON_version_error
RESULT_VARIABLE CYTHON_version_result
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE)

if(NOT ${CYTHON_version_result} EQUAL 0)
set(_error_msg "Command \"${CYTHON_version_command}\" failed with")
set(_error_msg "${_error_msg} output:\n${CYTHON_version_error}")
message(SEND_ERROR "${_error_msg}")
else()
if("${CYTHON_version_output}" MATCHES "^[Cc]ython version ([^,]+)")
set(CYTHON_VERSION "${CMAKE_MATCH_1}")
else()
if("${CYTHON_version_error}" MATCHES "^[Cc]ython version ([^,]+)")
set(CYTHON_VERSION "${CMAKE_MATCH_1}")
endif()
endif()
endif()
endif()

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cython REQUIRED_VARS CYTHON_EXECUTABLE)

mark_as_advanced(CYTHON_EXECUTABLE)

include(UseCython)
17 changes: 17 additions & 0 deletions cmake/Modules/FindMKL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2022 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh
# This file is part of Swiftest.
# 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
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with Swiftest.
# If not, see: https://www.gnu.org/licenses.

# - Finds the Intel MKL libraries
find_path(MKL_INCLUDE_DIR NAMES mkl.h HINTS ENV MKLROOT PATH_SUFFIXES include)
find_library(MKL_LIBRARY NAMES libmkl_core.a HINTS ENV MKLROOT PATH_SUFFIXES lib lib/intel64 )

set(MKL_FOUND TRUE)
set(MKL_INCLUDE_DIRS ${MKL_INCLUDE_DIR})
set(MKL_LIBRARIES ${MKL_LIBRARY})
mark_as_advanced(MKL_LIBRARY MKL_INCLUDE_DIR)
Loading

0 comments on commit cbee67b

Please sign in to comment.