Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / share / FindLustre.cmake @ 17db36ed

History | View | Annotate | Download (4.23 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
#
20

    
21
if(LUSTRE_PATH_HINT)
22
  message(STATUS "FindLustre: using PATH HINT: ${LUSTRE_PATH_HINT}")
23
else()
24
  set(LUSTRE_PATH_HINT)
25
endif()
26

    
27
#One can add his/her own builtin PATH.
28
#FILE(TO_CMAKE_PATH "/DATA/ERIC/Lustre/lustre-x.y" MYPATH)
29
#list(APPEND LUSTRE_PATH_HINT ${MYPATH})
30

    
31
# FIND_PROGRAM twice using NO_DEFAULT_PATH on first shot
32
find_program(LUSTRE_COMPILER
33
  NAMES lustrec
34
  PATHS ${LUSTRE_PATH_HINT}
35
  PATH_SUFFIXES bin
36
  NO_DEFAULT_PATH
37
  DOC "Path to the Lustre compiler command 'lustrec'")
38

    
39
find_program(LUSTRE_COMPILER
40
  NAMES lustrec
41
  PATHS ${LUSTRE_PATH_HINT}
42
  PATH_SUFFIXES bin
43
  DOC "Path to the Lustre compiler command 'lustrec'")
44

    
45
if(LUSTRE_COMPILER)
46
    # get the path where the lustre compiler was found
47
    get_filename_component(LUSTRE_PATH ${LUSTRE_COMPILER} PATH)
48
    # remove bin
49
    get_filename_component(LUSTRE_PATH ${LUSTRE_PATH} PATH)
50
    # add path to LUSTRE_PATH_HINT
51
    list(APPEND LUSTRE_PATH_HINT ${LUSTRE_PATH})
52
    execute_process(COMMAND ${LUSTRE_COMPILER} -version
53
        OUTPUT_VARIABLE LUSTRE_COMPILER_VERSION
54
        OUTPUT_STRIP_TRAILING_WHITESPACE)
55
    message(STATUS "Lustre compiler version is : ${LUSTRE_COMPILER_VERSION}")
56
endif(LUSTRE_COMPILER)
57

    
58
find_path(LUSTRE_INCLUDE_DIR
59
          NAMES arrow.h
60
          PATHS ${LUSTRE_PATH_HINT}
61
          PATH_SUFFIXES include/lustrec
62
          DOC "The Lustre include headers")
63

    
64
# Macros used to compile a lustre library
65
include(CMakeParseArguments)
66
function(Lustre_Compile)
67
  set(options "")
68
  set(oneValueArgs NODE LIBNAME)
69
  set(multiValueArgs LUS_FILES USER_C_FILES)
70
  cmake_parse_arguments(LUS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
71

    
72
  if (NOT LUS_LIBNAME)
73
    message(FATAL_ERROR "You should specify LIBNAME for each Lustre_Compile call.")
74
  endif()
75

    
76
  if(LUS_NODE)
77
    set(LUSTRE_NODE_OPT "-node ${LUS_NODE}")
78
    set(LUSTRE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/lus_${LUS_LIBNAME}/${LUS_NODE}")
79
  else()
80
    set(LUSTRE_NODE_OPT "")
81
    set(LUSTRE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/lus_${LUS_LIBNAME}")
82
  endif()
83

    
84
  file(MAKE_DIRECTORY ${LUSTRE_OUTPUT_DIR})
85
  set(GLOBAL_LUSTRE_GENERATED_FILES)
86
  foreach(LFILE IN LISTS LUS_LUS_FILES)
87
    get_filename_component(L ${LFILE} NAME_WE)
88
    set(LUSTRE_GENERATED_FILES ${LUSTRE_OUTPUT_DIR}/${L}.h ${LUSTRE_OUTPUT_DIR}/${L}.c)
89
    list(APPEND GLOBAL_LUSTRE_GENERATED_FILES ${LUSTRE_GENERATED_FILES})
90
    add_custom_command(
91
      OUTPUT ${LUSTRE_GENERATED_FILES}
92
      COMMAND ${LUSTRE_COMPILER} ${LUSTRE_NODE_OPT} -d ${LUSTRE_OUTPUT_DIR} ${LFILE}
93
      DEPENDS ${LFILE}
94
      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
95
      COMMENT "Compile Lustre source(s): ${LFILE}."
96
      )
97
    set_source_files_properties(${LUSTRE_GENERATED_FILES} PROPERTIES GENERATED TRUE)
98
  endforeach()
99

    
100
  include_directories(${LUSTRE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${LUSTRE_OUTPUT_DIR})
101
  add_library(${LUS_LIBNAME} SHARED
102
              ${GLOBAL_LUSTRE_GENERATED_FILES} ${LUS_USER_C_FILES}
103
             )
104
  message(STATUS "Lustre: Added rule for building lustre library: ${LUS_LIBNAME}")
105
endfunction(Lustre_Compile)
106

    
107
# handle the QUIETLY and REQUIRED arguments and set LUSTRE_FOUND to TRUE if
108
# all listed variables are TRUE
109
include(FindPackageHandleStandardArgs)
110
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LUSTRE
111
                                  REQUIRED_VARS LUSTRE_COMPILER LUSTRE_INCLUDE_DIR)
112
# VERSION FPHSA options not handled by CMake version < 2.8.2)
113
#                                  VERSION_VAR LUSTRE_COMPILER_VERSION)
114
mark_as_advanced(LUSTRE_INCLUDE_DIR)