Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a96471

Browse files
authored
Merge pull request #29 from zerothi/cmake
Cmake addition
2 parents 14f9104 + 52ebd7c commit 6a96471

15 files changed

Lines changed: 512 additions & 10 deletions

CMakeLists.txt

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
2+
3+
# Include overwrites before setting up the project
4+
set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_SOURCE_DIR}/config/DefaultFlags.cmake)
5+
6+
# Define fdict project and languages used
7+
project(fdict
8+
LANGUAGES Fortran
9+
DESCRIPTION "Fortran dictionary for arbitrary data-types"
10+
)
11+
12+
13+
# Define project versions
14+
file(STRINGS "${PROJECT_SOURCE_DIR}/VERSION" PROJECT_VERSION)
15+
16+
# Listify the string
17+
string(REPLACE "." ";" VERSION_LIST ${PROJECT_VERSION})
18+
list(GET VERSION_LIST 0 PROJECT_VERSION_MAJOR)
19+
list(GET VERSION_LIST 1 PROJECT_VERSION_MINOR)
20+
list(GET VERSION_LIST 2 PROJECT_VERSION_PATCH)
21+
unset(VERSION_LIST)
22+
23+
24+
# Define library specific content
25+
set(PROJECT_AUTHOR "Nick Papior")
26+
set(PROJECT_DESCRIPTION "Fortran dictionary for arbitrary data-types")
27+
set(PROJECT_URL "https://github.com/zerothi/fdict")
28+
set(PROJECT_LICENSE "Mozilla Public License, 2.0 (MPL-2.0)")
29+
message("** PROJECT_NAME = ${PROJECT_NAME}")
30+
message("** Please report any build problems here: ${PROJECT_URL}")
31+
32+
33+
# Define the module temporary location
34+
#set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/modules/)
35+
36+
list(APPEND FYPPFLAGS
37+
"-DPROJECT_NAME=\\\"${PROJECT_NAME}\\\""
38+
"-DPROJECT_VERSION=\\\"${PROJECT_VERSION}\\\""
39+
"-DPROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}"
40+
"-DPROJECT_VERSION_MINOR=${PROJECT_VERSION_MINOR}"
41+
"-DPROJECT_VERSION_PATCH=${PROJECT_VERSION_PATCH}"
42+
)
43+
44+
45+
# Add our custom definitions
46+
add_subdirectory(config)
47+
48+
# Define the allocatable array sizes
49+
set(F_ARRAY ":")
50+
foreach(IR RANGE 2 ${CMAKE_MAXIMUM_RANK})
51+
list(APPEND F_ARRAY ":")
52+
endforeach()
53+
string(REPLACE ";" "," F_ARRAY "${F_ARRAY}")
54+
55+
# Once we have the sizes of the settings defined, we will add a check that the compiler will actually handle this.
56+
check_fortran_source_compiles("real, allocatable :: array(${F_ARRAY}); end" fmaximum_rank SRC_EXT f90)
57+
unset(F_ARRAY)
58+
check_fortran_source_runs("use, intrinsic :: iso_fortran_env, only : real128; real(real128) :: x; x = x+1; end" f03real128)
59+
60+
foreach(V IN ITEMS fmaximum_rank f03real128)
61+
if(NOT ${${V}})
62+
message(FATAL_ERROR "Could not succesfully test compiler capability: ${V}")
63+
endif()
64+
endforeach()
65+
66+
67+
add_subdirectory(src)
68+
69+
70+
install(EXPORT ${PROJECT_NAME}-targets
71+
NAMESPACE ${PROJECT_NAME}::
72+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
73+
)

Makefile.project

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ _SMEKA_project = 1
33
# Contains specific default information for this project
44

55
# Step this version upon new versions
6-
PROJECT_MAJOR = 0
7-
PROJECT_MINOR = 9
8-
PROJECT_PATCH = 0
9-
PROJECT_VERSION = $(PROJECT_MAJOR).$(PROJECT_MINOR).$(PROJECT_PATCH)
6+
PROJECT_VERSION_MAJOR = 0
7+
PROJECT_VERSION_MINOR = 9
8+
PROJECT_VERSION_PATCH = 0
9+
PROJECT_VERSION = $(PROJECT_VERSION_MAJOR).$(PROJECT_VERSION_MINOR).$(PROJECT_VERSION_PATCH)
1010

