jsdoc/CMakeLists.txt
authorAlan Knowles <alan@roojs.com>
Fri, 15 Feb 2019 05:02:01 +0000 (13:02 +0800)
committerAlan Knowles <alan@roojs.com>
Fri, 15 Feb 2019 05:02:01 +0000 (13:02 +0800)
jsdoc/CMakeLists.txt

index 61edc73..5df3cc6 100644 (file)
+#
+#
+# Library Target: linked against executable and tests.
 
-set(VALA_SRC
-    Collapse.vala 
-    CompressWhite.vala 
-    Identifier.vala 
-    Lang.vala 
-    Packer.vala 
-    ScopeParser.vala 
-    Scope.vala 
-    TextStream.vala 
-    TokenReader.vala 
-    TokenStream.vala 
-    Token.vala 
-    PackerRun.vala 
-    Walker.vala 
-    SymbolSet.vala 
-    DocBuilder.vala 
-    DocComment.vala 
-    DocParser.vala 
-    DocTag.vala 
-    PrettyPrint.vala 
-    Symbol.vala
-)
-
-
-# Vala segfaults if its output dirs are not existant. Therefore make sure they
-# are there.
-macro(make_compile_directory directory)
-       if (NOT IS_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${directory}")
-               make_directory("${CMAKE_CURRENT_BINARY_DIR}/${directory}")
-       endif (NOT IS_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${directory}")
-endmacro(make_compile_directory)
-
-## ----------- the library
+# Generate a config.vala file, which can be used for version
+# information and feature detection.
+configure_file(
+    "${CMAKE_CURRENT_SOURCE_DIR}/config.vala.in"
+    "${CMAKE_CURRENT_BINARY_DIR}/config.vala"
+    @ONLY)
+
+# You can re-type these if you prefer; putting them in variables makes
+# it easier to reuse them, and helps explain what each command needs
+# to include.
+
+# The name of the C header, without the trailing ".h"
+set(ROOJSPACKER_HEADER ${PROJECT_NAME})
+
+# These are the Vala sources you want to build your library out of.
+set(ROOJSPACKER_VALA_SOURCES
+    "${CMAKE_CURRENT_BINARY_DIR}/config.vala"
+    my_class.vala)
+
+# Any dependencies.  Note that it isn't actually necessary to add
+# glib-2.0 or gobject-2.0 (it is done implicitly), but for this
+# template project we don't actually depend on anything else, so we
+# added it for illustrative purposes.
+set(ROOJSPACKER_VALA_PACKAGES
+    glib-2.0
+    gobject-2.0)
 
+# Compile Vala -> C
 vala_precompile_target(
-        "libroojspacker-vala"
-       VALA_C
-PACKAGES 
-       gio-2.0
-       gee-0.8
-        glib-2.0
-        gobject-2.0
-        json-glib-1.0
-HEADER roojspacker-1.2.h
-VAPI roojspacker-1.2
-    ${VALA_SRC}
-)
-
-add_library(libroojspacker 
-       SHARED
-       ${VALA_C} roojspacker.h
-)
-
-add_dependencies("libroojspacker" "libroojspacker-vala")
+    "${ROOJSPACKER_LIBRARY_NAME}-vala"
+    ROOJSPACKER_C_SOURCES
+    PACKAGES ${ROOJSPACKER_VALA_PACKAGES}
+    VAPI "${CMAKE_CURRENT_BINARY_DIR}/${ROOJSPACKER_PKG_NAME}.vapi"
+    GIR "${ROOJSPACKER_GIR_NAME}.gir"
+    HEADER "${CMAKE_CURRENT_BINARY_DIR}/${ROOJSPACKER_PKG_NAME}.h"
+    ${ROOJSPACKER_VALA_SOURCES})
+
+# Compile the library.
+#
+# By default, we create and install a shared library.  If you don't
+# want to do that, you can change "SHARED" in the below function call
+# to "STATIC".
+add_library(${ROOJSPACKER_LIBRARY_NAME}
+    SHARED
+    ${ROOJSPACKER_C_SOURCES})
+
+# Make sure the Vala sources are compiled to C before attempting to
+# build the library.
+add_dependencies("${ROOJSPACKER_LIBRARY_NAME}" "${ROOJSPACKER_LIBRARY_NAME}-vala")
+
+# Generate a .gitignore
+file(WRITE  ".gitignore" "# Automatically generated by CMake, do not modify.\n")
+foreach(file
+    ".gitignore"
+    "${CMAKE_SHARED_LIBRARY_PREFIX}${ROOJSPACKER_LIBRARY_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}*"
+    "${CMAKE_STATIC_LIBRARY_PREFIX}${ROOJSPACKER_LIBRARY_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}"
+    "${CMAKE_SHARED_LIBRARY_PREFIX}${ROOJSPACKER_LIBRARY_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}.${ROOJSPACKER_VERSION_API}"
+    "${CMAKE_SHARED_LIBRARY_PREFIX}${ROOJSPACKER_LIBRARY_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}.${ROOJSPACKER_VERSION_API}.${ROOJSPACKER_VERSION_REVISION}"
+    "${ROOJSPACKER_PKG_NAME}.pc"
+    "config.vala")
+  file(APPEND ".gitignore" "/${file}\n")
+endforeach(file)
+foreach(file ${ROOJSPACKER_C_SOURCES})
+  string(REPLACE "${CMAKE_CURRENT_BINARY_DIR}/" "" file ${file})
+  file(APPEND ".gitignore" "/${file}\n")
+endforeach(file)
+
+# Define the gettext domain
+set_property (TARGET ${ROOJSPACKER_LIBRARY_NAME}
+    APPEND PROPERTY COMPILE_DEFINITIONS GETTEXT_PACKAGE="${GETTEXT_PACKAGE}")
+
+# If you don't want to build and install a shared library, comment out
+# (or remove) everything below this point.
 
 # Set the library's version information
-set_target_properties (${MY_PROJECT_LIBRARY_NAME} PROPERTIES
-    SOVERSION "1.2.1000"
-    VERSION   "1.2")
+set_target_properties (${ROOJSPACKER_LIBRARY_NAME} PROPERTIES
+    SOVERSION "${ROOJSPACKER_SOVERSION_CURRENT}.${ROOJSPACKER_SOVERSION_REVISION}.${ROOJSPACKER_SOVERSION_AGE}"
+    VERSION   "${ROOJSPACKER_SOVERSION_CURRENT}.${ROOJSPACKER_SOVERSION_REVISION}")
 
+# GObject Introspection support
+find_package(GObjectIntrospection REQUIRED)
+# Gir Repositories support
+find_file(GIREPOSITORY_FILE GObject-2.0.gir /usr/share/gir-1.0 )
+if(GIREPOSITORY_FILE)
+else()
+    message(FATAL_ERROR "Package libgirepository-dev not found.")
+endif()
+
+# We already had valac write a GIR, now we need to compile it to a
+# typelib.
+gobject_introspection_compile(
+  "${CMAKE_CURRENT_BINARY_DIR}/${ROOJSPACKER_GIR_NAME}.typelib"
+  "${CMAKE_CURRENT_BINARY_DIR}/${ROOJSPACKER_GIR_NAME}.gir")
+
+# Telling CMake you want to install a file doesn't actually get it to
+# *build* that file.  The workaround is to add a custom target which
+# is always built and depens on the file we want to install.
+add_custom_target(typelib ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${ROOJSPACKER_GIR_NAME}.typelib")
+
+# Install our typelib
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${ROOJSPACKER_GIR_NAME}.typelib"
+    DESTINATION "${GI_TYPELIB_DIR}")
+
+# Install our GIR
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${ROOJSPACKER_GIR_NAME}.gir"
+    DESTINATION "${GI_REPOSITORY_DIR}")
 
 # Install our VAPI
