Project

General

Profile

Download (6.51 KB) Statistics
| Branch: | Tag: | Revision:
1
# @configure_input@
2
#
3
# - Find Lustre compiler
4
# Find the Lustre synchronous language compiler with associated includes path.
5
# See https://cavale.enseeiht.fr/redmine/projects/lustrec
6
# This module defines
7
#  LUSTRE_COMPILER, the lustre compiler
8
#  LUSTRE_COMPILER_VERSION, the version of the lustre compiler
9
#  LUSTRE_INCLUDE_DIR, where to find dword.h, etc.
10
#  LUSTRE_FOUND, If false, Lustre was not found.
11
# On can set LUSTRE_PATH_HINT before using find_package(Lustre) and the
12
# module with use the PATH as a hint to find lustrec.
13
#
14
# The hint can be given on the command line too:
15
#   cmake -DLUSTRE_PATH_HINT=/DATA/ERIC/Lustre/lustre-x.y /path/to/source
16
#
17
# The module defines some functions:
18
#   Lustre_Compile([NODE <Lustre Main Node>]
19
#                  LUS_FILES <Lustre files>
20
#                  [USER_C_FILES <C files>]
21
#                  [VERBOSE <level>]
22
#                  [LUSI]
23
#                  LIBNAME <libraryName>)
24
#
25
# When used the Lustre_Compile macro define the variable
26
# LUSTRE_GENERATED_C_FILES_<libraryName> in the parent scope
27
# so that the caller can get (if needed) the list of Lustre generated files.
28
# The VERBOSE level is a numeric value passed directly to the -verbose
29
# command line option of the lustre compiler
30
#
31
include("@prefix@/share/helpful_functions.cmake")
32

    
33
if(LUSTRE_PATH_HINT)
34
  message(STATUS "FindLustre: using PATH HINT: ${LUSTRE_PATH_HINT}")
35
else()
36
  set(LUSTRE_PATH_HINT)
37
endif()
38

    
39
#One can add his/her own builtin PATH.
40
#FILE(TO_CMAKE_PATH "/DATA/ERIC/Lustre/lustre-x.y" MYPATH)
41
#list(APPEND LUSTRE_PATH_HINT ${MYPATH})
42

    
43
# FIND_PROGRAM twice using NO_DEFAULT_PATH on first shot
44
find_program(LUSTRE_COMPILER
45
  NAMES lustrec
46
  PATHS ${LUSTRE_PATH_HINT}
47
  PATH_SUFFIXES bin
48
  NO_DEFAULT_PATH
49
  DOC "Path to the Lustre compiler command 'lustrec'")
50

    
51
find_program(LUSTRE_COMPILER
52
  NAMES lustrec
53
  PATHS ${LUSTRE_PATH_HINT}
54
  PATH_SUFFIXES bin
55
  DOC "Path to the Lustre compiler command 'lustrec'")
56

    
57
if(LUSTRE_COMPILER)
58
    # get the path where the lustre compiler was found
59
    get_filename_component(LUSTRE_PATH ${LUSTRE_COMPILER} PATH)
60
    # remove bin
61
    get_filename_component(LUSTRE_PATH ${LUSTRE_PATH} PATH)
62
    # add path to LUSTRE_PATH_HINT
63
    list(APPEND LUSTRE_PATH_HINT ${LUSTRE_PATH})
64
    execute_process(COMMAND ${LUSTRE_COMPILER} -version
65
        OUTPUT_VARIABLE LUSTRE_COMPILER_VERSION
66
        OUTPUT_STRIP_TRAILING_WHITESPACE)
67
    message(STATUS "Lustre compiler version is : ${LUSTRE_COMPILER_VERSION}")
68
endif(LUSTRE_COMPILER)
69

    
70
find_path(LUSTRE_INCLUDE_DIR
71
          NAMES arrow.h
72
          PATHS ${LUSTRE_PATH_HINT}
73
          PATH_SUFFIXES include/lustrec
74
          DOC "The Lustre include headers")
75

    
76
# Macros used to compile a lustre library
77
include(CMakeParseArguments)
78
function(Lustre_Compile)
79
  set(options LUSI)
80
  set(oneValueArgs NODE LIBNAME VERBOSE)
81
  set(multiValueArgs LUS_FILES USER_C_FILES)
