Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / share / FindLustre.cmake @ a1daa793

History | View | Annotate | Download (5.44 KB)

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
#                  LIBNAME <libraryName>)
21
#
22
# When used the Lustre_Compile macro define the variable
23
# LUSTRE_GENERATED_C_FILES_<libraryName> in the parent scope
24
# so that the caller can get (if needed) the list of Lustre generated files.
25
# The VERBOSE level is a numeric value passed directly to the -verbose
26
# command line option of the lustre compiler
27
#
28

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

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

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

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

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

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

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

    
80
  if (NOT LUS_LIBNAME)
81
    message(FATAL_ERROR "You should specify LIBNAME for each Lustre_Compile call.")
82
  endif()
83

    
84
  if(LUS_NODE)
85
    set(LUSTRE_NODE_OPT "-node ${LUS_NODE}")
86
    set(LUSTRE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/lus_${LUS_LIBNAME}/${LUS_NODE}")
87
  else()
88
    set(LUSTRE_NODE_OPT "")
89
    set(LUSTRE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/lus_${LUS_LIBNAME}")
90
  endif()
91

    
92
  if (LUS_VERBOSE)
93
    set(LUSTRE_VERBOSE_OPT "-verbose ${LUS_VERBOSE}")
94
  else()
95
    # the default is to be quiet.
96
    set(LUSTRE_VERBOSE_OPT "-verbose;0")
97
  endif()
98

    
99
  file(MAKE_DIRECTORY ${LUSTRE_OUTPUT_DIR})
100
  set(GLOBAL_LUSTRE_GENERATED_C_FILES "")
101
  # create list of generated C files in parent scope
102
  set(LUSTRE_GENERATED_C_FILES_${LUS_LIBNAME} "" PARENT_SCOPE)
103
  foreach(LFILE IN LISTS LUS_LUS_FILES)
104
    get_filename_component(L ${LFILE} NAME_WE)
105
    get_filename_component(E ${LFILE} EXT)
106
    if ("${E}" STREQUAL ".lus")
107
      set(LUSTRE_GENERATED_FILES ${LUSTRE_OUTPUT_DIR}/${L}.h ${LUSTRE_OUTPUT_DIR}/${L}.c ${LUSTRE_OUTPUT_DIR}/${L}_alloc.h)
108
    elseif("${E}" STREQUAL ".lusi")
109
      set(LUSTRE_GENERATED_FILES ${LUSTRE_OUTPUT_DIR}/${L}.h)
110
    endif()
111
    list(APPEND GLOBAL_LUSTRE_GENERATED_C_FILES ${LUSTRE_GENERATED_FILES})
112
    set(LUSTRE_GENERATED_FILES ${LUSTRE_GENERATED_FILES} ${LUSTRE_OUTPUT_DIR}/${L}.lusic)
113
    add_custom_command(
114
      OUTPUT ${LUSTRE_GENERATED_FILES}
115
      COMMAND ${LUSTRE_COMPILER} ${LUSTRE_VERBOSE_OPT} ${LUSTRE_NODE_OPT} -d ${LUSTRE_OUTPUT_DIR} ${LFILE}
116
      DEPENDS ${LFILE}
117
      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
118
      COMMENT "Compile Lustre source(s): ${LFILE} (generates: ${LUSTRE_GENERATED_FILES})."
119
      )
120
    set_source_files_properties(${LUSTRE_GENERATED_FILES} PROPERTIES GENERATED TRUE)
121
  endforeach()
122

    
123
  include_directories(${LUSTRE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${LUSTRE_OUTPUT_DIR})
124
  add_library(${LUS_LIBNAME} SHARED
125
              ${GLOBAL_LUSTRE_GENERATED_C_FILES} ${LUS_USER_C_FILES}
126
              )
127
  set_target_properties(${LUS_LIBNAME} PROPERTIES COMPILE_FLAGS "-std=c99")
128
  set(LUSTRE_GENERATED_C_FILES_${LUS_LIBNAME} "${GLOBAL_LUSTRE_GENERATED_C_FILES}" PARENT_SCOPE)
129
  message(STATUS "Lustre: Added rule for building lustre library: ${LUS_LIBNAME}")
130
endfunction(Lustre_Compile)
131

    
132
# handle the QUIETLY and REQUIRED arguments and set LUSTRE_FOUND to TRUE if
133
# all listed variables are TRUE
134
include(FindPackageHandleStandardArgs)
135
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LUSTRE
136
                                  REQUIRED_VARS LUSTRE_COMPILER LUSTRE_INCLUDE_DIR)
137
# VERSION FPHSA options not handled by CMake version < 2.8.2)
138
#                                  VERSION_VAR LUSTRE_COMPILER_VERSION)
139
mark_as_advanced(LUSTRE_INCLUDE_DIR)