-
Notifications
You must be signed in to change notification settings - Fork 43
/
CMakeLists.txt
199 lines (174 loc) · 8.92 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# This file is part of gtk-fortran, a GTK / Fortran interface library.
# Copyright (C) 2011 The gtk-fortran team
#
# This is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Under Section 7 of GPL version 3, you are granted additional
# permissions described in the GCC Runtime Library Exception, version
# 3.1, as published by the Free Software Foundation.
#
# You should have received a copy of the GNU General Public License along with
# this program; see the files LICENSE and LICENSE_EXCEPTION respectively.
# If not, see <https://www.gnu.org/licenses/>.
#===============================================================================
# Contributed by Kyle Horne: 05.11.2011
# Last modifications: James Tappin 8/17/2012, Jens Hunger 01/07/2018,
# vmagnin 2022-04-06
#
# CMAKE build file for gtk-fortran
# Options:
# -D CMAKE_BUILD_TYPE=debug
# -D EXCLUDE_PLPLOT=true
# -D NO_BUILD_EXAMPLES=true
# -D NO_BUILD_HL=true
# -D INSTALL_EXAMPLES=true
cmake_minimum_required(VERSION 3.7)
# Include overwrites before setting up the project
set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DefaultFlags.cmake)
project(gtk-fortran Fortran)
set(CMAKE_PROJECT_DESCRIPTION "A GTK / Fortran binding")
set(CMAKE_PROJECT_HOMEPAGE_URL "https://github.com/vmagnin/gtk-fortran/wiki/")
#===============================================================================
# Version of gtk-fortran for the current branch (from VERSIONS file):
#===============================================================================
file(STRINGS VERSIONS OneLine REGEX "gtk-fortran;(.*)")
string(REGEX REPLACE "gtk-fortran;" "" SEMANTIC_VERSION ${OneLine})
# Major, minor and patch versions of gtk-fortran:
string(REGEX MATCH "[0-9]+" GTKv ${SEMANTIC_VERSION})
string(REGEX REPLACE "[0-9]+\.([0-9]+)\.[0-9]+" "\\1" MINOR_VERSION ${SEMANTIC_VERSION})
string(REGEX REPLACE "[0-9]+\.[0-9]+\.([0-9]+)" "\\1" PATCH_VERSION ${SEMANTIC_VERSION})
set(gtk_V_fortran "gtk-${GTKv}-fortran")
message(STATUS "Building ${gtk_V_fortran} ${SEMANTIC_VERSION}")
if (${GTKv} LESS_EQUAL 3)
set(GTKname "gtk+-${GTKv}.0")
else()
set(GTKname "gtk${GTKv}")
endif()
set(CMAKE_PROJECT_VERSION_MAJOR ${GTKv})
set(CMAKE_PROJECT_VERSION_MINOR ${MINOR_VERSION})
set(CMAKE_PROJECT_VERSION_PATCH ${PATCH_VERSION})
# Extracting the GTK and GLib versions from the VERSIONS file:
file(STRINGS VERSIONS OneLine REGEX "GTK;(.*)")
string(REGEX REPLACE "GTK;" "" GTK_SEMANTIC_VERSION ${OneLine})
file(STRINGS VERSIONS OneLine REGEX "GLib;(.*)")
string(REGEX REPLACE "GLib;" "" GLIB_SEMANTIC_VERSION ${OneLine})
message(STATUS "Based on GTK ${GTK_SEMANTIC_VERSION} and GLib ${GLIB_SEMANTIC_VERSION}")
#===============================================================================
# Define GNU standard installation directories:
#===============================================================================
include(GNUInstallDirs)
message(STATUS "GNUInstallDirs: ${CMAKE_INSTALL_PREFIX} ${CMAKE_INSTALL_LIBDIR} ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_BINDIR} ${CMAKE_INSTALL_DATAROOTDIR} ${CMAKE_INSTALL_MANDIR}")
#===============================================================================
# Default build type is release
# Uncomment this to debug or use "cmake -D CMAKE_BUILD_TYPE=debug .."
#===============================================================================
# set(CMAKE_BUILD_TYPE debug)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE release)
endif()
#===============================================================================
# Setting compilation flags for various compilers and build types:
#===============================================================================
# Print system, compiler CMake ID, version and path:
message(STATUS "System: ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION} ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "Compiler: ${CMAKE_Fortran_COMPILER_ID} ${CMAKE_Fortran_COMPILER_VERSION} ${CMAKE_Fortran_COMPILER}")
message(STATUS "Build type is: ${CMAKE_BUILD_TYPE}")
# Print compilation flags :
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
if(CMAKE_Fortran_FLAGS OR CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE})
message(STATUS "Compilation flags: ${CMAKE_Fortran_FLAGS} ${CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE}}")
endif()
#===============================================================================
# Package generation:
#===============================================================================
set(CPACK_PACKAGE_CHECKSUM SHA256)
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.md")
set(CPACK_GENERATOR "TGZ")
set(CPACK_SOURCE_GENERATOR "TGZ")
include(CPack)
#===============================================================================
# "Path for CMake modules to be loaded by the include() or find_package()
# commands before checking the default modules that come with CMake"
#===============================================================================
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
#===============================================================================
# Uninstall target:
# Generic code adapted from
# https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
#===============================================================================
if(NOT TARGET uninstall)
# configure_file() copies a file and substitutes @VAR@ or ${VAR}
# @ONLY means only @VAR@ will be sustituted
# https://cmake.org/cmake/help/latest/command/configure_file.html
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
@ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
#===============================================================================
# Examples can be tested via make test:
#===============================================================================
enable_testing()
#===============================================================================
# Find all GTK libraries:
#===============================================================================
# Use PkgConfig:
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK REQUIRED ${GTKname})
# Setup CMake to use GTK, tell the compiler where to look for headers
# and to the linker where to look for libraries:
include_directories(${GTK_INCLUDE_DIRS})
link_directories(${GTK_LIBRARY_DIRS})
# Add other flags to the compiler:
add_definitions(${GTK_CFLAGS_OTHER})
#===============================================================================
# PLplot integration (>=5.13 needed)
# ----------------------------------
# A lot of changes have occured in PLplot 5.11, 5.12 and 5.13: the libraries
# have been renamed (plplot and plplot-fortran) and the ISO_C_BINDING has been
# adopted.
# By now (March 2019), the find_package(plplot) command gives a lot of errors
# in Debian/Ubuntu distributions because of some renaming in Debian packages.
# As a temporary (?) workaround, we are now using pkg-config.
# If a CMake error occurs, add -D EXCLUDE_PLPLOT=true to your CMake command.
#===============================================================================
if (NOT EXCLUDE_PLPLOT AND NOT NO_BUILD_HL)
pkg_check_modules(PLPLOT-FORTRAN REQUIRED plplot-fortran)
pkg_check_modules(PLPLOT REQUIRED plplot)
# Setup CMake to use PLplot, tell the compiler where to look for headers
# and to the linker where to look for libraries:
include_directories(${PLPLOT-FORTRAN_INCLUDE_DIRS})
link_directories(${PLPLOT-FORTRAN_LIBRARY_DIRS})
# Add other flags to the compiler:
add_definitions(${PLPLOT-FORTRAN_CFLAGS_OTHER})
set(LIBRARIES ${LIBRARIES} ${PLPLOT_LIBRARIES})
include_directories(${PLPLOT_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES "${PLPLOT_LIBRARIES}")
set(CMAKE_REQUIRED_INCLUDES "${PLPLOT-FORTRAN_INCLUDE_DIRS}")
else(NOT EXCLUDE_PLPLOT AND NOT NO_BUILD_HL)
message(STATUS ">>> PLPLOT excluded as command option")
endif(NOT EXCLUDE_PLPLOT AND NOT NO_BUILD_HL)
#===============================================================================
# Add subdirectories to build:
#===============================================================================
add_subdirectory(src)
add_subdirectory(examples)
if(NOT NO_BUILD_HL)
add_subdirectory(sketcher)
if(PLPLOT_FOUND AND NOT EXCLUDE_PLPLOT)
add_subdirectory(plplot)
endif(PLPLOT_FOUND AND NOT EXCLUDE_PLPLOT)
else(NOT NO_BUILD_HL)
message(STATUS ">>> High Level API excluded as command option")
endif(NOT NO_BUILD_HL)