1111
# These are constant default
1212
PROJECT_NAME = fdict
@@ -16,9 +16,9 @@ FDICT_LIB ?= fdict$(LIB_SUFFIX)
1616
FDICT_LIB_STATIC ?= lib$(FDICT_LIB).a
1717
FDICT_LIB_SHARED ?= lib$(FDICT_LIB).so
1818

19-
FYPPFLAGS += -DPROJECT_MAJOR=$(PROJECT_MAJOR)
20-
FYPPFLAGS += -DPROJECT_MINOR=$(PROJECT_MINOR)
21-
FYPPFLAGS += -DPROJECT_PATCH=$(PROJECT_PATCH)
19+
FYPPFLAGS += -DPROJECT_VERSION_MAJOR=$(PROJECT_VERSION_MAJOR)
20+
FYPPFLAGS += -DPROJECT_VERSION_MINOR=$(PROJECT_VERSION_MINOR)
21+
FYPPFLAGS += -DPROJECT_VERSION_PATCH=$(PROJECT_VERSION_PATCH)
2222

2323
# Define custom options for fdict
2424
STATIC ?= 1

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ To enable the non-default data types you can do so with (Makefile scheme):
130130
FYPPFLAGS += -DWITH_LOG64=1 # for logical kind(18)
131131
FYPPFLAGS += -DWITH_ISO_C=1 # for enabling c_ptr and c_funptr
132132

133+
For `cmake` the same arguments can be made.
134+
133135
By default `fdict` generates the kind specifications from the `selected_*_kind` routines,
134136
however, if one wishes to use the `iso_fortran_env` module simply add `FYPPFLAGS += -DWITH_ISO_ENV`.
135137

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.9.0

