Skip to content
Browse files

Added useful documentation to the macros

  • Loading branch information...
1 parent eb76063 commit 4771b5918b6730ee0126c5b4bd903e306d5b99dd @jakobwesthoff committed
Showing with 108 additions and 25 deletions.
  1. +26 −14 vala/FindVala.cmake
  2. +5 −1 vala/ParseArguments.cmake
  3. +77 −10 vala/ValaPrecompile.cmake
View
40 vala/FindVala.cmake
@@ -27,27 +27,39 @@
# either expressed or implied, of Jakob Westhoff
##
-
-# - Find vala compiler
-# This module finds if vala compiler is installed and determines where the
-# executables are. This code sets the following variables:
+##
+# Find module for the Vala compiler (valac)
+#
+# This module determines wheter a Vala compiler is installed on the current
+# system and where its executable is.
+#
+# Call the module using "find_package(Vala) from within your CMakeLists.txt.
#
-# VALA_FOUND - Was the vala compiler found
-# VALA_EXECUTABLE - path to the vala compiler
-# VALA_VERSION - The version number of the available valac
+# The following variables will be set after an invocation:
+#
+# VALA_FOUND Whether the vala compiler has been found or not
+# VALA_EXECUTABLE Full path to the valac executable if it has been found
+# VALA_VERSION Version number of the available valac
+##
+
+# Search for the valac executable in the usual system paths.
find_program(VALA_EXECUTABLE
NAMES valac)
-# handle the QUIETLY and REQUIRED arguments and set VALA_FOUND to TRUE if
-# all listed variables are TRUE
+# Handle the QUIETLY and REQUIRED arguments, which may be given to the find call.
+# Furthermore set VALA_FOUND to TRUE if Vala has been found (aka.
+# VALA_EXECUTABLE is set)
+
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Vala DEFAULT_MSG VALA_EXECUTABLE)
mark_as_advanced(VALA_EXECUTABLE)
-# Determine vala version
-execute_process(COMMAND ${VALA_EXECUTABLE} "--version"
- OUTPUT_VARIABLE "VALA_VERSION")
-string(REPLACE "Vala" "" "VALA_VERSION" ${VALA_VERSION})
-string(STRIP ${VALA_VERSION} "VALA_VERSION")
+# Determine the valac version
+if(VALA_FOUND)
+ execute_process(COMMAND ${VALA_EXECUTABLE} "--version"
+ OUTPUT_VARIABLE "VALA_VERSION")
+ string(REPLACE "Vala" "" "VALA_VERSION" ${VALA_VERSION})
+ string(STRIP ${VALA_VERSION} "VALA_VERSION")
+endif(VALA_FOUND)
View
6 vala/ParseArguments.cmake
@@ -1,5 +1,9 @@
+##
# This is a helper Macro to parse optional arguments in Macros/Functions
-# See http://www.cmake.org/Wiki/CMakeMacroParseArguments for documentation
+# It has been taken from the public CMake wiki.
+# See http://www.cmake.org/Wiki/CMakeMacroParseArguments for documentation and
+# licensing.
+##
macro(parse_arguments prefix arg_names option_names)
set(DEFAULT_ARGS)
foreach(arg_name ${arg_names})
View
87 vala/ValaPrecompile.cmake
@@ -28,12 +28,73 @@
##
include(ParseArguments)
+find_package(Vala)
+
+##
+# Compile vala files to their c equivalents for further processing.
+#
+# The "vala_precompile" macro takes care of calling the valac executable on the
+# given source to produce c files which can then be processed further using
+# default cmake functions.
+#
+# The first parameter provided is a variable, which will be filled with a list
+# of c files outputted by the vala compiler. This list can than be used in
+# conjuction with functions like "add_executable" or others to create the
+# neccessary compile rules with CMake.
+#
+# The initial variable is followed by a list of .vala files to be compiled.
+# Please take care to add every vala file belonging to the currently compiled
+# project or library as Vala will otherwise not be able to resolve all
+# dependencies.
+#
+# The following sections may be specified afterwards to provide certain options
+# to the vala compiler:
+#
+# PACKAGES
+# A list of vala packages/libraries to be used during the compile cycle. The
+# package names are exactly the same, as they would be passed to the valac
+# "--pkg=" option.
+#
+# OPTIONS
+# A list of optional options to be passed to the valac executable. This can be
+# used to pass "--thread" for example to enable multi-threading support.
+#
+# CUSTOM_VAPIS
+# A list of custom vapi files to be included for compilation. This can be
+# useful to include freshly created vala libraries without having to install
+# them in the system.
+#
+# GENERATE_VAPI
+# Pass all the needed flags to the compiler to create an internal vapi for
+# the compiled library. The provided name will be used for this and a
+# <provided_name>.vapi file will be created.
+#
+# GENERATE_HEADER
+# Let the compiler generate a header file for the compiled code. There will
+# be a header file as well as an internal header file being generated called
+# <provided_name>.h and <provided_name>_internal.h
+#
+# The following call is a simple example to the vala_precompile macro showing
+# an example to every of the optional sections:
+#
+# vala_precompile(VALA_C
+# source1.vala
+# source2.vala
+# source3.vala
+# PACKAGES
+# gtk+-2.0
+# gio-1.0
+# posix
+# OPTIONS
+# --thread
+# CUSTOM_VAPIS
+# some_vapi.vapi
+# GENERATE_VAPI
+# myvapi
+# GENERATE_HEADER
+# myheader
+##
-# vala_precompile[output src.vala ... [PACKAGES ...] [OPTIONS ...]]
-# This macro precomiples the given vala files to .c files and puts
-# a list with the generated .c files to output.
-# packages and additional compiler options are directly passed to the
-# vala compiler.
macro(vala_precompile output)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
parse_arguments(ARGS "PACKAGES;OPTIONS;GENERATE_HEADER;GENERATE_VAPI;CUSTOM_VAPIS" "" ${ARGN})
@@ -52,6 +113,17 @@ macro(vala_precompile output)
list(APPEND ${output} ${out_file})
endforeach(src ${ARGS_DEFAULT_ARGS})
+ set(vapi_arguments "")
+ if(ARGS_GENERATE_VAPI)
+ list(APPEND out_files "${CMAKE_CURRENT_BINARY_DIR}/${ARGS_GENERATE_VAPI}.vapi")
+ set(vapi_arguments "--internal-vapi=${ARGS_GENERATE_VAPI}.vapi")
+
+ # Header and internal header is needed to generate internal vapi
+ if (NOT ARGS_GENERATE_HEADER)
+ set(ARGS_GENERATE_HEADER ${ARGS_GENERATE_VAPI})
+ endif(NOT ARGS_GENERATE_HEADER)
+ endif(ARGS_GENERATE_VAPI)
+
set(header_arguments "")
if(ARGS_GENERATE_HEADER)
list(APPEND out_files "${CMAKE_CURRENT_BINARY_DIR}/${ARGS_GENERATE_HEADER}.h")
@@ -60,11 +132,6 @@ macro(vala_precompile output)
list(APPEND header_arguments "--internal-header=${ARGS_GENERATE_HEADER}_internal.h")
endif(ARGS_GENERATE_HEADER)
- set(vapi_arguments "")
- if(ARGS_GENERATE_VAPI)
- list(APPEND out_files "${CMAKE_CURRENT_BINARY_DIR}/${ARGS_GENERATE_VAPI}.vapi")
- set(vapi_arguments "--internal-vapi=${ARGS_GENERATE_VAPI}.vapi")
- endif(ARGS_GENERATE_VAPI)
add_custom_command(OUTPUT ${out_files}
COMMAND ${VALA_EXECUTABLE} ARGS "-C" ${header_arguments} ${vapi_arguments}

0 comments on commit 4771b59

Please sign in to comment.
Something went wrong with that request. Please try again.