2
# Copyright 2009-2010 Jakob Westhoff. All rights reserved.
4
# Redistribution and use in source and binary forms, with or without
5
# modification, are permitted provided that the following conditions are met:
7
# 1. Redistributions of source code must retain the above copyright notice,
8
# this list of conditions and the following disclaimer.
10
# 2. Redistributions in binary form must reproduce the above copyright notice,
11
# this list of conditions and the following disclaimer in the documentation
12
# and/or other materials provided with the distribution.
14
# THIS SOFTWARE IS PROVIDED BY JAKOB WESTHOFF ``AS IS'' AND ANY EXPRESS OR
15
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17
# EVENT SHALL JAKOB WESTHOFF OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
22
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
# The views and conclusions contained in the software and documentation are those
26
# of the authors and should not be interpreted as representing official policies,
27
# either expressed or implied, of Jakob Westhoff
30
include(ParseArguments)
31
find_package(Vala REQUIRED)
34
# Compile vala files to their c equivalents for further processing.
36
# The "vala_precompile" macro takes care of calling the valac executable on the
37
# given source to produce c files which can then be processed further using
38
# default cmake functions.
40
# The first parameter provided is a variable, which will be filled with a list
41
# of c files outputted by the vala compiler. This list can than be used in
42
# conjuction with functions like "add_executable" or others to create the
43
# neccessary compile rules with CMake.
45
# The initial variable is followed by a list of .vala files to be compiled.
46
# Please take care to add every vala file belonging to the currently compiled
47
# project or library as Vala will otherwise not be able to resolve all
50
# The following sections may be specified afterwards to provide certain options
51
# to the vala compiler:
54
# A list of vala packages/libraries to be used during the compile cycle. The
55
# package names are exactly the same, as they would be passed to the valac
59
# A list of optional options to be passed to the valac executable. This can be
60
# used to pass "--thread" for example to enable multi-threading support.
63
# A list of custom vapi files to be included for compilation. This can be
64
# useful to include freshly created vala libraries without having to install
68
# Pass all the needed flags to the compiler to create an internal vapi for
69
# the compiled library. The provided name will be used for this and a
70
# <provided_name>.vapi file will be created.
73
# Let the compiler generate a header file for the compiled code. There will
74
# be a header file as well as an internal header file being generated called
75
# <provided_name>.h and <provided_name>_internal.h
77
# The following call is a simple example to the vala_precompile macro showing
78
# an example to every of the optional sections:
80
# vala_precompile(VALA_C
100
# Most important is the variable VALA_C which will contain all the generated c
101
# file names after the call.
104
macro(vala_precompile output)
105
parse_arguments(ARGS "PACKAGES;OPTIONS;DIRECTORY;GENERATE_HEADER;GENERATE_VAPI;CUSTOM_VAPIS" "" ${ARGN})
107
set(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${ARGS_DIRECTORY})
109
set(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
110
endif(ARGS_DIRECTORY)
111
include_directories(${DIRECTORY})
112
set(vala_pkg_opts "")
113
foreach(pkg ${ARGS_PACKAGES})
114
list(APPEND vala_pkg_opts "--pkg=${pkg}")
115
endforeach(pkg ${ARGS_PACKAGES})
119
foreach(src ${ARGS_DEFAULT_ARGS})
120
list(APPEND in_files "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
121
string(REPLACE ".vala" ".c" src ${src})
122
string(REPLACE ".gs" ".c" src ${src})
123
set(out_file "${DIRECTORY}/${src}")
124
list(APPEND out_files "${DIRECTORY}/${src}")
125
list(APPEND ${output} ${out_file})
126
endforeach(src ${ARGS_DEFAULT_ARGS})
128
set(custom_vapi_arguments "")
129
if(ARGS_CUSTOM_VAPIS)
130
foreach(vapi ${ARGS_CUSTOM_VAPIS})
131
if(${vapi} MATCHES ${CMAKE_SOURCE_DIR} OR ${vapi} MATCHES ${CMAKE_BINARY_DIR})
132
list(APPEND custom_vapi_arguments ${vapi})
133
else (${vapi} MATCHES ${CMAKE_SOURCE_DIR} OR ${vapi} MATCHES ${CMAKE_BINARY_DIR})
134
list(APPEND custom_vapi_arguments ${CMAKE_CURRENT_SOURCE_DIR}/${vapi})
135
endif(${vapi} MATCHES ${CMAKE_SOURCE_DIR} OR ${vapi} MATCHES ${CMAKE_BINARY_DIR})
136
endforeach(vapi ${ARGS_CUSTOM_VAPIS})
137
endif(ARGS_CUSTOM_VAPIS)
139
set(vapi_arguments "")
140
if(ARGS_GENERATE_VAPI)
141
list(APPEND out_files "${DIRECTORY}/${ARGS_GENERATE_VAPI}.vapi")
142
set(vapi_arguments "--internal-vapi=${ARGS_GENERATE_VAPI}.vapi")
144
# Header and internal header is needed to generate internal vapi
145
if (NOT ARGS_GENERATE_HEADER)
146
set(ARGS_GENERATE_HEADER ${ARGS_GENERATE_VAPI})
147
endif(NOT ARGS_GENERATE_HEADER)
148
endif(ARGS_GENERATE_VAPI)
150
set(header_arguments "")
151
if(ARGS_GENERATE_HEADER)
152
list(APPEND out_files "${DIRECTORY}/${ARGS_GENERATE_HEADER}.h")
153
list(APPEND out_files "${DIRECTORY}/${ARGS_GENERATE_HEADER}_internal.h")
154
list(APPEND header_arguments "--header=${DIRECTORY}/${ARGS_GENERATE_HEADER}.h")
155
list(APPEND header_arguments "--internal-header=${DIRECTORY}/${ARGS_GENERATE_HEADER}_internal.h")
156
endif(ARGS_GENERATE_HEADER)
158
add_custom_command(OUTPUT ${out_files}
165
"-b" ${CMAKE_CURRENT_SOURCE_DIR}
170
${custom_vapi_arguments}
175
endmacro(vala_precompile)