forked from ROCm/hipfort
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
170 lines (149 loc) · 7.06 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.2)
#Setting Default value for libdir
set(CMAKE_INSTALL_LIBDIR "lib" CACHE STRING "Library install directory")
#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.4-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("-- HIPFORT ----------------------------------------------")
set(CMAKE_Fortran_COMPILER_INIT ${HIPFORT_COMPILER})
PROJECT(hipfort Fortran C CXX) # hip-config.cmake requires CXX enabled
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}")
INCLUDE(FortranCInterface)
FortranCInterface_VERIFY()
IF(NOT FortranCInterface_VERIFIED_C)
MESSAGE(FATAL_ERROR "Fortran compiler must support C Interface")
ENDIF(NOT FortranCInterface_VERIFIED_C)
IF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)
MESSAGE(FATAL_ERROR "Fortran compiler does not support F90")
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 "
module mod
interface foo
module procedure :: foo_a,foo_b
end interface
contains
subroutine foo_a(a)
use iso_c_binding
integer,target,dimension(:) :: a
type(c_ptr) :: a_ptr
a_ptr = c_loc(a) ! gfortran < 4.9 fails here
end
subroutine foo_b(b)
integer,pointer,dimension(:,:) :: b
end
end
PROGRAM TESTFortran08
use mod
implicit none
integer :: a(5)
integer,allocatable :: b(:)
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)
IF(CMAKE_Fortran_COMPILER_SUPPORTS_F08)
MESSAGE(CHECK_PASS "yes")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Determining if the Fortran compiler supports Fortran 08 passed with "
"the following output:\n${OUTPUT}\n\n")
set(CMAKE_Fortran_COMPILER_SUPPORTS_F08 1)
ELSE(CMAKE_Fortran_COMPILER_SUPPORTS_F08)
MESSAGE(CHECK_FAIL "no")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if the Fortran compiler supports Fortran 08 failed with "
"the following output:\n${OUTPUT}\n\n")
set(CMAKE_Fortran_COMPILER_SUPPORTS_F08 0)
ENDIF(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")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${HIPFORT_COMPILER_FLAGS}")
ELSE(CMAKE_Fortran_COMPILER_ID MATCHES "Cray")
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")
# Set compile flags for DEBUG, # RELEASE, or TESTING.
INCLUDE(${CMAKE_MODULE_PATH}/SetFortranFlags.cmake)
message("-- Done setting FortranFlags")
# There is an error in CMAKE with this flag for pgf90. Unset it
GET_FILENAME_COMPONENT(FCNAME ${CMAKE_Fortran_COMPILER} NAME)
IF(FCNAME STREQUAL "pgf90")
UNSET(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
ENDIF(FCNAME STREQUAL "pgf90")
option(BUILD_TESTING "Build tests" OFF)
if(BUILD_TESTING)
enable_testing()
endif()
# Subdirectories and packaging
# NOTE: rocm-cmake must be be included before
# adding subdirectories.
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-rocclr (>= 3.5.0)")
set(CPACK_RPM_PACKAGE_REQUIRES "hip-rocclr >= 3.5.0")
# Package name changed from hipfort to hipfort-devel/dev
# Backward compatibility support for old package name
set(CPACK_DEBIAN_PACKAGE_PROVIDES "hipfort")
set(CPACK_DEBIAN_PACKAGE_REPLACES "hipfort")
set(CPACK_DEBIAN_PACKAGE_CONFLICTS "hipfort")
set(CPACK_RPM_PACKAGE_PROVIDES "hipfort")
set(CPACK_RPM_PACKAGE_OBSOLETES "hipfort")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
if(NOT CPACK_PACKAGING_INSTALL_PREFIX)
set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
endif()
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "\${CPACK_PACKAGING_INSTALL_PREFIX}")
# Prevent rpmbuild from stripping binaries, which caused issues on CentOS
set(CPACK_RPM_SPEC_INSTALL_POST "/bin/true")
rocm_create_package(
NAME hipfort
DESCRIPTION "Fortran Interface For GPU Kernel Libraries"
MAINTAINER "Hipfort maintainer <[email protected]>"
HEADER_ONLY # Enabled For generating Only -devel pkg.
)
message("-- HIPFORT ------------- cmake DONE --------------------")