]> git.lyx.org Git - features.git/blobdiff - development/cmake/modules/LyXMacros.cmake
Cmake build: Syntax of AC_INIT() in configure.ac changed, adapted macro
[features.git] / development / cmake / modules / LyXMacros.cmake
index a3db752f658dfe221d365dcfc3e66df57e2b17d4..2d93f46976ef3c62dbf34efff30406abffce91fa 100644 (file)
@@ -209,6 +209,7 @@ endmacro(lyx_const_touched_files)
 
 macro(LYX_OPTION_INIT)
        set(LYX_OPTIONS)
+       set(LYX_OPTION_STRINGS)
 endmacro()
 
 
@@ -244,6 +245,7 @@ macro(LYX_COMBO _name _description _default)
   set(${_lyx_name}_show_message ON)
   string(REGEX REPLACE ";" " " _use_list "${_combo_list}")
   set(${_lyx_name}_description "${_description} (${_use_list})")
+  list(APPEND LYX_OPTION_STRINGS ${_lyx_name})
   # Now check the value
   list(FIND _combo_list ${${_lyx_name}} _idx)
   if (_idx LESS 0)
@@ -251,6 +253,26 @@ macro(LYX_COMBO _name _description _default)
   endif()
 endmacro()
 
+macro(LYX_STRING _name _description _default)
+  set(_lyx_name "LYX_${_name}")
+  list(APPEND LYX_OPTIONS ${_lyx_name})
+  set(${_lyx_name}_show_message ON)
+  set(${_lyx_name}_description "${_description}")
+  list(APPEND LYX_OPTION_STRINGS ${_lyx_name})
+  # Now check the value
+  # Should not contain ' '
+  set(tmp_lyx_name ${${_lyx_name}})
+  if (NOT "${${_lyx_name}}" STREQUAL "")
+    if (NOT "${tmp_lyx_name}" MATCHES "^\\..*$")
+      set(tmp_lyx_name ".${tmp_lyx_name}")
+    endif()
+    if (NOT "${tmp_lyx_name}" MATCHES "^\\.[a-zA-Z_0-9\\.]+$")
+      message(FATAL_ERROR "Invalid string for lyx suffix (${tmp_lyx_name})")
+    endif()
+  endif()
+  set(${_lyx_name} "${tmp_lyx_name}" CACHE STRING "${_description}" FORCE)
+endmacro()
+
 macro(LYX_OPTION_LIST_ALL)
        if(UNIX)
                set(run_cmake ${CMAKE_BINARY_DIR}/run_cmake.sh)
@@ -266,18 +288,22 @@ macro(LYX_OPTION_LIST_ALL)
        file(APPEND ${run_cmake} " -G\"${CMAKE_GENERATOR}\"  ${cont}")
        foreach(_option ${LYX_OPTIONS})
                if(${_option}_show_message OR ${ARGV0} STREQUAL "help")
-                       string(SUBSTRING "${_option}                            " 0 25 _var)
                         get_property(_prop CACHE ${_option} PROPERTY STRINGS)
-                        if(_prop)
+                       list(FIND LYX_OPTION_STRINGS ${_option} _index)
+                       set(_type "BOOL")
+                       if (${_index} GREATER -1)
+                         #message(STATUS "${_option} is of type string")
                           set(_isset ${${_option}})
+                         set(_type "STRING")
                        elseif(${_option})
                                set(_isset ON)
                        else()
                                set(_isset OFF)
                        endif()
-                       string(SUBSTRING "${_isset}     " 0 4 _val)
-                       message(STATUS "${_var}= ${_val}   : ${${_option}_description}")
-                       file(APPEND ${run_cmake} " -D${_option}=${${_option}}  ${cont}")
+                       string(SUBSTRING "${_option}:${_type}                            " 0 35 _var)
+                       string(SUBSTRING "${_isset}           " 0 7 _val)
+                       message(STATUS "${_var}= ${_val}: ${${_option}_description}")
+                       file(APPEND ${run_cmake} " -D${_option}:${_type}=${${_option}}  ${cont}")
                endif()
        endforeach()
        file(APPEND ${run_cmake} "\n")
@@ -329,7 +355,7 @@ macro(sortlabellist listout)
     list(APPEND tmplist "${depth_${_lab}}${_lab}")
   endforeach()
   list(SORT tmplist)
-  string(REGEX REPLACE ";[0-9]+" ";" ${listout} ";${tmplist}")
+  string(REGEX REPLACE ";[-0-9]+" ";" ${listout} ";${tmplist}")
 endmacro()
 
 macro(createlabel reslabel first)
@@ -355,3 +381,116 @@ macro(lyx_target_link_libraries _target)
   endforeach()
 endmacro()
 
