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
|
COMMAND ${LUSTRE_COMPILER} ${LUSTRE_LUSI_OPT} ${LFILE}
|
122
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${LFILE}
|
123
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
124
|
COMMENT "Compile Lustre source(s): ${LFILE} with option -lusi."
|
125
|
)
|
126
|
message(STATUS "lustrec will produce lusi file: ${LFILE}i")
|
127
|
endif()
|
128
|
add_custom_command(
|
129
|
OUTPUT ${LUSTRE_GENERATED_FILES}
|
130
|
COMMAND ${LUSTRE_COMPILER} ${LUSTRE_VERBOSE_OPT} ${LUSTRE_NODE_OPT} -d ${LUSTRE_OUTPUT_DIR} ${LFILE}
|
131
|
DEPENDS ${LFILE}
|
132
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
133
|
COMMENT "Compile Lustre source(s): ${LFILE} (generates: ${LUSTRE_GENERATED_FILES})."
|
134
|
)
|
135
|
set_source_files_properties(${LUSTRE_GENERATED_FILES} PROPERTIES GENERATED TRUE)
|
136
|
endforeach()
|
137
|
|
138
|
include_directories(${LUSTRE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${LUSTRE_OUTPUT_DIR})
|
139
|
add_library(${LUS_LIBNAME} SHARED
|
140
|
${GLOBAL_LUSTRE_GENERATED_C_FILES} ${LUS_USER_C_FILES}
|
141
|
)
|
142
|
set_target_properties(${LUS_LIBNAME} PROPERTIES COMPILE_FLAGS "-std=c99")
|
143
|
set(LUSTRE_GENERATED_C_FILES_${LUS_LIBNAME} "${GLOBAL_LUSTRE_GENERATED_C_FILES}" PARENT_SCOPE)
|
144
|
message(STATUS "Lustre: Added rule for building lustre library: ${LUS_LIBNAME}")
|
145
|
endfunction(Lustre_Compile)
|
146
|
|
147
|
# handle the QUIETLY and REQUIRED arguments and set LUSTRE_FOUND to TRUE if
|
148
|
# all listed variables are TRUE
|
149
|
include(FindPackageHandleStandardArgs)
|
150
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LUSTRE
|
151
|
REQUIRED_VARS LUSTRE_COMPILER LUSTRE_INCLUDE_DIR)
|
152
|
# VERSION FPHSA options not handled by CMake version < 2.8.2)
|
153
|
# VERSION_VAR LUSTRE_COMPILER_VERSION)
|
154
|
mark_as_advanced(LUSTRE_INCLUDE_DIR)
|