Advertisement
rotrevrep

Untitled

Sep 10th, 2013
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CMake 5.92 KB | None | 0 0
  1. #
  2. # CMakeLists.txt
  3. # Copyright (C) 2012, 2013, Valama development team
  4. #
  5. # Valama is free software: you can redistribute it and/or modify it
  6. # under the terms of the GNU General Public License as published by the
  7. # Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # Valama is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. # See the GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License along
  16. # with this program.  If not, see <http://www.gnu.org/licenses/>.
  17. #
  18.  
  19. cmake_minimum_required(VERSION "2.8.4")
  20.  
  21. include("${CMAKE_SOURCE_DIR}/cmake/project.cmake")
  22. include("${CMAKE_SOURCE_DIR}/cmake/Common.cmake")
  23.  
  24. project("${project_name}" C)
  25. string(TOLOWER "${project_name}" project_name_lower)
  26.  
  27. set(bindir "bin")
  28. set(datarootdir "share")
  29. set(libdir "lib")
  30. set(includedir "include")
  31. set(datadir "${datarootdir}/${project_name_lower}")
  32. set(uidir "${datadir}/ui")
  33. set(localedir "${datarootdir}/locale")
  34. set(appdir "${datarootdir}/applications")
  35. set(gsettingsdir "${datarootdir}/glib-2.0/schemas")
  36. set(pixrootdir "${datarootdir}/pixmaps")
  37. set(pixdir "${pixrootdir}/${project_name_lower}")
  38. set(docdir "${datadir}/doc")
  39. set(mandir "${datarootdir}/man")
  40. set(mimedir "${datarootdir}/mime/packages")
  41. if(CMAKE_INSTALL_PREFIX)
  42.   set(install_prefix "${CMAKE_INSTALL_PREFIX}/")
  43. else()
  44.   set(install_prefix)
  45. endif()
  46.  
  47. list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/vala")
  48. list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
  49.  
  50.  
  51. find_package(Vala "0.17" REQUIRED)
  52.  
  53. # Custom library version checks.
  54. set(valac_cond)
  55. find_package(PkgConfig)
  56. # glib-2.0
  57. pkg_check_modules(GLIB2.0 REQUIRED "glib-2.0")
  58.  
  59.  
  60. set(default_vala_flags
  61.   "--thread"
  62.   "--gresources" "ui/resources.xml"
  63.   "--target-glib" "2.38"
  64.   ${valac_cond}
  65. )
  66.  
  67. include(ValaPkgs)
  68. vala_pkgs(VALA_C
  69.   PACKAGES
  70.     ${required_pkgs}
  71.   OPTIONAL
  72.     ${optional_pkgs}
  73.   SRCFILES
  74.     ${srcfiles}
  75.   VAPIS
  76.     ${vapifiles}
  77.   OPTIONS
  78.     ${default_vala_flags}
  79. )
  80.  
  81. add_custom_command(OUTPUT rc.c
  82.     COMMAND
  83.     glib-compile-resources --sourcedir="${CMAKE_CURRENT_SOURCE_DIR}/ui" "${CMAKE_CURRENT_SOURCE_DIR}/ui/resources.xml" --target=rc.c --generate-source
  84.     COMMENT "compile resources")
  85.  
  86. # Set common C-macros.
  87. add_definitions(-DPACKAGE_NAME="${project_name}")
  88. add_definitions(-DPACKAGE_VERSION="${${project_name}_VERSION}")
  89. if(project_root)
  90.   add_definitions(-DGETTEXT_PACKAGE="${project_root}")
  91. else()
  92.   add_definitions(-DGETTEXT_PACKAGE="${project_name_lower}")
  93. endif()
  94. add_definitions(-DPACKAGE_DATA_DIR="${install_prefix}${datadir}")
  95. add_definitions(-DPACKAGE_UI_DIR="${install_prefix}${uidir}")
  96. add_definitions(-DLOCALE_DIR="${install_prefix}${localedir}")
  97. add_definitions(-DPIXMAP_DIR="${install_prefix}${pixdir}")
  98. add_definitions(-DVALA_VERSION="${VALA_SHORTVER}")
  99. add_executable("${project_name_lower}" ${VALA_C} rc.c)
  100. target_link_libraries("${project_name_lower}" ${PROJECT_LDFLAGS})
  101. add_definitions(${PROJECT_C_FLAGS})
  102. install(TARGETS ${project_name_lower} DESTINATION "${bindir}")
  103.  
  104. # Install user interface files if used and copy them to build directory.
  105. set(uifiles_build)
  106. foreach(uifile ${uifiles})
  107.   add_custom_command(
  108.     OUTPUT
  109.       "${CMAKE_CURRENT_BINARY_DIR}/${uifile}"
  110.     COMMAND
  111.       "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/${uifile}" "${CMAKE_CURRENT_BINARY_DIR}/${uifile}"
  112.     DEPENDS
  113.       "${CMAKE_CURRENT_SOURCE_DIR}/${uifile}"
  114.     COMMENT ""
  115.   )
  116.   list(APPEND uifiles_build "${CMAKE_CURRENT_BINARY_DIR}/${uifile}")
  117.   install(FILES ${uifile} DESTINATION "${uidir}")
  118. endforeach()
  119. add_custom_target("ui_copy_${project_name_lower}" DEPENDS ${uifiles_build})
  120. add_dependencies("${project_name_lower}" "ui_copy_${project_name_lower}")
  121.  
  122. # Uninstall target
  123. add_custom_target(uninstall
  124.   COMMAND
  125.     "${CMAKE_COMMAND}" -D "CUSTOM_SOURCE_DIR:FILEPATH=${CMAKE_SOURCE_DIR}"
  126.                        -D "POSTREMOVE_HOOK:BOOL=${POSTINSTALL_HOOK}"
  127.                        -D "GSETTINGSDIR:FILEPATH=${install_prefix}${gsettingsdir}"
  128.                        -P "${CMAKE_SOURCE_DIR}/cmake/SimpleUninstall.cmake"
  129. )
  130.  
  131.  
  132. # Print some information about build.
  133. datestring(current_date "%F %T")
  134. message("")
  135. message("---------------------------------------------")
  136. message("                          ${current_date}")
  137. message("${project_name} ${${project_name}_VERSION}")
  138. message("")
  139. if(CMAKE_BUILD_TYPE)
  140.   message("Build type: ${CMAKE_BUILD_TYPE}")
  141.   string(TOUPPER "${CMAKE_BUILD_TYPE}" release_upper)
  142.   set(c_flags "${CMAKE_C_FLAGS_${release_upper}}")
  143. else()
  144.   message("Build type: Default")
  145.   set(c_flags "${CMAKE_C_FLAGS}")
  146. endif()
  147. message("")
  148. message("Installation prefix:    ${CMAKE_INSTALL_PREFIX}")
  149. base_list_to_delimited_string(vala_flags
  150.   DELIM " "
  151.   BASE_LIST "${default_vala_flags}")
  152. message("C compiler:             ${CMAKE_C_COMPILER}")
  153. message("C compiler version      ${CMAKE_C_COMPILER_VERSION}")
  154. if("${c_flags}" STREQUAL "")
  155.   set(c_flags "(none)")
  156. endif()
  157. message("C flags:                ${c_flags}")
  158. message("Vala compiler:          ${VALA_EXECUTABLE}")
  159. message("Vala compiler version:  ${VALA_VERSION}")
  160. if("${vala_flags}" STREQUAL "")
  161.   set(vala_flags "(none)")
  162. endif()
  163. message("Vala flags:             ${vala_flags}")
  164. message("GLib version:           ${GLIB2.0_VERSION}")
  165. message("")
  166. if(GETTEXT_PACKAGE_NAME)
  167.   if(GETTEXT_PACKAGE_VERSION)
  168.     message("Gettext package:        ${GETTEXT_PACKAGE_NAME} (${GETTEXT_PACKAGE_VERSION})")
  169.   else()
  170.     message("Gettext package:        ${GETTEXT_PACKAGE_NAME}")
  171.   endif()
  172. endif()
  173. if(CMAKE_VERBOSE_MAKEFILE)
  174.   message("Verbose build:          yes")
  175. else()
  176.   message("Verbose build:          no")
  177. endif()
  178. message("")
  179. message("---------------------------------------------")
  180. message("")
  181.  
  182. # vim: set ai ts=2 sts=2 et sw=2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement