Project

General

Profile

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

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

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

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

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

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

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

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

    
82
  if(LUS_LUSI)
83
    set(LUSTRE_LUSI_OPT "-lusi")
84
  endif()
85

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

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

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

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

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

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