Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / share / FindLustre.cmake @ ecba3795

History | View | Annotate | Download (6.06 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
#		   [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

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

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

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

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

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

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

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

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

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

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

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

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

    
140
  include_directories(${LUSTRE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${LUSTRE_OUTPUT_DIR})
141
  add_library(${LUS_LIBNAME} SHARED
142
              ${GLOBAL_LUSTRE_GENERATED_C_FILES} ${LUS_USER_C_FILES}
143
              )
144
  set_target_properties(${LUS_LIBNAME} PROPERTIES COMPILE_FLAGS "-std=c99")
145
  set(LUSTRE_GENERATED_C_FILES_${LUS_LIBNAME} "${GLOBAL_LUSTRE_GENERATED_C_FILES}" PARENT_SCOPE)
146
  message(STATUS "Lustre: Added rule for building lustre library: ${LUS_LIBNAME}")
147
endfunction(Lustre_Compile)
148

    
149
# handle the QUIETLY and REQUIRED arguments and set LUSTRE_FOUND to TRUE if
150
# all listed variables are TRUE
151
include(FindPackageHandleStandardArgs)
152
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LUSTRE
153
                                  REQUIRED_VARS LUSTRE_COMPILER LUSTRE_INCLUDE_DIR)
154
# VERSION FPHSA options not handled by CMake version < 2.8.2)
155
#                                  VERSION_VAR LUSTRE_COMPILER_VERSION)
156
mark_as_advanced(LUSTRE_INCLUDE_DIR)