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

Commit

Permalink
Updated compiler flag checks. Now use built in check_fortran_compiler…
Browse files Browse the repository at this point in the history
…_flag function and fixed Windows options
  • Loading branch information
daminton committed Sep 20, 2023
1 parent 2446448 commit 6cfa241
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 37 deletions.
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,15 @@ FILE(TO_CMAKE_PATH ${PY} PY)
# Set the name of the swiftest library
SET(SWIFTEST_LIBRARY ${SKBUILD_PROJECT_NAME})


# This INCLUDE statement executes code that sets the compile flags for DEBUG,
# RELEASE, PROFILING, and TESTING.
# Determine compiler options
IF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)
MESSAGE(FATAL_ERROR "Fortran compiler does not support F90")
ENDIF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)
INCLUDE(SetParallelizationLibrary)

IF (COMPILER_OPTIONS STREQUAL "Intel" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
INCLUDE(SetMKL)
ENDIF ()
INCLUDE(SetSwiftestFlags)

# The source for the SWIFTEST binary and have it placed in the bin folder
Expand Down
2 changes: 1 addition & 1 deletion cmake/Modules/FindOpenMP_Fortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ IF (COMPILER_OPTIONS STREQUAL "Intel")
)
ELSE ()
SET (OpenMP_Fortran_FLAG_CANDIDATES
"/Qopenmp-simd-" # Intel Windows
"/Qopenmp /Qopenmp-simd-" # Intel Windows
)
ENDIF (USE_SIMD)
ELSE ()
Expand Down
22 changes: 2 additions & 20 deletions cmake/Modules/SetCompileFlag.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

INCLUDE(${CMAKE_ROOT}/Modules/CheckCCompilerFlag.cmake)
INCLUDE(${CMAKE_ROOT}/Modules/CheckCXXCompilerFlag.cmake)
INCLUDE(${CMAKE_ROOT}/Modules/CheckFortranCompilerFlag.cmake)

FUNCTION(SET_COMPILE_FLAG FLAGVAR FLAGVAL LANG)

Expand Down Expand Up @@ -79,26 +80,7 @@ FUNCTION(SET_COMPILE_FLAG FLAGVAR FLAGVAL LANG)
ELSEIF(LANG STREQUAL "CXX")
CHECK_CXX_COMPILER_FLAG("${flag}" FLAG_WORKS)
ELSEIF(LANG STREQUAL "Fortran")
# There is no nice function to do this for FORTRAN, so we must manually
# create a test program and check if it compiles with a given flag.
SET(TESTFILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}")
SET(TESTFILE "${TESTFILE}/CMakeTmp/testFortranFlags.f90")
FILE(WRITE "${TESTFILE}"
"
program dummyprog
i = 5
end program dummyprog
")
TRY_COMPILE(FLAG_WORKS ${CMAKE_BINARY_DIR} ${TESTFILE}
COMPILE_DEFINITIONS "${flag}" OUTPUT_VARIABLE OUTPUT)

# Check that the output message doesn't match any errors
FOREACH(rx ${FAIL_REGEX})
IF("${OUTPUT}" MATCHES "${rx}")
SET(FLAG_WORKS FALSE)
ENDIF("${OUTPUT}" MATCHES "${rx}")
ENDFOREACH(rx ${FAIL_REGEX})

CHECK_Fortran_COMPILER_FLAG("${flag}" FLAG_WORKS)
ELSE()
MESSAGE(FATAL_ERROR "Unknown language in SET_COMPILE_FLAGS: ${LANG}")
ENDIF(LANG STREQUAL "C")
Expand Down
6 changes: 3 additions & 3 deletions cmake/Modules/SetSwiftestFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,11 @@ IF (CMAKE_BUILD_TYPE STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE STREQUAL "PROFILE")
IF (WINOPT)
# Unroll loops
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "/unroll" # Intel Windows
Fortran "/Qunroll" # Intel Windows
)
# Inline functions
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "/Qinline" # Intel Windows
Fortran "/inline" # Intel Windows
)
# Calls the Matrix Multiply library
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Expand All @@ -520,7 +520,7 @@ IF (CMAKE_BUILD_TYPE STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE STREQUAL "PROFILE")
)
# No floating-point exceptions
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "/fp:no-except" # Intel Windows
Fortran "/fp:except-" # Intel Windows
)
# Generate fused multiply-add instructions
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Expand Down
11 changes: 1 addition & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ set(GLOBAL_MODULE_IN ${SRC}/globals/globals_module.f90.in)
set(GLOBAL_MODULE_OUT ${SRC}/globals/globals_module.f90)
CONFIGURE_FILE(${GLOBAL_MODULE_IN} ${GLOBAL_MODULE_OUT})

IF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)
MESSAGE(FATAL_ERROR "Fortran compiler does not support F90")
ENDIF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)

INCLUDE(SetParallelizationLibrary)
INCLUDE(SetUpNetCDF)
IF (COMPILER_OPTIONS STREQUAL "Intel" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
INCLUDE(SetMKL)
ENDIF ()

# Add the source files
SET(STRICT_MATH_FILES
${SRC}/collision/collision_generate.f90
Expand Down Expand Up @@ -136,6 +126,7 @@ ADD_EXECUTABLE(${SWIFTEST_DRIVER} ${DRIVER_src})
# Add the needed libraries
#####################################################
# Create a library from the source files, except the driver
INCLUDE(SetUpNetCDF)
ADD_LIBRARY(${SWIFTEST_LIBRARY} ${SWIFTEST_src})
IF (NOT BUILD_SHARED_LIBS)
SET_PROPERTY(TARGET ${SWIFTEST_LIBRARY} PROPERTY POSITION_INDEPENDENT_CODE)
Expand Down

0 comments on commit 6cfa241

Please sign in to comment.