Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec-tests / regression_tests / modules / Lustre_compile.cmake @ 6c3ea955

History | View | Annotate | Download (6.58 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
#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 "")
77
  set(oneValueArgs  NODE VERBOSE LUS_FILE)
78
  set(multiValueArgs  OPTS USER_C_FILES )
79
  cmake_parse_arguments(LUS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
80

    
81

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

    
100
  if (LUS_VERBOSE)
101
    set(LUSTRE_VERBOSE_OPT "-verbose ${LUS_VERBOSE}")
102
    set(LUSTREC_ARGS ${LUSTREC_ARGS} -verbose ${LUS_VERBOSE} )
103
  endif()
104
  
105
  
106
  set(LUSTRE_GENERATED_FILES "")
107
  file(MAKE_DIRECTORY ${LUSTRE_OUTPUT_DIR})
108
  # create list of generated C files in parent scope
109
  if ("${E}" STREQUAL ".lus")
110
	set(LUSTRE_GENERATED_FILES ${LUSTRE_OUTPUT_DIR}/${L}.h  ${LUSTRE_OUTPUT_DIR}/${L}.c ${LUSTRE_OUTPUT_DIR}/${L}_alloc.h ${LUSTRE_OUTPUT_DIR}/${L}.makefile)
111
	if (LUS_NODE)
112
		set(LUSTRE_GENERATED_FILES ${LUSTRE_GENERATED_FILES} ${LUSTRE_OUTPUT_DIR}/${L}_main.c ${LUSTRE_OUTPUT_DIR}/${L}.makefile)
113
	endif(LUS_NODE)
114
  elseif("${E}" STREQUAL ".lusi")
115
	set(LUSTRE_GENERATED_FILES ${LUSTRE_OUTPUT_DIR}/${L}.h)
116
  endif()
117
  
118
  
119
  set(LUSTREC_ARGS ${LUSTREC_ARGS}   -d ${LUSTRE_OUTPUT_DIR} ${LUS_LUS_FILE})
120
	execute_process(RESULT_VARIABLE res_var
121
		COMMAND ${LUSTRE_COMPILER} ${LUSTREC_ARGS}  
122
		DEPENDS ${LUS_LUS_FILE}  
123
		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
124
    )
125
	
126
	if(NOT "${res_var}" STREQUAL "0")
127
	  # Lustrec failed
128
	  set(REPORT_PATH  "${CMAKE_CURRENT_BINARY_DIR}/report")
129
	  file(APPEND ${REPORT_PATH}.in  "Lustrec failed with the following command \n ${LUSTRE_COMPILER} ${LUSTREC_ARGS}  \n")
130
	  message("Lustrec failed with the following command \n ${LUSTRE_COMPILER} ${LUSTREC_ARGS}  \n")
131
	  
132
	endif()
133
	set(LUSTRE_OUTPUT_DIR_${L}_${LUS_NODE}_${LUS_OPTS}_RESULT ${res_var} PARENT_SCOPE)
134
  #add_custom_command(
135
  #  OUTPUT ${LUSTRE_GENERATED_FILES}
136
  #  COMMAND ${LUSTRE_COMPILER} 
137
	#ARGS ${LUSTREC_ARGS}    
138
  #  DEPENDS ${LUS_LUS_FILE}
139
  #  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
140
  #  COMMENT "${LUSTRE_COMPILER} ${LUSTREC_ARGS}"
141
  #)
142

    
143
	add_test(NAME LUSTRE_OUTPUT_DIR_${L}_${LUS_NODE}_${LUS_OPTS}
144
			COMMAND ${CMAKE_BINARY_DIR}/modules/read_value "${res_var}" "${LUSTRE_COMPILER} ${LUSTREC_ARGS}"
145
			WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
146
	)
147

    
148

    
149
  set(LUSTRE_GENERATED_FILES_${L}_${LUS_NODE}_${LUS_OPTS} "${LUSTRE_GENERATED_FILES}" PARENT_SCOPE)
150
  set(LUSTRE_OUTPUT_DIR_${L}_${LUS_NODE}_${LUS_OPTS} "${LUSTRE_OUTPUT_DIR}" PARENT_SCOPE)
151
  message(STATUS "Lustre: Added rule for compiling lustre source: ${LUSTRE_COMPILER} ${LUSTREC_ARGS}")
152
endfunction(Lustre_Compile)
153

    
154
# handle the QUIETLY and REQUIRED arguments and set LUSTRE_FOUND to TRUE if
155
# all listed variables are TRUE
156
include(FindPackageHandleStandardArgs)
157
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LUSTRE
158
                                  REQUIRED_VARS LUSTRE_COMPILER LUSTRE_INCLUDE_DIR)
159
# VERSION FPHSA options not handled by CMake version < 2.8.2)
160
#                                  VERSION_VAR LUSTRE_COMPILER_VERSION)
161
mark_as_advanced(LUSTRE_INCLUDE_DIR)
162

    
163

    
164
#helpfull functions and macros
165
MACRO(SUBDIRLIST result curdir REGEX_PREFIX)
166
  FILE(GLOB children RELATIVE ${curdir} ${curdir}/${REGEX_PREFIX}*)
167
  SET(dirlist "")
168
  FOREACH(child ${children})
169
    IF(IS_DIRECTORY ${curdir}/${child})
170
      LIST(APPEND dirlist ${child})
171
    ENDIF()
172
  ENDFOREACH()
173
  SET(${result} ${dirlist})
174
ENDMACRO()
175

    
176
MACRO(LUSTREFILES result dir)
177
  FILE(GLOB children ${dir} ${dir}/*.lus)
178
  SET(lustreFileslist "")
179
  FOREACH(child ${children})
180
    IF(EXISTS ${child} AND NOT IS_DIRECTORY ${child})
181
      LIST(APPEND lustreFileslist ${child})
182
    ENDIF()
183
  ENDFOREACH()
184
  SET(${result} ${lustreFileslist})
185
ENDMACRO()
186

    
187

    
188