config/CMakeLists.txt

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Ensure we use some basic packages
2+
3+
# Project installation follows GNU installation directory convention
4+
include(GNUInstallDirs)
5+
6+
include(ProjectOptions.cmake)
7+
8+
# --- compiler feature checks
9+
include(CheckFortranSourceCompiles)
10+
include(CheckFortranSourceRuns)
11+
12+
set(CMAKE_INSTALL_CMAKECONFIG_DIR
13+
"${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
14+
)
15+
16+
17+
# Export a pkg-config file
18+
configure_file(
19+
"${PROJECT_SOURCE_DIR}/fdict.pc.in"
20+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
21+
@ONLY
22+
)
23+
24+
# Install pkg-config files
25+
install(
26+
FILES
27+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
28+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
29+
)
30+
31+
# Export CMake package file
32+
include(CMakePackageConfigHelpers)
33+
34+
# Export a cmake package configure file
35+
configure_package_config_file(
36+
"${CMAKE_CURRENT_SOURCE_DIR}/template.cmake"
37+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
38+
INSTALL_DESTINATION "${CMAKE_INSTALL_CMAKECONFIG_DIR}"
39+
)
40+
41+
if(BUILD_SHARED_LIBS OR PROJECT_VERSION_MAJOR EQUAL 0)
42+
# Due to the uncertain ABI compatibility of Fortran shared libraries
43+
# limit compatibility for dynamic linking to same minor version.
44+
set(COMPATIBILITY SameMinorVersion)
45+
else()
46+
# Require API compatibility via semantic versioning for static linking.
47+
set(COMPATIBILITY SameMajorVersion)
48+
endif()
49+
50+
# Export a package version file
51+
write_basic_package_version_file(
52+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
53+
VERSION "${PROJECT_VERSION}"
54+
COMPATIBILITY ${COMPATIBILITY}
55+
)
56+
57+
# Install cmake configuration files
58+
install(
59+
FILES
60+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
61+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
62+
DESTINATION "${CMAKE_INSTALL_CMAKECONFIG_DIR}"
63+
)
64+
65+
66+
# Preprocesses a list of files with given preprocessor and preprocessor options
67+
#
68+
# Args:
69+
# preproc [in]: Preprocessor program
70+
# preprocopts [in]: Preprocessor options
71+
# srcext [in]: File extension of the source files
72+
# trgext [in]: File extension of the target files
73+
# srcfiles [in]: List of the source files
74+
# trgfiles [out]: Contains the list of the preprocessed files on exit
75+
#
76+
function(preprocess preproc preprocopts srcext trgext srcfiles trgfiles)
77+
78+
set(_trgfiles)
79+
foreach(srcfile IN LISTS srcfiles)
80+
string(REGEX REPLACE "\\.${srcext}$" ".${trgext}" trgfile ${srcfile})
81+
add_custom_command(
82+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${trgfile}
83+
COMMAND ${preproc} ${preprocopts} ${CMAKE_CURRENT_SOURCE_DIR}/${srcfile} ${CMAKE_CURRENT_BINARY_DIR}/${trgfile}
84+
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${srcfile})
85+
list(APPEND _trgfiles ${CMAKE_CURRENT_BINARY_DIR}/${trgfile})
86+
endforeach()
87+
set(${trgfiles} ${_trgfiles} PARENT_SCOPE)
88+
89+
endfunction()
90+
91+
# Define a function for fyppifying sources
92+
function(fyppify)
93+
# Parse arguments
94+
set(options "")
95+
set(oneValueArgs FYPP EXTIN EXTOUT COMMENT OUTPUT)
96+
set(multiValueArgs FLAGS FILES)
97+
cmake_parse_arguments(
98+
_fyppify "${options}" "${oneValueArgs}" "${multiValueArgs}"
99+
${ARGN}
100+
)
101+
102+
# Now handle arguments
103+
#[==[
104+
message(INFO "Before parsing inputs:
105+
comment=${_fyppify_COMMENT}
106+
fypp=${_fyppify_FYPP}
107+
EXTIN=${_fyppify_EXTIN}
108+
EXTOUT=${_fyppify_EXTOUT}
109+
FLAGS=${_fyppify_FLAGS}
110+
FILES=${_fyppify_FILES}
111+
")
112+
]==]
113+
114+
if(NOT DEFINED _fyppify_FYPP)
115+
set(_fyppify_FYPP ${FYPP})
116+
endif()
117+
if(NOT DEFINED _fyppify_EXTIN)
118+
set(_fyppify_EXTIN "fypp")
119+
endif()
120+
if(NOT DEFINED _fyppify_EXTOUT)
121+
set(_fyppify_EXTOUT "f90")
122+
endif()
123+
if(DEFINED _fyppify_COMMENT)
124+
message(VERBOSE "-- Setting up fyppify: ${_fyppify_COMMENT}")
125+
endif()
126+
if(NOT DEFINED _fyppify_FLAGS)
127+
set(_fyppify_FLAGS "")
128+
endif()
129+
if(NOT DEFINED _fyppify_FILES)
130+
message(FATAL_ERROR "fyppify requires FILES arguments to determine which files to preprocess")
131+
endif()
132+
133+
#[==[
134+
message(INFO "After parsing inputs:
135+
comment=${_fyppify_COMMENT}
136+
fypp=${_fyppify_FYPP}
137+
EXTIN=${_fyppify_EXTIN}
138+
EXTOUT=${_fyppify_EXTOUT}
139+
FLAGS=${_fyppify_FLAGS}
140+
FILES=${_fyppify_FILES}
141+
")
142+
]==]
143+
144+
# Lets do the preprocessing
145+
preprocess("${_fyppify_FYPP}" "${_fyppify_FLAGS}"
146+
"${_fyppify_EXTIN}" "${_fyppify_EXTOUT}"
147+
"${_fyppify_FILES}" _outfiles)
148+
if(DEFINED _fyppify_OUTPUT)
149+
set(${_fyppify_OUTPUT} ${_outfiles} PARENT_SCOPE)
150+
endif()
151+
152+
endfunction()

