xref: /phasta/CMakeLists.txt (revision dc37f0bc1247e555caa37d503e8cbcbfb273ecfc)
1CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5)
2#SET(CMAKE_FORTRAN_COMPILER gfortran gfortran)
3PROJECT(PHASTA Fortran C CXX )
4enable_language(Fortran)
5enable_language(C)
6enable_language(CXX)
7
8#The following commit fixes an issue with imported targets and gfortran
9#https://gitlab.kitware.com/cmake/cmake/commit/a8e7a1047ad3b61238f073ea3d2cd138f207c1ed
10if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.3.0)
11  #if the cmake version is too old then set the magic flag to use -I instead of
12  # -isystem for imported targets - we are importing a fortran module from
13  # SCOREC/core for phasta io timers
14  unset(CMAKE_INCLUDE_SYSTEM_FLAG_Fortran)
15endif()
16
17enable_testing()
18include(CTest)
19set(MPIRUN "mpirun"
20  CACHE STRING
21  "the mpirun or srun executable")
22set(MPIRUN_PROCFLAG "-np"
23  CACHE STRING
24  "the command line flag to give process count to MPIRUN")
25
26list(APPEND CMAKE_MODULE_PATH ${PHASTA_SOURCE_DIR}/CMakeFiles)
27
28#Handle Fortran name mangling
29include(FortranCInterface)
30FortranCInterface_VERIFY(CXX)
31FortranCInterface_Header(FCMangle.h SYMBOLS write_restart write_error write_displ write_field write_hessian)
32include_directories("${PHASTA_BINARY_DIR}")
33
34# Force static linking
35IF(CMAKE_SYSTEM_NAME MATCHES BlueGeneQ-static)
36  SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
37ENDIF(CMAKE_SYSTEM_NAME MATCHES BlueGeneQ-static)
38
39#MESSAGE(ERROR ${CMAKE_Fortran_SOURCE_FILE_EXTENSIONS})
40#SET(CMAKE_Fortran_SOURCE_FILE_EXTENSIONS f90 f F90 F)
41# stuff for C/C++ calls to Fortran -- still needs to be done properly...
42IF(CMAKE_Fortran_COMPILER_ID MATCHES GNU)
43  SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffixed-form -ffixed-line-length-132 -cpp " )
44	IF(CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER 9.5.0)
45		#This feature was introduced in gfortran 10
46		#the last public release prior was 9.5 and
47		#version_greater_equal was introduced recently so we implement
48		#for compatibility.
49		SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch")
50	ENDIF(CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER 9.5.0)
51ENDIF(CMAKE_Fortran_COMPILER_ID MATCHES GNU)
52
53IF(CMAKE_Fortran_COMPILER_ID MATCHES Intel)
54
55SET(CMAKE_Fortran_FLAGS "-W0 -132 -fixed -fpp ${CMAKE_Fortran_FLAGS}" )
56if((CMAKE_BUILD_TYPE MATCHES "Release") OR
57	(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo"))
58	set(CMAKE_Fortran_FLAGS "-O3 -ip ${CMAKE_Fortran_FLAGS}" )
59endif()
60message(STATUS "Found ifort")
61message(STATUS ${CMAKE_Fortran_FLAGS})
62ENDIF(CMAKE_Fortran_COMPILER_ID MATCHES Intel)
63
64if(CMAKE_Fortran_COMPILER_ID MATCHES PGI)
65	set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Mextend")
66endif(CMAKE_Fortran_COMPILER_ID MATCHES PGI)
67
68if(CMAKE_Fortran_COMPILER_ID MATCHES XL)
69	#set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qstrict -qnullterm -qfixed=132")
70	set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qnullterm -qfixed=132")
71endif(CMAKE_Fortran_COMPILER_ID MATCHES XL)
72
73IF(${CMAKE_BUILD_TYPE} MATCHES "Debug" )
74  ADD_DEFINITIONS( -DDEBUG )
75ENDIF(${CMAKE_BUILD_TYPE} MATCHES "Debug" )
76
77# set archos "like" options for things like c calling fortran bindings
78# later on we may want to do it dependent on behavior (e.g.
79# C_FORTRAN_CALL == uppercase, underline, nochange)
80#OPTION(ARCHOS_OPTION "ArchOS dependent defines (e.g. -DLINUX)" )
81SET(ARCHOS_OPTION "-DLINUX" CACHE STRING "ArchOS dependent defines (e.g. -DLINUX)" )
82ADD_DEFINITIONS( ${ARCHOS_OPTION} )
83
84
85SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
86  ${PHASTA_BINARY_DIR}/lib)
87
88SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY
89  ${PHASTA_BINARY_DIR}/bin)
90
91OPTION(PHASTA_USE_MPI "Build MPI components" ON)
92IF(PHASTA_USE_MPI)
93  ADD_DEFINITIONS( -DPARALLEL -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX )
94  option(PHASTA_SKIP_MPI_CHECK "Bypass CMake MPI code. Don't use this" OFF)
95  mark_as_advanced(FORCE PHASTA_SKIP_MPI_CHECK)
96  if(NOT PHASTA_SKIP_MPI_CHECK)
97  FIND_PACKAGE(MPI REQUIRED)
98  endif()
99#  SET(CMAKE_MODULE_PATH ${PHASTA_SOURCE_DIR}/CMakeFiles)
100  # bug in FIND_PACKAGE for Threads -- ignore for now (bug has been reported)...
101  FIND_PACKAGE(Threads)
102  IF(Threads_FOUND)
103    INCLUDE(FindThreads)
104  ENDIF(Threads_FOUND)
105ENDIF(PHASTA_USE_MPI)
106
107if(PHASTA_CHEF_ENABLED)
108  message(STATUS "PHASTA_CHEF_ENABLED SCOREC_PREFIX ${SCOREC_PREFIX}")
109  find_package(SCOREC 2.1.0 REQUIRED CONFIG
110    PATHS ${SCOREC_PREFIX} NO_DEFAULT_PATH)
111endif(PHASTA_CHEF_ENABLED)
112
113OPTION(PHASTA_BUILD_PHASTAIO "Build PhastaIO" ON)
114if(PHASTA_BUILD_PHASTAIO)
115	add_subdirectory(phastaIO)
116	list(APPEND PHASTA_INCLUDES "${PHASTA_SOURCE_DIR}/phastaIO")
117        if(NOT PHASTA_CHEF_ENABLED)
118	  list(APPEND PHASTA_INCLUDES
119            "${PHASTA_SOURCE_DIR}/phastaIO/phiotimer_empty")
120        endif(NOT PHASTA_CHEF_ENABLED)
121endif(PHASTA_BUILD_PHASTAIO)
122
123OPTION(PHASTA_BUILD_SHAPEFUNCTION "Build shapeFunction" ON)
124if(PHASTA_BUILD_SHAPEFUNCTION)
125	list(APPEND PHASTA_INCLUDES "${PHASTA_SOURCE_DIR}/shapeFunction/src")
126	add_subdirectory(shapeFunction)
127endif(PHASTA_BUILD_SHAPEFUNCTION)
128
129if(EXISTS ${PHASTA_SOURCE_DIR}/phShape)
130OPTION(PHASTA_BUILD_PHSHAPE "Build phShape" OFF)
131if(PHASTA_BUILD_PHSHAPE)
132	list(APPEND PHASTA_INCLUDES "${PHASTA_SOURCE_DIR}/phShape/src")
133	add_subdirectory(phShape)
134endif(PHASTA_BUILD_PHSHAPE)
135endif(EXISTS ${PHASTA_SOURCE_DIR}/phShape)
136
137OPTION(PHASTA_USE_SVLS "Build svLS Linear Solver" OFF)
138if(PHASTA_USE_SVLS)
139	message(WARNING "\
140svLS has a non-commercial license. \n \
141by activating PHASTA_USE_SVLS in cmake \n \
142you agree to the terms outlined in \
143svLS/license.txt"
144	)
145	list(APPEND PHASTA_INCLUDES "${PHASTA_SOURCE_DIR}/svLS")
146	add_subdirectory(svLS)
147endif(PHASTA_USE_SVLS)
148
149OPTION(PHASTA_BUILD_SOLVERS "Build Solvers" ON)
150if(PHASTA_BUILD_SOLVERS)
151	set(PHASTA_BUILD_PHASTAIO ON)
152	if(PHASTA_USE_MPI)
153		set(PHASTA_BUILD_METIS ON)
154	endif(PHASTA_USE_MPI)
155	list(APPEND PHASTA_INCLUDES "${PHASTA_SOURCE_DIR}/phSolver/common")
156	include_directories(${PHASTA_INCLUDES})
157	add_subdirectory(phSolver)
158        add_subdirectory(checkphasta)
159#TODO
160endif(PHASTA_BUILD_SOLVERS)
161
162OPTION(PHASTA_BUILD_CONVERTERIO "Build IO converter" ON)
163if(PHASTA_BUILD_CONVERTERIO)
164	add_subdirectory(converterIO)
165endif(PHASTA_BUILD_CONVERTERIO)
166
167OPTION(PHASTA_BUILD_ACUSTAT "Build AcuStat" ON)
168if(PHASTA_BUILD_ACUSTAT)
169	add_subdirectory(AcuStat)
170endif(PHASTA_BUILD_ACUSTAT)
171
172OPTION(PHASTA_BUILD_M2N "Build M2N" ON)
173if(PHASTA_BUILD_M2N)
174	add_subdirectory(M2N)
175endif(PHASTA_BUILD_M2N)
176
177OPTION(PHASTA_BUILD_M2NFixBnd "Build M2NFixBnd" ON)
178if(PHASTA_BUILD_M2NFixBnd)
179	add_subdirectory(M2NFixBnd)
180endif(PHASTA_BUILD_M2NFixBnd)
181
182if(EXISTS ${PHASTA_SOURCE_DIR}/phNSpre)
183	add_subdirectory(phNSpre)
184endif(EXISTS ${PHASTA_SOURCE_DIR}/phNSpre)
185
186