-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
110 lines (94 loc) · 6.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
# This file is used to generate a makefile for the project.
#
# Author: Jabir Ali Ouassou <[email protected]>
# Created: 2015-07-12
# Updated: 2016-03-02
###############################################################################
# PROJECT DEFINITION
###############################################################################
# General metadata
project(GENEUS Fortran)
cmake_minimum_required(VERSION 2.6)
# Programming languages
enable_language(Fortran)
# Source files
file(GLOB src_e77 RELATIVE ${CMAKE_SOURCE_DIR} "src/external/bvp_la.f")
file(GLOB src_e90 RELATIVE ${CMAKE_SOURCE_DIR} "src/external/bvp_m.f" "src/external/pchip.f" "src/external/fparser.f")
file(GLOB src_mod RELATIVE ${CMAKE_SOURCE_DIR} "src/system/*.f" "src/foundation/*.f" "src/materials/*.f")
file(GLOB src_exe RELATIVE ${CMAKE_SOURCE_DIR} "src/programs/*.f")
# Libraries
add_library(geneus STATIC ${src_mod} ${src_e90} ${src_e77})
# Executables
foreach(src_name ${src_exe})
get_filename_component( exe_name ${src_name} NAME_WE )
add_executable( ${exe_name} ${src_name} )
target_link_libraries( ${exe_name} geneus )
endforeach()
###############################################################################
# COMPILATION SETTINGS
###############################################################################
# Set the target directory
set(EXECUTABLE_OUTPUT_PATH "../bin/")
# Set the build type
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Using default build type: 'Release'.")
set(CMAKE_BUILD_TYPE Release)
else()
message(STATUS "Using custom build type: '" ${CMAKE_BUILD_TYPE} "'.")
endif()
# Check which compiler we use
get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
if(Fortran_COMPILER_NAME MATCHES "gfortran.*" AND CMAKE_SYSTEM_NAME MATCHES "Windows")
# Cross-compiling with GNU GFORTRAN for WINDOWS
set(CMAKE_Fortran_FLAGS "-flto -Ofast -fno-stack-arrays -s")
set(CMAKE_EXE_LINKER_FLAGS "-flto -Ofast -fwhole-program -static")
set_source_files_properties(${src_e77} PROPERTIES COMPILE_FLAGS "-std=legacy -ffixed-form")
set_source_files_properties(${src_e90} PROPERTIES COMPILE_FLAGS "-std=legacy -ffree-form")
set_source_files_properties(${src_mod} PROPERTIES COMPILE_FLAGS "-std=f2008 -ffree-form -fimplicit-none -Wconversion")
set_source_files_properties(${src_exe} PROPERTIES COMPILE_FLAGS "-std=f2008 -ffree-form -fimplicit-none -Wconversion")
elseif(Fortran_COMPILER_NAME MATCHES "gfortran.*" AND CMAKE_BUILD_TYPE MATCHES "Release")
# Compiling with GNU GFORTRAN in RELEASE mode
set(CMAKE_AR "gcc-ar")
SET(CMAKE_Fortran_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_Fortran_ARCHIVE_FINISH true)
set(CMAKE_Fortran_FLAGS "-march=native -flto -Ofast -fno-stack-arrays -s")
set(CMAKE_EXE_LINKER_FLAGS "-march=native -flto -Ofast -fwhole-program -static")
set_source_files_properties(${src_e77} PROPERTIES COMPILE_FLAGS "-std=legacy -ffixed-form")
set_source_files_properties(${src_e90} PROPERTIES COMPILE_FLAGS "-std=legacy -ffree-form")
set_source_files_properties(${src_mod} PROPERTIES COMPILE_FLAGS "-std=f2008 -ffree-form -fimplicit-none -Wconversion")
set_source_files_properties(${src_exe} PROPERTIES COMPILE_FLAGS "-std=f2008 -ffree-form -fimplicit-none -Wconversion")
elseif(Fortran_COMPILER_NAME MATCHES "gfortran.*" AND CMAKE_BUILD_TYPE MATCHES "Debug")
# Compiling with GNU GFORTRAN in DEBUG mode
set(CMAKE_AR "gcc-ar")
SET(CMAKE_Fortran_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_Fortran_ARCHIVE_FINISH true)
set(CMAKE_Fortran_FLAGS "-march=native -Og -g -pg -fbacktrace")
set(CMAKE_EXE_LINKER_FLAGS "-march=native -Og -fwhole-program -static")
set_source_files_properties(${src_e77} PROPERTIES COMPILE_FLAGS "-std=legacy -ffixed-form")
set_source_files_properties(${src_e90} PROPERTIES COMPILE_FLAGS "-std=legacy -ffree-form")
set_source_files_properties(${src_mod} PROPERTIES COMPILE_FLAGS "-std=f2008 -ffree-form -fimplicit-none -Wconversion -pedantic -fcheck=all")
set_source_files_properties(${src_exe} PROPERTIES COMPILE_FLAGS "-std=f2008 -ffree-form -fimplicit-none -Wconversion -pedantic -fcheck=all")
elseif(Fortran_COMPILER_NAME MATCHES "ifort.*" AND CMAKE_BUILD_TYPE MATCHES "Release")
# Compiling with INTEL IFORT in RELEASE mode
set(CMAKE_Fortran_FLAGS "-fast")
set(CMAKE_EXE_LINKER_FLAGS "-fast")
set_source_files_properties(${src_e77} PROPERTIES COMPILE_FLAGS "-stand none -fixed")
set_source_files_properties(${src_e90} PROPERTIES COMPILE_FLAGS "-stand none -free")
set_source_files_properties(${src_mod} PROPERTIES COMPILE_FLAGS "-stand f08 -free -warn declarations,interfaces,usage -diag-disable 5112,5268")
set_source_files_properties(${src_exe} PROPERTIES COMPILE_FLAGS "-stand f08 -free -warn declarations,interfaces,usage -diag-disable 5112,5268")
elseif(Fortran_COMPILER_NAME MATCHES "ifort.*" AND CMAKE_BUILD_TYPE MATCHES "Debug")
# Compiling with INTEL IFORT in DEBUG mode
set(CMAKE_Fortran_FLAGS "-xHost -g -traceback -ftrapuv")
set(CMAKE_EXE_LINKER_FLAGS "-xHost")
set_source_files_properties(${src_e77} PROPERTIES COMPILE_FLAGS "-stand none -fixed")
set_source_files_properties(${src_e90} PROPERTIES COMPILE_FLAGS "-stand none -free")
set_source_files_properties(${src_mod} PROPERTIES COMPILE_FLAGS "-stand f08 -free -warn declarations,interfaces,usage -check bounds,pointers,uninit,stack -diag-disable 5112,5268,10182")
set_source_files_properties(${src_exe} PROPERTIES COMPILE_FLAGS "-stand f08 -free -warn declarations,interfaces,usage -check bounds,pointers,uninit,stack -diag-disable 5112,5268,10182")
else()
# Compiling with an unknown compiler
message(WARNING "The only compilers that have been tested are GFortran and IFort...")
endif()
# Print the results
message(STATUS "Using Fortran compiler: " ${CMAKE_Fortran_COMPILER})
message(STATUS "Using Fortran flags: " ${CMAKE_Fortran_FLAGS})
message(STATUS "Using linker flags: " ${CMAKE_EXE_LINKER_FLAGS})