This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
153 lines (134 loc) · 6.25 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
# Master CMAKE Build Script
cmake_minimum_required(VERSION 3.7)
project(curvefit C CXX Fortran)
# Define version information
set(CURVEFIT_MAJOR_VERSION 1)
set(CURVEFIT_MINOR_VERSION 1)
set(CURVEFIT_PATCH_VERSION 0)
set(CURVEFIT_VERSION ${CURVEFIT_MAJOR_VERSION}.${CURVEFIT_MINOR_VERSION}.${CURVEFIT_PATCH_VERSION})
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif()
# By default, shared library
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
# Locate Dependencies
find_package(ferror 1.3.0)
find_package(linalg 1.5.0)
find_package(nonlin 1.3.0)
# Define dependency directories
set(NONLIN_DIRECTORY ${PROJECT_SOURCE_DIR}/src/external/nonlin)
set(LINALG_DIRECTORY ${NONLIN_DIRECTORY}/src/external/linalg)
set(FERROR_DIRECTORY ${LINALG_DIRECTORY}/src/external/ferror)
# If FERROR is not installed on the system, build the default implementation
if (${ferror_FOUND})
message(STATUS "An acceptable version of FERROR (v" ${ferror_VERSION} ") was found, and will be utilized.")
set(FERROR_LIBRARIES ferror)
get_target_property(ferror_LibLocation ferror LOCATION)
endif()
# If LINALG is not installed on the system, build the default implementation
if (${linalg_FOUND})
message(STATUS "An acceptable version of LINALG (v" ${linalg_VERSION} ") was found, and will be utilized.")
set(LINALG_LIBRARIES linalg)
get_target_property(linalg_LibLocation linalg LOCATION)
endif()
# If NONLIN is not installed on the system, build the default implementation
if (${nonlin_FOUND})
message(STATUS "An acceptable version of NONLIN (v" ${nonlin_VERSION} ") was found, and will be utilized.")
set(NONLIN_LIBRARIES nonlin)
get_target_property(nonlin_LibLocation nonlin LOCATION)
else()
message(STATUS "NONLIN not found. The default implementation will be used.")
add_subdirectory(${NONLIN_DIRECTORY})
set(nonlin_INCLUDE_DIRS ${NONLIN_DIRECTORY}/include)
set(NONLIN_LIBRARIES nonlin)
set(nonlin_LibLocation ${nonlin_BINARY_DIR})
include_directories(${LINALG_DIRECTORY}/include)
include_directories(${FERROR_DIRECTORY}/include)
endif()
# Include the dependency module files
include_directories(${nonlin_INCLUDE_DIRS} ${linalg_INCLUDE_DIRS} ${ferror_INCLUDE_DIRS})
# Export all symbols on Windows when building shared libraries
SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
# Locate the module files
set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_SOURCE_DIR}/include)
# Define output directories, if undefined
if (NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
message(STATUS "CURVEFIT library output directories undefined. Using default directories.")
if (CMAKE_BUILD_TYPE MATCHES Debug)
# Debug Build
if (BUILD_SHARED_LIBS)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Debug)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Debug)
else()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Debug)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Debug)
endif ()
elseif (CMAKE_BUILD_TYPE MATCHES Release)
# Release Build
if (BUILD_SHARED_LIBS)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Release)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Release)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Release)
else()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Release)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Release)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Release)
endif ()
else ()
# Default Condition
if (BUILD_SHARED_LIBS)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Debug)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Debug)
else()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Debug)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Debug)
endif ()
endif ()
endif ()
# FFLAGS depend on the compiler
get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
if (Fortran_COMPILER_NAME MATCHES "gfortran.*")
# gfortran
set(CMAKE_Fortran_FLAGS_RELEASE "-funroll-all-loops -fno-f2c -O3")
set (CMAKE_Fortran_FLAGS_DEBUG "-fno-f2c -O0 -g -Wall -Wno-c-binding-type")
elseif (Fortran_COMPILER_NAME MATCHES "ifort.*")
# ifort (untested)
set (CMAKE_Fortran_FLAGS_RELEASE "-f77rtl -O3")
set (CMAKE_Fortran_FLAGS_DEBUG "-f77rtl -O0 -g")
else (Fortran_COMPILER_NAME MATCHES "gfortran.*")
message ("CMAKE_Fortran_COMPILER full path: " ${CMAKE_Fortran_COMPILER})
message ("Fortran compiler: " ${Fortran_COMPILER_NAME})
message ("No optimized Fortran compiler flags are known, we just try -O2...")
set (CMAKE_Fortran_FLAGS_RELEASE "-O2")
set (CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -Wall")
endif (Fortran_COMPILER_NAME MATCHES "gfortran.*")
# Locate the source directory
add_subdirectory(src)
# ------------------------------------------------------------------------------
# EXAMPLES
# ------------------------------------------------------------------------------
option(BUILD_CURVEFIT_EXAMPLES "Build CURVEFIT examples?" OFF)
if (BUILD_CURVEFIT_EXAMPLES)
# Inform the user we're building the examples
message(STATUS "Building CURVEFIT examples.")
# Build the examples
add_subdirectory(examples)
endif()
# ------------------------------------------------------------------------------
# TESTS
# ------------------------------------------------------------------------------
option(BUILD_CURVEFIT_TESTS "Build CURVEFIT tests?" OFF)
if (BUILD_CURVEFIT_TESTS)
# Inform the user we're building the tests
message(STATUS "Building CURVEFIT tests.")
# Build the tests
add_subdirectory(tests)
endif()