-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathCMakeLists.txt
114 lines (99 loc) · 3.76 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
cmake_minimum_required(VERSION 3.1)
project(
bezier
VERSION 2020.2.3
LANGUAGES Fortran C)
set(AUTHOR "Danny Hermes")
set(AUTHOR_DETAILS "[email protected]")
set(DESCRIPTION "Library for Bezier curves and triangles.")
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(TARGET_NATIVE_ARCH "Optimize build for host (native) architecture" ON)
if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU|Intel)$")
message(FATAL_ERROR "gfortran and ifort are the only supported compilers")
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
if(WIN32 AND CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static")
if(NOT CMAKE_IMPORT_LIBRARY_SUFFIX_Fortran)
set(CMAKE_IMPORT_LIBRARY_SUFFIX_Fortran ".lib")
endif()
if(NOT CMAKE_IMPORT_LIBRARY_PREFIX_Fortran)
set(CMAKE_IMPORT_LIBRARY_PREFIX_Fortran "")
endif()
if(NOT CMAKE_SHARED_LIBRARY_PREFIX_Fortran)
set(CMAKE_SHARED_LIBRARY_PREFIX_Fortran "")
endif()
endif()
if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release)$")
message(FATAL_ERROR "Debug and Release are the only supported build types")
endif()
# Unset all Fortran flags (instead rely on our flags).
set(OLD_CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS})
set(OLD_CMAKE_Fortran_FLAGS_DEBUG ${CMAKE_Fortran_FLAGS_DEBUG})
set(OLD_CMAKE_Fortran_FLAGS_RELEASE ${CMAKE_Fortran_FLAGS_RELEASE})
set(CMAKE_Fortran_FLAGS "")
set(CMAKE_Fortran_FLAGS_DEBUG "")
set(CMAKE_Fortran_FLAGS_RELEASE "")
add_subdirectory(quadpack)
file(GLOB SOURCES *.f90)
add_library(bezier ${SOURCES} $<TARGET_OBJECTS:quadpack>)
unset(SOURCES)
if(${BUILD_SHARED_LIBS})
set_target_properties(
bezier
PROPERTIES VERSION ${bezier_VERSION} SOVERSION 2020
POSITION_INDEPENDENT_CODE ON)
endif()
target_include_directories(bezier PUBLIC $<INSTALL_INTERFACE:include>)
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
# ``-Wextra`` includes ``no-compare-reals``, but we have comparisons like
# ``value == 0.0_dp``.
target_compile_options(
bezier
PRIVATE -fno-second-underscore
-Wall
-Wextra
-Wno-compare-reals
-Wimplicit-interface
-fmax-errors=1
-std=f2008)
if(CMAKE_BUILD_TYPE MATCHES "^Debug$")
target_compile_options(bezier PRIVATE -fcheck=all -fbacktrace
-fimplicit-none -pedantic)
target_compile_options(bezier PUBLIC -g)
elseif(CMAKE_BUILD_TYPE MATCHES "^Release$")
target_compile_options(bezier PRIVATE -Werror)
if(${TARGET_NATIVE_ARCH})
target_compile_options(bezier PRIVATE -march=native)
endif()
target_compile_options(bezier PUBLIC -DNDEBUG -O3 -funroll-loops)
endif()
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
target_compile_options(quadpack PUBLIC -warn all)
if(CMAKE_BUILD_TYPE MATCHES "^Debug$")
target_compile_options(quadpack PUBLIC -check all)
elseif(CMAKE_BUILD_TYPE MATCHES "^Release$")
target_compile_options(quadpack PUBLIC -fast)
endif()
else()
message(FATAL_ERROR "gfortran and ifort are the only supported compilers")
endif()
include(GNUInstallDirs)
install(
TARGETS bezier
EXPORT BezierConfig
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT BezierConfig DESTINATION share/bezier/cmake)
export(TARGETS bezier FILE BezierConfig.cmake)
# Restore all Fortran flags.
set(CMAKE_Fortran_FLAGS ${OLD_CMAKE_Fortran_FLAGS})
set(CMAKE_Fortran_FLAGS_DEBUG ${OLD_CMAKE_Fortran_FLAGS_DEBUG})
set(CMAKE_Fortran_FLAGS_RELEASE ${OLD_CMAKE_Fortran_FLAGS_RELEASE})
unset(OLD_CMAKE_Fortran_FLAGS)
unset(OLD_CMAKE_Fortran_FLAGS_DEBUG)
unset(OLD_CMAKE_Fortran_FLAGS_RELEASE)