Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmake revamp #222

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 15 additions & 59 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,51 +1,20 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)

#Setting Default value for libdir
set(CMAKE_INSTALL_LIBDIR "lib" CACHE STRING "Library install directory")
CMAKE_MINIMUM_REQUIRED(VERSION 3.18)
PROJECT(hipfort VERSION 0.6 LANGUAGES Fortran C CXX) # hip-config.cmake requires CXX enabled

#include definitions for GNU install dir cmake flags.
include(GNUInstallDirs)

# Default compiler gfortran, otherwise cmake Fortran package will set it to f95
# You can override the compiler with cmake -DHIPFORT_COMPILER=
set(HIPFORT_COMPILER "/usr/bin/gfortran" CACHE STRING "Fortran Compiler to build HIPFORT")
set(HIPFORT_AR "/usr/bin/gcc-ar" CACHE STRING "Static archive command")
set(HIPFORT_RANLIB "/usr/bin/gcc-ranlib" CACHE STRING "ranlib used to create Static archive")
set(HIPFORT_COMPILER_FLAGS "-ffree-form -cpp -ffree-line-length-none -fmax-errors=5" CACHE STRING "Compiler flags to build HIPFORT")
set(HIPFORT_BUILD_TYPE "RELEASE" CACHE STRING "Set to RELEASE TESTING or DEBUG")

# The ROCm release manager and other integrators should build hipfort as follows:
# cmake -DHIPFORT_INSTALL_DIR=/opt/rocm-<release>/hipfort -DHIPFORT_VERSION=<release> <githubrepo>

set(HIPFORT_VERSION "0.6.0" CACHE STRING "Version of HIPFORT to build")
set(HIPFORT_INSTALL_DIR "/usr/local/hipfort-${HIPFORT_VERSION}" CACHE STRING "Install directory for hipfort")
IF(CMAKE_INSTALL_PREFIX)
# Make HIPFORT_INSTALL_DIR be the same as CmAKE_INSTALL_PREFIX
set(HIPFORT_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
ELSE()
# Make CMAKE_INSTALL_PREFIX be the same as HIPFORT_INSTALL_PREFIX
set(CMAKE_INSTALL_PREFIX ${HIPFORT_INSTALL_DIR})
ENDIF()
message("-- HIPFORT ------------- cmake START -------------------")
message("-- HIPFORT_COMPILER: ${HIPFORT_COMPILER}")
message("-- HIPFORT_AR: ${HIPFORT_AR}")
message("-- HIPFORT_RANLIB: ${HIPFORT_RANLIB}")
message("-- HIPFORT_COMPILER_FLAGS: ${HIPFORT_COMPILER_FLAGS}")
message("-- HIPFORT_BUILD_TYPE: ${HIPFORT_BUILD_TYPE}")
message("-- HIPFORT_INSTALL_DIR: ${HIPFORT_INSTALL_DIR}")
message("-- HIPFORT_VERSION: ${HIPFORT_VERSION}")
message("-- Fortran Compiler: ${CMAKE_Fortran_COMPILER}")
message("-- Build Type: ${CMAKE_BUILD_TYPE}")
message("-- Installation Directory: ${CMAKE_INSTALL_PREFIX}")
message("-- hipfort Version: ${hipfort_VERSION}")
message("-- HIPFORT ----------------------------------------------")

set(CMAKE_Fortran_COMPILER_INIT ${HIPFORT_COMPILER})
PROJECT(hipfort Fortran C CXX) # hip-config.cmake requires CXX enabled
set(CMAKE_Fortran_FORMAT FREE)
set(CMAKE_Fortran_PREPROCESS ON)

SET(CMAKE_BUILD_TYPE ${HIPFORT_BUILD_TYPE})
SET(VERSION ${HIPFORT_VERSION})
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")
SET(CMAKE_AR ${HIPFORT_AR})
SET(CMAKE_RANLIB ${HIPFORT_RANLIB})
SET(CMAKE_INSTALL_PREFIX ${HIPFORT_INSTALL_DIR})
message("-- CMAKE_INSTALL_PREFIX:${CMAKE_INSTALL_PREFIX}")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")

INCLUDE(FortranCInterface)
FortranCInterface_VERIFY()
Expand All @@ -60,7 +29,8 @@ ENDIF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)
# Test for Fortran 08 support by using an f08-specific construct.
IF(NOT DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F08)
MESSAGE(CHECK_START "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 08")
FILE(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF08.f90 "
INCLUDE(CheckFortranSourceCompiles)
CHECK_FORTRAN_SOURCE_COMPILES("
module mod
interface foo
module procedure :: foo_a,foo_b
Expand All @@ -84,10 +54,7 @@ IF(NOT DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F08)
allocate(b,mold=a)
deallocate(b)
END PROGRAM TESTFortran08
")
TRY_COMPILE(CMAKE_Fortran_COMPILER_SUPPORTS_F08 ${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF08.f90
OUTPUT_VARIABLE OUTPUT)
" CMAKE_Fortran_COMPILER_SUPPORTS_F08)
IF(CMAKE_Fortran_COMPILER_SUPPORTS_F08)
MESSAGE(CHECK_PASS "yes")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
Expand All @@ -104,22 +71,12 @@ IF(NOT DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F08)
unset(CMAKE_Fortran_COMPILER_SUPPORTS_F08 CACHE)
ENDIF(NOT DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F08)

#OPTION(USE_MPI "Use the MPI library for parallelization" OFF)
#OPTION(USE_OPENMP "Use OpenMP for parallelization" OFF)

IF(CMAKE_Fortran_COMPILER_ID MATCHES "(Cray|LLVMFlang)")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${HIPFORT_COMPILER_FLAGS}")
ELSE(CMAKE_Fortran_COMPILER_ID MATCHES "(Cray|LLVMFlang)")
IF(CMAKE_Fortran_COMPILER_SUPPORTS_F08)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${HIPFORT_COMPILER_FLAGS} -std=f2008")
ELSE(CMAKE_Fortran_COMPILER_SUPPORTS_F08)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${HIPFORT_COMPILER_FLAGS} -std=f2003")
ENDIF(CMAKE_Fortran_COMPILER_SUPPORTS_F08)
ENDIF(CMAKE_Fortran_COMPILER_ID MATCHES "(Cray|LLVMFlang)")

# Set compile flags for DEBUG, # RELEASE, or TESTING.
INCLUDE(${CMAKE_MODULE_PATH}/SetFortranFlags.cmake)
message("-- Done setting FortranFlags")
message("-- CMAKE_Fortran_FLAGS_DEBUG: ${CMAKE_Fortran_FLAGS_DEBUG}")
message("-- CMAKE_Fortran_FLAGS_RELEASE: ${CMAKE_Fortran_FLAGS_RELEASE}")
message("-- CMAKE_Fortran_FLAGS_TESTING: ${CMAKE_Fortran_FLAGS_TESTING}")

# There is an error in CMAKE with this flag for pgf90. Unset it
GET_FILENAME_COMPONENT(FCNAME ${CMAKE_Fortran_COMPILER} NAME)
Expand All @@ -139,7 +96,6 @@ INCLUDE(${CMAKE_MODULE_PATH}/rocm-cmake.cmake)
rocm_setup_version(VERSION ${VERSION})
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/lib)
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/test)
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/bin)