82
  cmake_parse_arguments(LUS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
83

    
84
  if(LUS_LUSI)
85
    set(LUSTRE_LUSI_OPT "-lusi")
86
  endif()
87

    
88
  if (NOT LUS_LIBNAME)
89
    message(FATAL_ERROR "You should specify LIBNAME for each Lustre_Compile call.")
90
  endif()
91

    
92
  if(LUS_NODE)
93
    set(LUSTRE_NODE_OPT "-node;${LUS_NODE}")
94
    set(LUSTRE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/lus_${LUS_LIBNAME}/${LUS_NODE}")
95
  else()
96
    set(LUSTRE_NODE_OPT "")
97
    set(LUSTRE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/lus_${LUS_LIBNAME}")
98
  endif()
99

    
100
  if (LUS_VERBOSE)
101
    set(LUSTRE_VERBOSE_OPT "-verbose;${LUS_VERBOSE}")
102
  else()
103
    # the default is to be quiet.
104
    set(LUSTRE_VERBOSE_OPT "-verbose;0")
105
  endif()
106

    
107
  file(MAKE_DIRECTORY ${LUSTRE_OUTPUT_DIR})
108
  set(GLOBAL_LUSTRE_GENERATED_C_FILES "")
109
  set(GLOBAL_LUSTRE_DEP_C_FILES "")
110
  # create list of generated C files in parent scope
111
  set(LUSTRE_GENERATED_C_FILES_${LUS_LIBNAME} "" PARENT_SCOPE)
112
  foreach(LFILE IN LISTS LUS_LUS_FILES)
113
    get_lustre_name_ext(${LFILE} L E)
114
    
115
    if ("${E}" STREQUAL "lus")
116
      set(LUSTRE_GENERATED_FILES ${LUSTRE_OUTPUT_DIR}/${L}.h ${LUSTRE_OUTPUT_DIR}/${L}.c ${LUSTRE_OUTPUT_DIR}/${L}_alloc.h)
117
      set(LUSTRE_DEP_FILES "")
118
      if(LUS_NODE)
119
         list(APPEND LUSTRE_GENERATED_FILES ${LUSTRE_OUTPUT_DIR}/${L}_main.c)
120
         list(APPEND LUSTRE_DEP_FILES ${LUSTRE_INCLUDE_DIR}/io_frontend.c)
121
      endif()
122
    elseif("${E}" STREQUAL "lusi")
123
      set(LUSTRE_GENERATED_FILES ${LUSTRE_OUTPUT_DIR}/${L}.h)
124
    endif()
125
    list(APPEND GLOBAL_LUSTRE_GENERATED_C_FILES ${LUSTRE_GENERATED_FILES})
126
    list(APPEND GLOBAL_LUSTRE_DEP_FILES ${LUSTRE_DEP_FILES}) # todo: add if not already in the list
127
    set(LUSTRE_GENERATED_FILES ${LUSTRE_GENERATED_FILES} ${LUSTRE_OUTPUT_DIR}/${L}.lusic)
128
    if (LUS_LUSI)
129
      add_custom_command(
130
         OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${LFILE}i
131
         COMMAND ${LUSTRE_COMPILER} ${LUSTRE_LUSI_OPT} ${LFILE}
132
         DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${LFILE}
133
         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
134
         COMMENT "Compile Lustre source(s): ${LFILE} with option -lusi."
135
         )
136
      message(STATUS "lustrec will produce lusi file: ${LFILE}i")
137
    endif()
138
    add_custom_command(
139
      OUTPUT ${LUSTRE_GENERATED_FILES}
140
      COMMAND ${LUSTRE_COMPILER} ${LUSTRE_VERBOSE_OPT} ${LUSTRE_NODE_OPT} -d ${LUSTRE_OUTPUT_DIR} ${LFILE}
141
      DEPENDS ${LFILE}
142
      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
143
      COMMENT "Compile Lustre source(s): ${LFILE} (generates: ${LUSTRE_GENERATED_FILES})."
144
      )
145
    set_source_files_properties(${LUSTRE_GENERATED_FILES} PROPERTIES GENERATED TRUE)
146
  endforeach()
147

    
148
  include_directories(${LUSTRE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${LUSTRE_OUTPUT_DIR})
149
  if(LUS_NODE)
150
  add_executable(${LUS_LIBNAME}
151
              ${GLOBAL_LUSTRE_GENERATED_C_FILES} ${GLOBAL_LUSTRE_DEP_FILES} ${LUS_USER_C_FILES}
152
              )
153
  else()
154
  add_library(${LUS_LIBNAME} SHARED
155
              ${GLOBAL_LUSTRE_GENERATED_C_FILES} ${GLOBAL_LUSTRE_DEP_FILES} ${LUS_USER_C_FILES}
156
              )
157
  endif()
158
  set_target_properties(${LUS_LIBNAME} PROPERTIES COMPILE_FLAGS "-std=c99")
159
  set(LUSTRE_GENERATED_C_FILES_${LUS_LIBNAME} "${GLOBAL_LUSTRE_GENERATED_C_FILES}" PARENT_SCOPE)
160
  message(STATUS "Lustre: Added rule for building lustre library: ${LUS_LIBNAME}")
161
endfunction(Lustre_Compile)
162

    
163
# handle the QUIETLY and REQUIRED arguments and set LUSTRE_FOUND to TRUE if
164
# all listed variables are TRUE
165
include(FindPackageHandleStandardArgs)
166
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LUSTRE
167
                                  REQUIRED_VARS LUSTRE_COMPILER LUSTRE_INCLUDE_DIR)
168
# VERSION FPHSA options not handled by CMake version < 2.8.2)
169
#                                  VERSION_VAR LUSTRE_COMPILER_VERSION)
170
mark_as_advanced(LUSTRE_INCLUDE_DIR)
(1-1/2)