[latexila] CMake: call "valac-0.12" instead of "valac"



commit e001df6a16daef38ba47da566240c617a7b22860
Author: SÃbastien Wilmet <swilmet src gnome org>
Date:   Fri Sep 16 15:27:17 2011 +0200

    CMake: call "valac-0.12" instead of "valac"
    
    "0.12" is just an example, it can be changed easily.
    
    When several versions of Vala are installed at the same time, it is
    easier to call directly the right binary.
    
    It is useful for the Gentoo package for example.

 CMakeLists.txt                               |   17 ++-
 cmake/find_vala.cmake                        |   53 ++++++++
 cmake/{vala/UseVala.cmake => use_vala.cmake} |   38 +++---
 cmake/vala/FindVala.cmake                    |   69 ----------
 cmake/vala/README.rst                        |  173 --------------------------
 5 files changed, 84 insertions(+), 266 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2f7a67e..394a59d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,12 +25,19 @@ set (SCHEMA_DIR "${CMAKE_INSTALL_PREFIX}/share")
 set (ICONS_DIR "${CMAKE_INSTALL_PREFIX}/share/icons/hicolor")
 
 if (BUILD_VALA)
-	list (APPEND CMAKE_MODULE_PATH "${latexila_SOURCE_DIR}/cmake/vala")
-	find_package (Vala "0.12.1" REQUIRED)
-	if (${VALA_VERSION} VERSION_GREATER "0.12.99")
-		message (FATAL_ERROR "Vala 0.12.x required")
+	include ("${latexila_SOURCE_DIR}/cmake/find_vala.cmake")
+	include ("${latexila_SOURCE_DIR}/cmake/use_vala.cmake")
+
+	set (_vala_main_version "0.12")
+	set (_vala_min_version "0.12.1")
+
+	find_vala (${_vala_main_version})
+
+	if ((NOT VALA_FOUND) OR
+	    ("${VALA_VERSION}" VERSION_LESS "${_vala_min_version}"))
+		message (FATAL_ERROR
+			"Vala ${_vala_main_version}.x >= ${_vala_min_version} required")
 	endif ()
-	include (${VALA_USE_FILE})
 endif ()
 
 find_package (PkgConfig)
diff --git a/cmake/find_vala.cmake b/cmake/find_vala.cmake
new file mode 100644
index 0000000..f999b03
--- /dev/null
+++ b/cmake/find_vala.cmake
@@ -0,0 +1,53 @@
+# The purpose of this function is to use the right binary "valac-X.Y" directly.
+# For distributions like Gentoo which permits to install several Vala versions
+# in parallel, it's a lot easier for the packaging.
+#
+# 'version_required' must have the pattern "X.Y". For example "0.12", but not
+# "0.12.1".
+#
+# If a minimum version is required, for example the "0.12.1", then it must be
+# checked outside this function, with the VALA_VERSION variable:
+#
+#	if ((NOT VALA_FOUND) OR
+#	    ("${VALA_VERSION}" VERSION_LESS "0.12.1"))
+#		message (FATAL_ERROR "Vala 0.12.x >= 0.12.1 required")
+#	endif ()
+#
+# VALA_FOUND is always set.
+# If VALA_FOUND is true, then VALA_EXECUTABLE and VALA_VERSION are also set.
+#
+# TODO:
+# To be more generic, the function should accept several versions, for example
+# "0.12" and "0.14".  It will first search the 0.14 version, and then the 0.12
+# if the 0.14 is not found.
+
+function (find_vala version_required)
+
+	# Search for the valac executable in the usual system paths
+	find_program (_vala_executable "valac-${version_required}")
+
+	if (_vala_executable)
+		# HACK: be able to use the variable where the function is called.
+		# It would be better to do something cleaner, for instance return the value...
+		set (VALA_EXECUTABLE ${_vala_executable} PARENT_SCOPE)
+		mark_as_advanced (VALA_EXECUTABLE)
+
+		set (VALA_FOUND true PARENT_SCOPE)
+		mark_as_advanced (VALA_FOUND)
+
+		# Determine the valac version
+		execute_process (COMMAND ${_vala_executable} --version
+			OUTPUT_VARIABLE _vala_version)
+		string (REGEX MATCH "[.0-9]+" _vala_version "${_vala_version}")
+
+		set (VALA_VERSION ${_vala_version} PARENT_SCOPE)
+		mark_as_advanced (VALA_VERSION)
+
+		message (STATUS "Vala ${_vala_version} found")
+	else ()
+		set (VALA_FOUND false PARENT_SCOPE)
+		mark_as_advanced (VALA_FOUND)
+
+		message (STATUS "Vala ${version_required} not found")
+	endif ()
+endfunction ()
diff --git a/cmake/vala/UseVala.cmake b/cmake/use_vala.cmake
similarity index 95%
rename from cmake/vala/UseVala.cmake
rename to cmake/use_vala.cmake
index 352921c..436d1d0 100644
--- a/cmake/vala/UseVala.cmake
+++ b/cmake/use_vala.cmake
@@ -1,5 +1,5 @@
 ##
-# Compile vala files to their c equivalents for further processing. 
+# Compile vala files to their c equivalents for further processing.
 #
 # The "vala_precompile" function takes care of calling the valac executable on
 # the given source to produce c files which can then be processed further using
@@ -76,17 +76,17 @@
 ##
 # Copyright 2009-2010 Jakob Westhoff. All rights reserved.
 # Copyright 2010-2011 Daniel Pfeifer
-# 
+#
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions are met:
-# 
+#
 #    1. Redistributions of source code must retain the above copyright notice,
 #       this list of conditions and the following disclaimer.
-# 
+#
 #    2. Redistributions in binary form must reproduce the above copyright notice,
 #       this list of conditions and the following disclaimer in the documentation
 #       and/or other materials provided with the distribution.
-# 
+#
 # THIS SOFTWARE IS PROVIDED BY JAKOB WESTHOFF ``AS IS'' AND ANY EXPRESS OR
 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
@@ -97,7 +97,7 @@
 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-# 
+#
 # The views and conclusions contained in the software and documentation are those
 # of the authors and should not be interpreted as representing official policies,
 # either expressed or implied, of Jakob Westhoff
@@ -159,21 +159,21 @@ function(vala_precompile output)
         list(APPEND header_arguments "--internal-header=${DIRECTORY}/${ARGS_GENERATE_HEADER}_internal.h")
     endif(ARGS_GENERATE_HEADER)
 
-    add_custom_command(OUTPUT ${out_files} 
-    COMMAND 
-        ${VALA_EXECUTABLE} 
-    ARGS 
-        "-C" 
-        ${header_arguments} 
+    add_custom_command(OUTPUT ${out_files}
+    COMMAND
+        ${VALA_EXECUTABLE}
+    ARGS
+        "-C"
+        ${header_arguments}
         ${vapi_arguments}
-        "-b" ${CMAKE_CURRENT_SOURCE_DIR} 
-        "-d" ${DIRECTORY} 
-        ${vala_pkg_opts} 
-        ${ARGS_OPTIONS} 
-        ${in_files} 
+        "-b" ${CMAKE_CURRENT_SOURCE_DIR}
+        "-d" ${DIRECTORY}
+        ${vala_pkg_opts}
+        ${ARGS_OPTIONS}
+        ${in_files}
         ${custom_vapi_arguments}
-    DEPENDS 
-        ${in_files} 
+    DEPENDS
+        ${in_files}
         ${ARGS_CUSTOM_VAPIS}
     )
     set(${output} ${out_files} PARENT_SCOPE)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]