set(CPACK_DEBIAN_PACKAGE_DEPENDS "hip-runtime-amd (>= 4.5.0)")
set(CPACK_RPM_PACKAGE_REQUIRES "hip-runtime-amd >= 4.5.0")
Expand Down
15 changes: 1 addition & 14 deletions cmake/Modules/SetFortranFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ ENDIF(CMAKE_Fortran_FLAGS_RELEASE AND CMAKE_Fortran_FLAGS_TESTING AND CMAKE_Fort

IF(NOT CMAKE_Fortran_COMPILER_ID MATCHES "Cray")

# Don't add underscores in symbols for C-compatability
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}"
Fortran "-fno-underscoring")

option(BUILD_NATIVE "Enable optimizations that make the binaries non-portable" OFF)
if(BUILD_NATIVE)
# There is some bug where -march=native doesn't work on Mac
Expand All @@ -82,12 +78,6 @@ ENDIF(NOT CMAKE_Fortran_COMPILER_ID MATCHES "Cray")

# NOTE: debugging symbols (-g or /debug:full) are already on by default

# Disable optimizations
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}"
Fortran REQUIRED "-O0" # All compilers not on Windows
"/Od" # Intel Windows
)

# Turn on all warnings
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}"
Fortran "-warn all" # Intel
Expand Down Expand Up @@ -122,10 +112,7 @@ SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG}"
#####################

# Optimizations
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_TESTING "${CMAKE_Fortran_FLAGS_TESTING}"
Fortran REQUIRED "-O2" # All compilers not on Windows
"/O2" # Intel Windows
)
SET(CMAKE_Fortran_FLAGS_TESTING "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO}")

#####################
### RELEASE FLAGS ###
Expand Down
4 changes: 2 additions & 2 deletions cmake/Modules/rocm-cmake.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Find or download/install rocm-cmake project
find_package(ROCM QUIET CONFIG PATHS /opt/rocm)
find_package(ROCmCMakeBuildTools QUIET CONFIG PATHS /opt/rocm)
if(NOT ROCM_FOUND)
set(rocm_cmake_tag "master" CACHE STRING "rocm-cmake tag to download")
file(
Expand All @@ -24,7 +24,7 @@ if(NOT ROCM_FOUND)
if(rocm_cmake_unpack_error_code)
message(FATAL_ERROR "Error: unpacking ${CMAKE_CURRENT_BINARY_DIR}/rocm-cmake-${rocm_cmake_tag}.zip failed")
endif()
find_package(ROCM REQUIRED CONFIG PATHS ${CMAKE_CURRENT_BINARY_DIR}/rocm-cmake-${rocm_cmake_tag})
find_package(ROCmCMakeBuildTools REQUIRED CONFIG PATHS ${CMAKE_CURRENT_BINARY_DIR}/rocm-cmake-${rocm_cmake_tag})
endif()

include(ROCMSetupVersion)
Expand Down
3 changes: 0 additions & 3 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

IF(NOT CMAKE_Fortran_COMPILER_ID MATCHES "Cray")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-underscoring")
ENDIF(NOT CMAKE_Fortran_COMPILER_ID MATCHES "Cray")
file(GLOB HIPFORT_SRC_HIP "${CMAKE_CURRENT_SOURCE_DIR}/hipfort/*.f*")
#file(GLOB HIPFORT_SRC_amdgcn "${CMAKE_CURRENT_SOURCE_DIR}/modules-amdgcn/*.f*")
#file(GLOB HIPFORT_SRC_nvptx "${CMAKE_CURRENT_SOURCE_DIR}/modules-nvptx/*.f*")
Expand Down