xref: /phasta/CMakeLists.txt (revision 06d45c3e23cf9519431c2d5c7bbad33ddf2fbe7a)
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 " )
44ENDIF(CMAKE_Fortran_COMPILER_ID MATCHES GNU)
45
46IF(CMAKE_Fortran_COMPILER_ID MATCHES Intel)
47
48SET(CMAKE_Fortran_FLAGS "-W0 -132 -fixed -fpp ${CMAKE_Fortran_FLAGS}" )
49if((CMAKE_BUILD_TYPE MATCHES "Release") OR
50	(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo"))
51	set(CMAKE_Fortran_FLAGS "-O3 -ip ${CMAKE_Fortran_FLAGS}" )
52endif()
53message(STATUS "Found ifort")
54message(STATUS ${CMAKE_Fortran_FLAGS})
55ENDIF(CMAKE_Fortran_COMPILER_ID MATCHES Intel)
56
57if(CMAKE_Fortran_COMPILER_ID MATCHES PGI)
58	set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Mextend")
59endif(CMAKE_Fortran_COMPILER_ID MATCHES PGI)
60
61if(CMAKE_Fortran_COMPILER_ID MATCHES XL)
62	#set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qstrict -qnullterm -qfixed=132")
63	set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qnullterm -qfixed=132")
64endif(CMAKE_Fortran_COMPILER_ID MATCHES XL)
65
66IF(${CMAKE_BUILD_TYPE} MATCHES "Debug" )
67  ADD_DEFINITIONS( -DDEBUG )
68ENDIF(${CMAKE_BUILD_TYPE} MATCHES "Debug" )
69
70# set archos "like" options for things like c calling fortran bindings
71# later on we may want to do it dependent on behavior (e.g.
72# C_FORTRAN_CALL == uppercase, underline, nochange)
73#OPTION(ARCHOS_OPTION "ArchOS dependent defines (e.g. -DLINUX)" )
74SET(ARCHOS_OPTION "-DLINUX" CACHE STRING "ArchOS dependent defines (e.g. -DLINUX)" )
75ADD_DEFINITIONS( ${ARCHOS_OPTION} )
76
77
78SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
79  ${PHASTA_BINARY_DIR}/lib)
80
81SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY
82  ${PHASTA_BINARY_DIR}/bin)
83
84OPTION(PHASTA_USE_MPI "Build MPI components" ON)
85IF(PHASTA_USE_MPI)
86  ADD_DEFINITIONS( -DPARALLEL -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX )
87  option(PHASTA_SKIP_MPI_CHECK "Bypass CMake MPI code. Don't use this" OFF)
88  mark_as_advanced(FORCE PHASTA_SKIP_MPI_CHECK)
89  if(NOT PHASTA_SKIP_MPI_CHECK)
90  FIND_PACKAGE(MPI REQUIRED)
91  endif()
92#  SET(CMAKE_MODULE_PATH ${PHASTA_SOURCE_DIR}/CMakeFiles)
93  # bug in FIND_PACKAGE for Threads -- ignore for now (bug has been reported)...
94  FIND_PACKAGE(Threads)
95  IF(Threads_FOUND)
96    INCLUDE(FindThreads)
97  ENDIF(Threads_FOUND)
98ENDIF(PHASTA_USE_MPI)
99
100if(PHASTA_CHEF_ENABLED)
101  message(STATUS "PHASTA_CHEF_ENABLED SCOREC_PREFIX ${SCOREC_PREFIX}")
102  find_package(SCOREC 2.1.0 REQUIRED CONFIG
103    PATHS ${SCOREC_PREFIX} NO_DEFAULT_PATH)
104endif(PHASTA_CHEF_ENABLED)
105
106OPTION(PHASTA_BUILD_PHASTAIO "Build PhastaIO" ON)
107if(PHASTA_BUILD_PHASTAIO)
108	add_subdirectory(phastaIO)
109	list(APPEND PHASTA_INCLUDES "${PHASTA_SOURCE_DIR}/phastaIO")
110        if(NOT PHASTA_CHEF_ENABLED)
111	  list(APPEND PHASTA_INCLUDES
112            "${PHASTA_SOURCE_DIR}/phastaIO/phiotimer_empty")
113        endif(NOT PHASTA_CHEF_ENABLED)
114endif(PHASTA_BUILD_PHASTAIO)
115
116OPTION(PHASTA_BUILD_SHAPEFUNCTION "Build shapeFunction" ON)
117if(PHASTA_BUILD_SHAPEFUNCTION)
118	list(APPEND PHASTA_INCLUDES "${PHASTA_SOURCE_DIR}/shapeFunction/src")
119	add_subdirectory(shapeFunction)
120endif(PHASTA_BUILD_SHAPEFUNCTION)
121
122if(EXISTS ${PHASTA_SOURCE_DIR}/phShape)
123OPTION(PHASTA_BUILD_PHSHAPE "Build phShape" OFF)
124if(PHASTA_BUILD_PHSHAPE)
125	list(APPEND PHASTA_INCLUDES "${PHASTA_SOURCE_DIR}/phShape/src")
126	add_subdirectory(phShape)
127endif(PHASTA_BUILD_PHSHAPE)
128endif(EXISTS ${PHASTA_SOURCE_DIR}/phShape)
129
130OPTION(PHASTA_USE_SVLS "Build svLS Linear Solver" OFF)
131if(PHASTA_USE_SVLS)
132	message(WARNING "\
133svLS has a non-commercial license. \n \
134by activating PHASTA_USE_SVLS in cmake \n \
135you agree to the terms outlined in \
136svLS/license.txt"
137	)
138	list(APPEND PHASTA_INCLUDES "${PHASTA_SOURCE_DIR}/svLS")
139	add_subdirectory(svLS)
140endif(PHASTA_USE_SVLS)
141
142OPTION(PHASTA_BUILD_SOLVERS "Build Solvers" ON)
143if(PHASTA_BUILD_SOLVERS)
144	set(PHASTA_BUILD_PHASTAIO ON)
145	if(PHASTA_USE_MPI)
146		set(PHASTA_BUILD_METIS ON)
147	endif(PHASTA_USE_MPI)
148	list(APPEND PHASTA_INCLUDES "${PHASTA_SOURCE_DIR}/phSolver/common")
149	include_directories(${PHASTA_INCLUDES})
150	add_subdirectory(phSolver)
151        add_subdirectory(checkphasta)
152#TODO
153endif(PHASTA_BUILD_SOLVERS)
154
155OPTION(PHASTA_BUILD_CONVERTERIO "Build IO converter" ON)
156if(PHASTA_BUILD_CONVERTERIO)
157	add_subdirectory(converterIO)
158endif(PHASTA_BUILD_CONVERTERIO)
159
160OPTION(PHASTA_BUILD_ACUSTAT "Build AcuStat" ON)
161if(PHASTA_BUILD_ACUSTAT)
162	add_subdirectory(AcuStat)
163endif(PHASTA_BUILD_ACUSTAT)
164
165OPTION(PHASTA_BUILD_M2N "Build M2N" ON)
166if(PHASTA_BUILD_M2N)
167	add_subdirectory(M2N)
168endif(PHASTA_BUILD_M2N)
169
170OPTION(PHASTA_BUILD_M2NFixBnd "Build M2NFixBnd" ON)
171if(PHASTA_BUILD_M2NFixBnd)
172	add_subdirectory(M2NFixBnd)
173endif(PHASTA_BUILD_M2NFixBnd)
174
175if(EXISTS ${PHASTA_SOURCE_DIR}/phNSpre)
176	add_subdirectory(phNSpre)
177endif(EXISTS ${PHASTA_SOURCE_DIR}/phNSpre)
178
179