config/DefaultFlags.cmake

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
2+
# GNU compiler gfortran
3+
set(
4+
CMAKE_Fortran_FLAGS_INIT
5+
"-fimplicit-none"
6+
)
7+
set(
8+
CMAKE_Fortran_FLAGS_RELEASE_INIT
9+
)
10+
set(
11+
CMAKE_Fortran_FLAGS_DEBUG_INIT
12+
"-Wall"
13+
"-Wextra"
14+
"-Wimplicit-procedure"
15+
)
16+
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
17+
# Intel compiler ifort
18+
set(
19+
CMAKE_Fortran_FLAGS_INIT
20+
)
21+
set(
22+
CMAKE_Fortran_FLAGS_RELEASE_INIT
23+
)
24+
set(
25+
CMAKE_Fortran_FLAGS_DEBUG_INIT
26+
"-warn declarations,general,usage,interfaces,unused"
27+
)
28+
else()
29+
# unknown compiler (possibly)
30+
set(
31+
CMAKE_Fortran_FLAGS_INIT
32+
)
33+
set(
34+
CMAKE_Fortran_FLAGS_RELEASE_INIT
35+
)
36+
set(
37+
CMAKE_Fortran_FLAGS_DEBUG_INIT
38+
)
39+
endif()
40+
string(REPLACE ";" " " CMAKE_Fortran_FLAGS_INIT "${CMAKE_Fortran_FLAGS_INIT}")
41+
string(REPLACE ";" " " CMAKE_Fortran_FLAGS_RELEASE_INIT "${CMAKE_Fortran_FLAGS_RELEASE_INIT}")
42+
string(REPLACE ";" " " CMAKE_Fortran_FLAGS_DEBUG_INIT "${CMAKE_Fortran_FLAGS_DEBUG_INIT}")

config/ProjectOptions.cmake

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Here we define all options that are related to fdict
2+
3+
# Ensure we have the program fypp installed
4+
find_program(FYPP fypp)
5+
if(NOT FYPP)
6+
message(FATAL_ERROR "Could not find executable fypp -- it is required for the pre-processing step")
7+
endif()
8+
9+
# We need to define certain variables before the initial configuration of this project
10+
if(NOT DEFINED CMAKE_MAXIMUM_RANK)
11+
set(CMAKE_MAXIMUM_RANK 5 CACHE STRING "Maximum array rank for generated procedures")
12+
endif()
13+
14+
# Whether we should use the iso_fortran_env for data-types
15+
message(CHECK_START "Requested use of intrinsic fortran module (iso_fortran_env) for data-types")
16+
if(DEFINED "WITH_ISO_ENV}")
17+
message(CHECK_PASS "used")
18+
list(APPEND FYPPFLAGS "-DWITH_ISO_ENV=$<BOOL:${WITH_ISO_ENV}>")
19+
else()
20+
message(CHECK_FAIL "not used")
21+
endif()
22+
23+
24+
# Parse data-type options
25+
message(CHECK_START "Checking for data-type interfaces")
26+
list(APPEND CMAKE_MESSAGE_INDENT " ")
27+
foreach(var INT8 INT16 REAL80 REAL128 LOG8 LOG16 LOG64 ISO_C)
28+
message(CHECK_START "data-type ${var}")
29+
if(DEFINED "WITH_${var}")
30+
message(CHECK_PASS "added")
31+
list(APPEND FYPPFLAGS "-DWITH_${var}=$<BOOL:${WITH_${var}}>")
32+
else()
33+
message(CHECK_FAIL "not added")
34+
endif()
35+
endforeach()
36+
list(POP_BACK CMAKE_MESSAGE_INDENT)
37+
message(CHECK_PASS "done")
38+
39+
# Global maxrank
40+
message(CHECK_START "Checking for data-type rank size interfaces")
41+
list(APPEND CMAKE_MESSAGE_INDENT " ")
42+
message(CHECK_START "default rank size")
43+
if(DEFINED "MAXRANK")
44+
message(CHECK_PASS "found size = ${MAXRANK}")
45+
list(APPEND FYPPFLAGS "-DMAXRANK=${MAXRANK}")
46+
else()
47+
set(MAXRANK 5)
48+
message(CHECK_FAIL "using default size = ${MAXRANK}")
49+
endif()
50+
51+
# Parse rank sizes
52+
foreach(var INT REAL CMPLX LOG ISO_C)
53+
message(CHECK_START "rank size of ${var}")
54+
if(DEFINED "MAXRANK_${var}")
55+
message(CHECK_PASS "found size = ${MAXRANK_${var}}")
56+
list(APPEND FYPPFLAGS "-DMAXRANK_${var}=${MAXRANK_${var}}")
57+
else()
58+
message(CHECK_FAIL "using default size = ${MAXRANK}")
59+
endif()
60+
endforeach()
61+
list(POP_BACK CMAKE_MESSAGE_INDENT)
62+
message(CHECK_PASS "done")

config/README

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
These configuration files are highly inspired from the
2+
github.com/fortran-lang/stdlib project.
3+
4+
I acknowledge and thank them for their continued support to
5+
the Fortran community!

0 commit comments

Comments
 (0)