Project

General

Profile

Download (4.79 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
#
20

    
21
if(LUSTRE_PATH_HINT)
22
  message(STATUS "FindLustre: using PATH HINT: ${LUSTRE_PATH_HINT}")
23
else()
24
  set(LUSTRE_PATH_HINT)
25
endif()
26

    
27
#One can add his/her own builtin PATH.
28
#FILE(TO_CMAKE_PATH "/DATA/ERIC/Lustre/lustre-x.y" MYPATH)
29
#list(APPEND LUSTRE_PATH_HINT ${MYPATH})
30

    
31
# FIND_PROGRAM twice using NO_DEFAULT_PATH on first shot
32
find_program(LUSTRE_COMPILER
33
  NAMES lustrec
34
  PATHS ${LUSTRE_PATH_HINT}
35
  PATH_SUFFIXES bin
36
  NO_DEFAULT_PATH
37
  DOC "Path to the Lustre compiler command 'lustrec'")
38

    
39
find_program(LUSTRE_COMPILER
40
  NAMES lustrec
41
  PATHS ${LUSTRE_PATH_HINT}
42
  PATH_SUFFIXES bin
43
  DOC "Path to the Lustre compiler command 'lustrec'")
44

    
45
if(LUSTRE_COMPILER)
46
    # get the path where the lustre compiler was found
47
    get_filename_component(LUSTRE_PATH ${LUSTRE_COMPILER} PATH)
48
    # remove bin
49
    get_filename_component(LUSTRE_PATH ${LUSTRE_PATH} PATH)
50
    # add path to LUSTRE_PATH_HINT
51
    list(APPEND LUSTRE_PATH_HINT ${LUSTRE_PATH})
52
    execute_process(COMMAND ${LUSTRE_COMPILER} -version
53
        OUTPUT_VARIABLE LUSTRE_COMPILER_VERSION
54
        OUTPUT_STRIP_TRAILING_WHITESPACE)
55
    message(STATUS "Lustre compiler version is : ${LUSTRE_COMPILER_VERSION}")
56
endif(LUSTRE_COMPILER)
57

    
58
find_path(LUSTRE_INCLUDE_DIR
59
          NAMES arrow.h
60
          PATHS ${LUSTRE_PATH_HINT}
61
          PATH_SUFFIXES include/lustrec
62
          DOC "The Lustre include headers")
63

    
64
# Macros used to compile a lustre library
65
include(CMakeParseArguments)
66
function(Lustre_Compile)
67
  set(options "")
68
  set(oneValueArgs NODE LIBNAME)
69
  set(multiValueArgs LUS_FILES USER_C_FILES)
70
  cmake_parse_arguments(LUS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
71

    
72
  if (NOT LUS_LIBNAME)
73
    message(FATAL_ERROR "You should specify LIBNAME for each Lustre_Compile call.")
74
  endif()
75

    
76
  if(LUS_NODE)
77
    set(LUSTRE_NODE_OPT "-node ${LUS_NODE}")
78
    set(LUSTRE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/lus_${LUS_LIBNAME}/${LUS_NODE}")
79
  else()
80
    set(LUSTRE_NODE_OPT "")
81
    set(LUSTRE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/lus_${LUS_LIBNAME}")
82
  endif()
83

    
84
  file(MAKE_DIRECTORY ${LUSTRE_OUTPUT_DIR})
85
  set(GLOBAL_LUSTRE_GENERATED_C_FILES "")
86
  # create list of generated C files in parent scope
87
  set(LUSTRE_GENERATED_C_FILES_${LUS_LIBNAME} "" PARENT_SCOPE)
88
  foreach(LFILE IN LISTS LUS_LUS_FILES)
89
    get_filename_component(L ${LFILE} NAME_WE)
90
    get_filename_component(E ${LFILE} EXT)
91
    if ("${E}" STREQUAL ".lus")
92
      set(LUSTRE_GENERATED_FILES ${LUSTRE_OUTPUT_DIR}/${L}.h ${LUSTRE_OUTPUT_DIR}/${L}.c ${LUSTRE_OUTPUT_DIR}/${L}_alloc.h)
93
    elseif("${E}" STREQUAL ".lusi")
94
      set(LUSTRE_GENERATED_FILES ${LUSTRE_OUTPUT_DIR}/${L}.h)
95
    endif()
96
    list(APPEND GLOBAL_LUSTRE_GENERATED_C_FILES ${LUSTRE_GENERATED_FILES})
97
    set(LUSTRE_GENERATED_FILES ${LUSTRE_GENERATED_FILES} ${LUSTRE_OUTPUT_DIR}/${L}.lusic)
98
    add_custom_command(
99
      OUTPUT ${LUSTRE_GENERATED_FILES}
100
      COMMAND ${LUSTRE_COMPILER} ${LUSTRE_NODE_OPT} -d ${LUSTRE_OUTPUT_DIR} ${LFILE}
101
      DEPENDS ${LFILE}
102
      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
103
      COMMENT "Compile Lustre source(s): ${LFILE} (generates: ${LUSTRE_GENERATED_FILES})."
104
      )
105
    set_source_files_properties(${LUSTRE_GENERATED_FILES} PROPERTIES GENERATED TRUE)
106
  endforeach()
107

    
108
  include_directories(${LUSTRE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${LUSTRE_OUTPUT_DIR})
109
  add_library(${LUS_LIBNAME} SHARED
110
              ${GLOBAL_LUSTRE_GENERATED_C_FILES} ${LUS_USER_C_FILES}
111
              )
112
  set(LUSTRE_GENERATED_C_FILES_${LUS_LIBNAME} "${GLOBAL_LUSTRE_GENERATED_C_FILES}" PARENT_SCOPE)
113
  message(STATUS "Lustre: Added rule for building lustre library: ${LUS_LIBNAME}")
114
endfunction(Lustre_Compile)
115

    
116
# handle the QUIETLY and REQUIRED arguments and set LUSTRE_FOUND to TRUE if
117
# all listed variables are TRUE
118
include(FindPackageHandleStandardArgs)
119
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LUSTRE
120
                                  REQUIRED_VARS LUSTRE_COMPILER LUSTRE_INCLUDE_DIR)
121
# VERSION FPHSA options not handled by CMake version < 2.8.2)
122
#                                  VERSION_VAR LUSTRE_COMPILER_VERSION)
123
mark_as_advanced(LUSTRE_INCLUDE_DIR)
    (1-1/1)