Advertisement
rotrevrep

find vala

Apr 4th, 2014
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CMake 5.48 KB | None | 0 0
  1. #
  2. # cmake/vala/FindVala.cmake
  3. #
  4. ##
  5. # Find module for the Vala compiler (valac)
  6. #
  7. # This module determines whether a Vala compiler is installed on the current
  8. # system and where its executable is.
  9. #
  10. # Call the module using "find_package(Vala) from within your CMakeLists.txt.
  11. #
  12. # The following variables will be set after an invocation:
  13. #
  14. #  VALA_FOUND       Whether the vala compiler has been found or not
  15. #  VALA_EXECUTABLE  Full path to the valac executable if it has been found
  16. #  VALA_VERSION     Version number of the available valac
  17. #
  18. #  VALA_SHORTVER    Short version of valac (major.minor). Round up development
  19. #                   versions. E.g. 0.19.1 -> 0.20, 0.20.1 -> 0.20
  20. #  VALA_LIBPKG      Name of libvala library (libvala-${VALA_SHORTVER}).
  21. #  VALA_VAPIDIR     Vapi directory path.
  22. #  VALA_DATADIR     Path to libvala data directory. E.g. /usr/share/libvala-0.20
  23. #  VALA_VAPIGEN     Path to vapigen executable.
  24. #  VALA_GEN_INTROSPECT  Path to version specific gen-introspect executable.
  25. #  VALA_VALA_GEN_INTROSPECT  Path to version independent gen-introspect
  26. #                   executable.
  27. #
  28. ##
  29.  
  30. # Copyright (C) 2013, Valama development team
  31. #
  32. # Valama is free software: you can redistribute it and/or modify it
  33. # under the terms of the GNU General Public License as published by the
  34. # Free Software Foundation, either version 3 of the License, or
  35. # (at your option) any later version.
  36. #
  37. # Valama is distributed in the hope that it will be useful, but
  38. # WITHOUT ANY WARRANTY; without even the implied warranty of
  39. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  40. # See the GNU General Public License for more details.
  41. #
  42. # You should have received a copy of the GNU General Public License along
  43. # with this program.  If not, see <http://www.gnu.org/licenses/>.
  44. #
  45. ##
  46. # Copyright 2009-2010 Jakob Westhoff. All rights reserved.
  47. # Copyright 2010-2011 Daniel Pfeifer
  48. #
  49. # Redistribution and use in source and binary forms, with or without
  50. # modification, are permitted provided that the following conditions are met:
  51. #
  52. #    1. Redistributions of source code must retain the above copyright notice,
  53. #       this list of conditions and the following disclaimer.
  54. #
  55. #    2. Redistributions in binary form must reproduce the above copyright notice,
  56. #       this list of conditions and the following disclaimer in the documentation
  57. #       and/or other materials provided with the distribution.
  58. #
  59. # THIS SOFTWARE IS PROVIDED BY JAKOB WESTHOFF ``AS IS'' AND ANY EXPRESS OR
  60. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  61. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  62. # EVENT SHALL JAKOB WESTHOFF OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  63. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  64. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  65. # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  66. # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  67. # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  68. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  69. #
  70. # The views and conclusions contained in the software and documentation are those
  71. # of the authors and should not be interpreted as representing official policies,
  72. # either expressed or implied, of Jakob Westhoff
  73. ##
  74.  
  75. # Search for the valac executable in the usual system paths.
  76. find_program(VALA_EXECUTABLE NAMES "valac-0.26" "valac-0.24" "valac-0.22" "valac-0.20" "valac")
  77. mark_as_advanced(VALA_EXECUTABLE)
  78.  
  79. # Determine the valac version
  80. if(VALA_EXECUTABLE)
  81.   execute_process(
  82.     COMMAND
  83.       "${VALA_EXECUTABLE}" "--version"
  84.     OUTPUT_VARIABLE
  85.       VALA_VERSION
  86.     OUTPUT_STRIP_TRAILING_WHITESPACE
  87.   )
  88.   string(REPLACE "Vala " "" VALA_VERSION "${VALA_VERSION}")
  89.   string(REPLACE "." ";" VALA_LIST "${VALA_VERSION}")
  90.   list(GET VALA_LIST 0 maj_ver)
  91.   list(GET VALA_LIST 1 min_ver)
  92.   list(GET VALA_LIST 2 rev_ver)
  93.   math(EXPR is_odd "${min_ver} % 2")
  94.   list(LENGTH VALA_LIST len)
  95.   if((${is_odd} EQUAL 1))
  96.     math(EXPR min_ver "${min_ver} + 1")
  97.   elseif(len GREATER 3)
  98.     math(EXPR min_ver "${min_ver} + 2")
  99.   endif()
  100.   set(VALA_SHORTVER "${maj_ver}.${min_ver}" CACHE INTERNAL "")
  101.   if(NOT "${maj_ver}" STREQUAL "" AND NOT "${min_ver}" STREQUAL "")
  102.     set(VALA_LIBPKG "libvala-${VALA_SHORTVER}" CACHE INTERNAL "")
  103.  
  104.     find_package(PkgConfig)
  105.     pkg_check_modules("VALA" REQUIRED "${VALA_LIBPKG}")
  106.     _pkgconfig_invoke("${VALA_LIBPKG}" "VALA" VAPIDIR "" "--variable=vapidir")
  107.     _pkgconfig_invoke("${VALA_LIBPKG}" "VALA" DATADIR "" "--variable=datadir")
  108.     set(VALA_DATADIR "${VALA_DATADIR}/vala" CACHE INTERNAL "")
  109.     _pkgconfig_invoke("${VALA_LIBPKG}" "VALA" VAPIGEN "" "--variable=vapigen")
  110.     _pkgconfig_invoke("${VALA_LIBPKG}" "VALA" GEN_INTROSPECT "" "--variable=gen_introspect")
  111.     _pkgconfig_invoke("${VALA_LIBPKG}" "VALA" VALA_GEN_INTROSPECT "" "--variable=vala_gen_introspect")
  112.   endif()
  113. endif()
  114.  
  115. # Handle the QUIETLY and REQUIRED arguments, which may be given to the find call.
  116. # Furthermore set VALA_FOUND to TRUE if Vala has been found (aka.
  117. # VALA_EXECUTABLE etc. are set)
  118.  
  119. include(FindPackageHandleStandardArgs)
  120. find_package_handle_standard_args(Vala
  121.   REQUIRED_VARS
  122.     VALA_EXECUTABLE
  123.     VALA_SHORTVER
  124.     VALA_LIBPKG
  125.     VALA_VAPIDIR
  126.     VALA_DATADIR
  127.     VALA_VAPIGEN
  128.     VALA_GEN_INTROSPECT
  129.     VALA_VALA_GEN_INTROSPECT
  130.   VERSION_VAR
  131.     VALA_VERSION
  132. )
  133.  
  134. # vim: set ai ts=2 sts=2 et sw=2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement