File: util_template.cmake

package info (click to toggle)
openmolcas 25.02-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 170,204 kB
  • sloc: f90: 498,088; fortran: 139,779; python: 13,587; ansic: 5,745; sh: 745; javascript: 660; pascal: 460; perl: 325; makefile: 17
file content (90 lines) | stat: -rw-r--r-- 3,535 bytes parent folder | download | duplicates (2)
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
#***********************************************************************
# This file is part of OpenMolcas.                                     *
#                                                                      *
# OpenMolcas is free software; you can redistribute it and/or modify   *
# it under the terms of the GNU Lesser General Public License, v. 2.1. *
# OpenMolcas is distributed in the hope that it will be useful, but it *
# is provided "as is" and without any express or implied warranties.   *
# For more details see the full text of the license in the file        *
# LICENSE or in <http://www.gnu.org/licenses/>.                        *
#                                                                      *
# Copyright (C) 2020, Ignacio Fdez. Galván                             *
#***********************************************************************

# Template for building an OpenMolcas utility library,
# that will be part of libmolcas
# * Creates:
#   - An object library ${prog} with all sources
#     (except those that define Fortran modules)
# * Supports:
#   - ${util}_defs with utility-specific compile definitions
#   - ${util}_incs with utility-specific include directories
#   - ${util}_deps with utility-specific dependencies
# * Defines:
#   - ${util}_src with the path for the source directory
#   - ${util}_sources with all the non-module source files
#   - ${util}_mods with all the module source files

get_filename_component (util ${CMAKE_CURRENT_SOURCE_DIR} NAME)

if (DEFINED sources)
  set_absolute_paths (sources ${CMAKE_CURRENT_SOURCE_DIR} ${sources})
else ()
  file (GLOB sources *.f *.f90 *.F *.F90 *.c)
endif ()

# Ignore an empty directory
if (NOT sources)
  return ()
endif ()

# Find source files that define Fortran modules.
# These must be moved to another target to ensure
# that they are compiled first.
# If modfile_list is predefined, it may contain
# only the module sources that need to be available
# to other directories.
#--------------------------------------------------
if (DEFINED modfile_list)
  set_absolute_paths (modfile_list ${CMAKE_CURRENT_SOURCE_DIR} ${modfile_list})
else ()
  foreach (fname ${sources})
    file (READ ${fname} contents)
    if ("${contents}" MATCHES "\n *[mM][oO][dD][uU][lL][eE] ")
      list (APPEND modfile_list ${fname})
    endif ()
  endforeach ()
endif ()
foreach (fname ${modfile_list})
  list (REMOVE_ITEM sources ${fname})
endforeach ()

# Create an object library
#-------------------------
add_Molcas_library (${util}_obj OBJECT ${sources})

# dependencies
if (DEFINED ${util}_deps)
  add_dependencies(${util}_obj ${${util}_deps})
endif()
# utility-specific compile definitions
if (DEFINED ${util}_defs)
  target_compile_definitions (${util}_obj PRIVATE "${${util}_defs}")
endif ()
# utility-specific include directories
list (APPEND ${util}_incs ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories (${util}_obj PRIVATE "${${util}_incs}")
# add a dummy source if there are none left,
# (CMake does not like empty targets)
if (NOT sources)
  set (dummy_file ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${util}/dummy.f90)
  if (NOT EXISTS ${dummy_file})
    file (WRITE ${dummy_file} "subroutine empty_dummy() ; end subroutine")
  endif ()
  target_sources (${util}_obj PRIVATE ${dummy_file})
endif ()

# Info for the main project
set (${util}_src     ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
set (${util}_sources ${sources}                  PARENT_SCOPE)
set (${util}_mods    ${modfile_list}             PARENT_SCOPE)