-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/roojspacker.vapi
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${ROOJSPACKER_PKG_NAME}.vapi
     DESTINATION ${CMAKE_INSTALL_DATADIR}/vala/vapi)
-    
-install (TARGETS "libroojspacker"
+
+# Install the library
+install (TARGETS ${ROOJSPACKER_LIBRARY_NAME}
     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}  # On Windows, the DLL goes in the same place as the executables
     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}  # This is where shared libraries (*.so on Linux, *.dynlib on OS X)
     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) # Finally, this is where static libraries (*.a) go
 
 # Install the C header
-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/roojspacker-1.2.h
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${ROOJSPACKER_PKG_NAME}.h
     DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR})
 
+# Install our VAPI
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${ROOJSPACKER_PKG_NAME}.vapi
+    DESTINATION ${CMAKE_INSTALL_DATADIR}/vala/vapi)
 
-# pkg-config file..    
+# Generate and install a pkg-config file
 configure_file (
-    "${CMAKE_CURRENT_SOURCE_DIR}/../roojspacker-1.2.pc.in"
-    "${CMAKE_CURRENT_BINARY_DIR}/roojspacker-1.2.pc"
+    "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in"
+    "${CMAKE_CURRENT_BINARY_DIR}/${ROOJSPACKER_PKG_NAME}.pc"
     @ONLY)
-    
-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/roojspacker-1.2.pc
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${ROOJSPACKER_PKG_NAME}.pc
   DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
-     
+
+# Generate documentation
+find_package(Valadoc)
+if(${VALADOC_FOUND})
+    valadoc_generate(html
+        PACKAGE_NAME ${ROOJSPACKER_PKG_NAME}
+        PACKAGE_VERSION "${ROOJSPACKER_VERSION_MAJOR}.${ROOJSPACKER_VERSION_MINOR}.${ROOJSPACKER_VERSION_REVISION}"
+        SOURCES ${ROOJSPACKER_VALA_SOURCES}
+        PACKAGES ${ROOJSPACKER_VALA_PACKAGES})
+    valadoc_generate(devhelp
+        DOCLET devhelp
+        PACKAGE_NAME ${ROOJSPACKER_PKG_NAME}
+        PACKAGE_VERSION "${ROOJSPACKER_VERSION_MAJOR}.${ROOJSPACKER_VERSION_MINOR}.${ROOJSPACKER_VERSION_REVISION}"
+        SOURCES ${ROOJSPACKER_VALA_SOURCES}
+        PACKAGES ${ROOJSPACKER_VALA_PACKAGES})
+
+    install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/devhelp/${ROOJSPACKER_PKG_NAME}"
+        DESTINATION "${CMAKE_INSTALL_DATADIR}/devhelp/books")
+    add_custom_target(doc ALL
+        DEPENDS html devhelp)
+endif()
\ No newline at end of file