Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec-tests / regression_tests / modules / Lustre_compile.cmake @ fa9e78e5

History | View | Annotate | Download (5.69 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_FILE <Lustre file>
18
#                  [USER_C_FILES <C files>]
19
#                  [VERBOSE <level>]
20
#		   [OPTIONS <options>])
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

    
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

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

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

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

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

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

    
78

    
79
  get_filename_component(L ${LUS_LUS_FILE} NAME_WE)
80
  get_filename_component(E ${LUS_LUS_FILE} EXT)
81
  set(LUSTREC_ARGS "")
82
  if(LUS_NODE)
83
    set(LUSTRE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/${L}/node_${LUS_NODE}")
84
    set(LUSTREC_ARGS ${LUSTREC_ARGS} -node ${LUS_NODE} )
85
  else()
86
    set(LUSTRE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/${L}")
87
  endif()
88
 
89
  
90
  if(LUS_OPTS)
91
    string(REPLACE "-" "" LUS_OPTS_CUT ${LUS_OPTS})
92
    string(REPLACE " " "_" LUS_OPTS_CUT ${LUS_OPTS_CUT})
93
    if(LUS_NODE)
94
		set(LUSTRE_OUTPUT_DIR "${LUSTRE_OUTPUT_DIR}_${LUS_OPTS_CUT}")
95
    else()
96
		set(LUSTRE_OUTPUT_DIR "${LUSTRE_OUTPUT_DIR}/${LUS_OPTS_CUT}")
97
	endif()
98
	set(LUSTREC_ARGS ${LUSTREC_ARGS} ${LUS_OPTS} )
99
  endif()
100

    
101
  if (LUS_VERBOSE)
102
    set(LUSTRE_VERBOSE_OPT "-verbose ${LUS_VERBOSE}")
103
    set(LUSTREC_ARGS ${LUSTREC_ARGS} -verbose ${LUS_VERBOSE} )
104
  endif()
105
  
106
  
107
  set(LUSTRE_GENERATED_FILES "")
108
  file(MAKE_DIRECTORY ${LUSTRE_OUTPUT_DIR})
109
  # create list of generated C files in parent scope
110
  if ("${E}" STREQUAL ".lus")
111
	set(LUSTRE_GENERATED_FILES ${LUSTRE_OUTPUT_DIR}/${L}.h   ${LUSTRE_OUTPUT_DIR}/${L}.lusic )
112
	if (LUS_NODE)
113
		set(LUSTRE_GENERATED_FILES ${LUSTRE_GENERATED_FILES} ${LUSTRE_OUTPUT_DIR}/${L}.c ${LUSTRE_OUTPUT_DIR}/${L}_alloc.h ${LUSTRE_OUTPUT_DIR}/${L}_main.c ${LUSTRE_OUTPUT_DIR}/${L}.makefile)
114
	endif(LUS_NODE)
115
	if(LUS_OPTS MATCHES "horn")
116
		set(LUSTRE_GENERATED_FILES ${LUSTRE_GENERATED_FILES} ${LUSTRE_OUTPUT_DIR}/${L}.smt2)
117
	endif(LUS_OPTS MATCHES "horn")
118
  elseif("${E}" STREQUAL ".lusi")
119
	set(LUSTRE_GENERATED_FILES ${LUSTRE_OUTPUT_DIR}/${L}.h)
120
  endif()
121
  
122
  
123
  set(LUSTREC_ARGS ${LUSTREC_ARGS} -d ${LUSTRE_OUTPUT_DIR} ${LUS_LUS_FILE})
124
	
125
  set(LUSTRE_OPTS_POSTFIX_${L} "${LUS_OPTS_CUT}" PARENT_SCOPE)
126
  set(LUSTREC_ARGS_${L}_${LUS_NODE}_${LUS_OPTS_CUT} "${LUSTREC_ARGS}" PARENT_SCOPE)
127
  set(LUSTRE_GENERATED_FILES_${L}_${LUS_NODE}_${LUS_OPTS_CUT} "${LUSTRE_GENERATED_FILES}" PARENT_SCOPE)
128
  set(LUSTRE_OUTPUT_DIR_${L}_${LUS_NODE}_${LUS_OPTS_CUT} "${LUSTRE_OUTPUT_DIR}" PARENT_SCOPE)
129
endfunction(Lustre_Compile)
130

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

    
140

    
141
#helpfull functions and macros
142
MACRO(SUBDIRLIST result curdir REGEX_PREFIX)
143
  FILE(GLOB children RELATIVE ${curdir} ${curdir}/${REGEX_PREFIX}*)
144
  SET(dirlist "")
145
  FOREACH(child ${children})
146
    IF(IS_DIRECTORY ${curdir}/${child})
147
      LIST(APPEND dirlist ${child})
148
    ENDIF()
149
  ENDFOREACH()
150
  SET(${result} ${dirlist})
151
ENDMACRO()
152

    
153
MACRO(LUSTREFILES result dir)
154
  FILE(GLOB children ${dir} ${dir}/*.lus)
155
  SET(lustreFileslist "")
156
  FOREACH(child ${children})
157
    IF(EXISTS ${child} AND NOT IS_DIRECTORY ${child})
158
      LIST(APPEND lustreFileslist ${child})
159
    ENDIF()
160
  ENDFOREACH()
161
  SET(${result} ${lustreFileslist})
162
ENDMACRO()
163

    
164

    
165