1
|
# - Find Zustre compiler with associated includes path.
|
2
|
# See https://github.com/coco-team/zustre
|
3
|
# This module defines
|
4
|
# ZUSTRE_COMPILER, the ZUStre compiler
|
5
|
# ZUSTRE_COMPILER_VERSION, the version of the ZUStre compiler
|
6
|
# ZUSTRE_INCLUDE_DIR, where to find dword.h, etc.
|
7
|
# ZUSTRE_FOUND, If false, ZUStre was not found.
|
8
|
# On can set ZUSTRE_PATH_HINT before using find_package(Zustre) and the
|
9
|
# module with use the PATH as a hint to find zustre.
|
10
|
#
|
11
|
# The hint can be given on the command line too:
|
12
|
# cmake -DZUSTRE_PATH_HINT=/DATA/Hamza/Zustre/zustre-x.y /path/to/source
|
13
|
#
|
14
|
# The module defines some functions:
|
15
|
# Zustre_Compile([NODE <ZUStre Main Node>]
|
16
|
# LUS_FILE <ZUStre file>
|
17
|
# [VERBOSE <level>]
|
18
|
# [OPTIONS <options>])
|
19
|
#
|
20
|
#
|
21
|
|
22
|
|
23
|
if(ZUSTRE_PATH_HINT)
|
24
|
message(STATUS "FindZustre: using PATH HINT: ${ZUSTRE_PATH_HINT}")
|
25
|
else()
|
26
|
set(ZUSTRE_PATH_HINT)
|
27
|
endif()
|
28
|
|
29
|
|
30
|
# FIND_PROGRAM twice using NO_DEFAULT_PATH on first shot
|
31
|
find_program(ZUSTRE_COMPILER
|
32
|
NAMES zustre
|
33
|
PATHS ${ZUSTRE_PATH_HINT}
|
34
|
PATH_SUFFIXES bin
|
35
|
NO_DEFAULT_PATH
|
36
|
DOC "Path to the Zustre compiler command 'zustre'")
|
37
|
|
38
|
find_program(ZUSTRE_COMPILER
|
39
|
NAMES zustre
|
40
|
PATHS ${ZUSTRE_PATH_HINT}
|
41
|
PATH_SUFFIXES bin
|
42
|
DOC "Path to the ZUStre compiler command 'zustre'")
|
43
|
|
44
|
if(ZUSTRE_COMPILER)
|
45
|
# get the path where the zustre compiler was found
|
46
|
get_filename_component(ZUSTRE_PATH ${ZUSTRE_COMPILER} PATH)
|
47
|
# remove bin
|
48
|
get_filename_component(ZUSTRE_PATH ${ZUSTRE_PATH} PATH)
|
49
|
# add path to ZUSTRE_PATH_HINT
|
50
|
list(APPEND ZUSTRE_PATH_HINT ${ZUSTRE_PATH})
|
51
|
endif(ZUSTRE_COMPILER)
|
52
|
|
53
|
find_path(ZUSTRE_INCLUDE_DIR
|
54
|
NAMES z3.h
|
55
|
PATHS ${ZUSTRE_PATH_HINT}
|
56
|
PATH_SUFFIXES include
|
57
|
DOC "The ZUStre include headers")
|
58
|
|
59
|
# Macros used to compile a ZUStre library
|
60
|
include(CMakeParseArguments)
|
61
|
function(Zustre_Compile)
|
62
|
set(options "")
|
63
|
set(oneValueArgs NODE VERBOSE LUS_FILE)
|
64
|
set(multiValueArgs OPTS )
|
65
|
cmake_parse_arguments(ZUS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
66
|
|
67
|
|
68
|
get_filename_component(L ${ZUS_LUS_FILE} NAME_WE)
|
69
|
get_filename_component(E ${ZUS_LUS_FILE} EXT)
|
70
|
set(ZUSTRE_ARGS "")
|
71
|
if(ZUS_NODE)
|
72
|
set(ZUSTRE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/${L}/node_${ZUS_NODE}")
|
73
|
set(ZUSTRE_ARGS ${ZUSTRE_ARGS} --node ${ZUS_NODE} )
|
74
|
else()
|
75
|
set(ZUSTRE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/${L}")
|
76
|
endif()
|
77
|
|
78
|
|
79
|
if(ZUS_OPTS)
|
80
|
string(REPLACE "--" "_" ZUS_OPTS_CUT ${ZUS_OPTS})
|
81
|
string(REPLACE "-" "" ZUS_OPTS_CUT ${ZUS_OPTS_CUT})
|
82
|
string(REPLACE " " "_" ZUS_OPTS_CUT ${ZUS_OPTS_CUT})
|
83
|
if(ZUS_NODE)
|
84
|
set(ZUSTRE_OUTPUT_DIR "${ZUSTRE_OUTPUT_DIR}_${ZUS_OPTS_CUT}")
|
85
|
else()
|
86
|
set(ZUSTRE_OUTPUT_DIR "${ZUSTRE_OUTPUT_DIR}/${ZUS_OPTS_CUT}")
|
87
|
endif()
|
88
|
set(ZUSTRE_ARGS ${ZUSTRE_ARGS} ${ZUS_OPTS} )
|
89
|
endif()
|
90
|
|
91
|
if (ZUS_VERBOSE)
|
92
|
set(ZUSTRE_ARGS ${ZUSTRE_ARGS} --verbose ${ZUS_VERBOSE} )
|
93
|
endif()
|
94
|
|
95
|
|
96
|
set(ZUSTRE_GENERATED_FILES "")
|
97
|
file(MAKE_DIRECTORY ${ZUSTRE_OUTPUT_DIR})
|
98
|
# create list of generated C files in parent scope
|
99
|
if ("${E}" STREQUAL ".lus")
|
100
|
set(ZUSTRE_GENERATED_FILES ${ZUSTRE_OUTPUT_DIR}/${L}.h ${ZUSTRE_OUTPUT_DIR}/${L}.lusic )
|
101
|
if(ZUS_OPTS MATCHES "smt2")
|
102
|
set(ZUSTRE_GENERATED_FILES ${ZUSTRE_GENERATED_FILES} ${ZUSTRE_OUTPUT_DIR}/${L}.smt2)
|
103
|
endif(ZUS_OPTS MATCHES "smt2")
|
104
|
endif()
|
105
|
file(COPY ${ZUS_LUS_FILE} DESTINATION ${ZUSTRE_OUTPUT_DIR})
|
106
|
set(ZUSTRE_ARGS ${ZUSTRE_ARGS} ${ZUSTRE_OUTPUT_DIR}/${L}.lus)
|
107
|
|
108
|
set(ZUSTRE_OPTS_POSTFIX_${L} "${ZUS_OPTS_CUT}" PARENT_SCOPE)
|
109
|
set(ZUSTRE_ARGS_${L}_${ZUS_NODE}_${ZUS_OPTS_CUT} "${ZUSTRE_ARGS}" PARENT_SCOPE)
|
110
|
set(ZUSTRE_GENERATED_FILES_${L}_${ZUS_NODE}_${ZUS_OPTS_CUT} "${ZUSTRE_GENERATED_FILES}" PARENT_SCOPE)
|
111
|
set(ZUSTRE_OUTPUT_DIR_${L}_${ZUS_NODE}_${ZUS_OPTS_CUT} "${ZUSTRE_OUTPUT_DIR}" PARENT_SCOPE)
|
112
|
endfunction(Zustre_Compile)
|
113
|
|
114
|
# handle the QUIETLY and REQUIRED arguments and set ZUSTRE_FOUND to TRUE if
|
115
|
# all listed variables are TRUE
|
116
|
include(FindPackageHandleStandardArgs)
|
117
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZUSTRE
|
118
|
REQUIRED_VARS ZUSTRE_COMPILER ZUSTRE_INCLUDE_DIR)
|
119
|
# VERSION FPHSA options not handled by CMake version < 2.8.2)
|
120
|
# VERSION_VAR ZUSTRE_COMPILER_VERSION)
|
121
|
mark_as_advanced(ZUSTRE_INCLUDE_DIR)
|
122
|
|
123
|
|