+# Check if python module exists
+# Idea stolen from http://public.kitware.com/pipermail/cmake/2011-January/041666.html
+function(find_python_module module)
+  string(TOUPPER ${module} module_upper)
+  if(NOT LYX_PY_${module_upper})
+    if(ARGC GREATER 1 AND ARGV1 STREQUAL "REQUIRED")
+      set(LYX_PY_${module}_FIND_REQUIRED TRUE)
+    endif()
+    # A module's location is usually a directory, but for binary modules
+    # it's a .so file.
+    execute_process(COMMAND "${LYX_PYTHON_EXECUTABLE}" "-c"
+      "import re, ${module}; print(re.compile('/__init__.py.*').sub('',${module}.__file__))"
+      RESULT_VARIABLE _${module}_status
+      OUTPUT_VARIABLE _${module}_location
+      ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
+    if(NOT _${module}_status)
+      set(LYX_PY_${module_upper} ${_${module}_location} CACHE STRING
+        "Location of Python module ${module}")
+    endif()
+  endif()
+  find_package_handle_standard_args(LYX_PY_${module} DEFAULT_MSG LYX_PY_${module_upper})
+endfunction(find_python_module)
+
+macro(setstripped _varname)
+        if(${ARGC} GREATER 1)
+                string(STRIP "${ARGV1}" _v)
+                if (_v MATCHES "^\\[\(.+\)\\]$")
+                  set(_v ${CMAKE_MATCH_1})
+                endif()
+                if(USE_POSIX_PACKAGING)
+                        string(TOLOWER ${_v} ${_varname})
+                else()
+                        set(${_varname} ${_v})
+                endif()
+        else()
+                set(${_varname})
+        endif()
+endmacro(setstripped)
+
+# Determine the version and build-type
+function(determineversionandbuildtype configfile package version dirs date buildtype)
+  file(STRINGS "${configfile}" _config_lines)
+  foreach(_c_l ${_config_lines} )
+    if(_c_l MATCHES "^AC_INIT\\(\([^,]+\),\([^,]+\), *\\[\([^,]+\)\\] *,\(.*\)")
+      # Not using CMAKE_MATCH_ directly is needed, because
+      # its value is now changed inside macro setstripped
+      set(_PB ${CMAKE_MATCH_1})
+      set(_PV ${CMAKE_MATCH_2})
+      set(_PBU ${CMAKE_MATCH_3})
+      setstripped(PACKAGE_BASE ${_PB})
+      setstripped(PACKAGE_VERSION ${_PV})
+      setstripped(PACKAGE_BUGREPORT ${_PBU})
+      set(${package} ${PACKAGE_BASE} ${PACKAGE_VERSION} ${PACKAGE_BUGREPORT} PARENT_SCOPE)
+      if(PACKAGE_VERSION MATCHES "^\([0-9]+\)\\.\([0-9]+\)\(\\.\([0-9]+\)\(\\.\([0-9]+\)\)?\)?-?\([a-z]*[0-9]*\).*$")
+        set(LYX_MAJOR_VERSION ${CMAKE_MATCH_1})
+        set(LYX_MINOR_VERSION ${CMAKE_MATCH_2})
+        set(LYX_RELEASE_LEVEL ${CMAKE_MATCH_4})
+        set(LYX_RELEASE_PATCH ${CMAKE_MATCH_6})
+        set(LYX_BUILD_TYPE ${CMAKE_MATCH_7})
+        set(LYX_DIR_VER "LYX_DIR_${CMAKE_MATCH_1}${CMAKE_MATCH_2}x")
+        set(LYX_USERDIR_VER "LYX_USERDIR_${CMAKE_MATCH_1}${CMAKE_MATCH_2}x")
+        if (NOT LYX_RELEASE_LEVEL)
+          set(LYX_RELEASE_LEVEL 0)
+        endif()
+        if (NOT LYX_RELEASE_PATCH)
+          set(LYX_RELEASE_PATCH 0)
+        endif()
+        set(LYX_VERSION "${LYX_MAJOR_VERSION}.${LYX_MINOR_VERSION}")
+      endif()
+    endif()
+    if(_c_l MATCHES "^AC_SUBST\\( *LYX_DATE *, *\\[\\\"(.*)\\\"\\].*")
+      set(LYX_DATE "${CMAKE_MATCH_1}")
+    endif()
+  endforeach(_c_l)
+  set(${version} ${LYX_VERSION} ${LYX_MAJOR_VERSION} ${LYX_MINOR_VERSION} ${LYX_RELEASE_LEVEL} ${LYX_RELEASE_PATCH} PARENT_SCOPE)
+  set(${dirs} ${LYX_DIR_VER} ${LYX_USERDIR_VER} PARENT_SCOPE)
+  set(${date} ${LYX_DATE} PARENT_SCOPE)
+  if(LYX_BUILD_TYPE MATCHES "^\(dev\)$")
+    set(${buildtype} "development" PARENT_SCOPE)
+  elseif(LYX_BUILD_TYPE MATCHES "^\(alpha|beta|rc|pre\)[0-9]*$")
+    set(${buildtype} "prerelease" PARENT_SCOPE)
+  elseif(LYX_BUILD_TYPE MATCHES "^$")
+    set(${buildtype} "release" PARENT_SCOPE)
+  else()
+    set(${buildtype} "unknown" PARENT_SCOPE)
+    message(FATAL_ERROR "\"${configfile}\": Unable to determine build-type from suffix \"${LYX_BUILD_TYPE}\" in AC_INIT macro")
+  endif()
+endfunction(determineversionandbuildtype)
+
+# determine known cmake cxx_std features but only if not greater than ${max_desired}
+function(lyxgetknowncmakestd max_desired result)
+  set(tmp_list)
+  set(CXX_STD_LIST)
+  math(EXPR max_desired "${max_desired}+1")
+  if (CMAKE_VERSION VERSION_LESS "3.9")
+    list(APPEND tmp_list 98 11 14)
+  else()
+    foreach(_e ${CMAKE_CXX_COMPILE_FEATURES})
+      if (_e MATCHES "^cxx_std_\(.*)")
+        list(APPEND tmp_list ${CMAKE_MATCH_1})
+      endif()
+    endforeach()
+  endif()
+  list(REVERSE tmp_list)
+  # Filter undesired from list
+  foreach(i ${tmp_list})
+    if (i LESS ${max_desired} OR i GREATER 89)
+      list(APPEND CXX_STD_LIST ${i})
+    endif()
+  endforeach()
+  set(${result} ${CXX_STD_LIST} PARENT_SCOPE)
+endfunction()
+