From 7cb304774fdeef0b2a674aaa54d394872512335a Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Sat, 28 Aug 2021 16:15:23 +0200 Subject: GIR and Vala bindings: Properly detect GObjectIntrospection and Vala and disable GIR and Vala if not found. --- CMakeLists.txt | 15 ++++++++++++ src/CMakeLists.txt | 66 +++++++++++++++++++++++++++------------------------- tests/CMakeLists.txt | 15 +++++++----- 3 files changed, 58 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 751bf36..4dfc038 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,10 @@ pkg_check_modules( ) include_directories(${URLDISPATCHER_INCLUDE_DIRS}) +# for GIR and Vala bindings +find_package (GObjectIntrospection QUIET) +find_package (Vala QUIET) + set(CC_WARNING_ARGS " -Wall -pedantic -Wextra -Wno-missing-field-initializers") add_subdirectory(src) @@ -76,3 +80,14 @@ endif() message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}") message(STATUS "Unit tests: ${ENABLE_TESTS}") message(STATUS "Build with -Werror: ${ENABLE_WERROR}") + +if (INTROSPECTION_FOUND) + message(STATUS "Build GObjectIntrospection: YES") + if (VALA_COMPILER) + message(STATUS "Build Vala bindings: YES") + else() + message(STATUS "Build Vala bindings: NO") + endif() +else() + message(STATUS "Build GObjectIntrospection: NO") +endif() \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 637ce9f..39682a7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,41 +30,43 @@ install(TARGETS ayatana-common DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}) # AyatanaCommon.gir -find_package(GObjectIntrospection REQUIRED QUIET) - -add_custom_command( - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.gir" - DEPENDS "ayatana-common" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND - ${INTROSPECTION_SCANNER} - utils.c utils.h - --namespace=AyatanaCommon - --c-include=ayatana/common/utils.h - --quiet - --warn-all - --include=GLib-2.0 - --library="ayatana-common" - --library-path=${CMAKE_CURRENT_BINARY_DIR} - --output "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.gir" -) - -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.gir" DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/gir-1.0") +if (INTROSPECTION_FOUND) + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.gir" + DEPENDS "ayatana-common" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND + ${INTROSPECTION_SCANNER} + utils.c utils.h + --namespace=AyatanaCommon + --c-include=ayatana/common/utils.h + --quiet + --warn-all + --include=GLib-2.0 + --library="ayatana-common" + --library-path=${CMAKE_CURRENT_BINARY_DIR} + --output "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.gir" + ) + + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.gir" DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/gir-1.0") # AyatanaCommon.vapi -find_package(Vala REQUIRED QUIET) + if (VALA_COMPILER) + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.vapi" + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.gir" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND + ${VAPI_GEN} + --library=AyatanaCommon + AyatanaCommon.gir + ) -add_custom_command( - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.vapi" - DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.gir" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND - ${VAPI_GEN} - --library=AyatanaCommon - AyatanaCommon.gir -) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.vapi" DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/vala/vapi") -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.vapi" DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/vala/vapi") + add_custom_target("src" ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.vapi") -add_custom_target("src" ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/AyatanaCommon.vapi") + endif() + +endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ecb3c12..002e4db 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -56,10 +56,13 @@ add_custom_command( # tst_utils_vala -add_executable("tst_utils_vala" "${CMAKE_CURRENT_BINARY_DIR}/tst_utils.c") -target_include_directories("tst_utils_vala" PUBLIC "${GLIB_INCLUDE_DIRS};${CMAKE_BINARY_DIR}/src") -target_link_libraries("tst_utils_vala" "${GLIB_LIBRARIES} -layatana-common -L${CMAKE_BINARY_DIR}/src") -target_link_directories("tst_utils_vala" PUBLIC "${CMAKE_BINARY_DIR}/src") -add_dependencies("tst_utils_vala" "src") +if (VALA_COMPILER) -add_test(NAME "TstUtilsVala" COMMAND "${CMAKE_CURRENT_BINARY_DIR}/tst_utils_vala" "${CMAKE_CURRENT_BINARY_DIR}") + add_executable("tst_utils_vala" "${CMAKE_CURRENT_BINARY_DIR}/tst_utils.c") + target_include_directories("tst_utils_vala" PUBLIC "${GLIB_INCLUDE_DIRS};${CMAKE_BINARY_DIR}/src") + target_link_libraries("tst_utils_vala" "${GLIB_LIBRARIES} -layatana-common -L${CMAKE_BINARY_DIR}/src") + target_link_directories("tst_utils_vala" PUBLIC "${CMAKE_BINARY_DIR}/src") + add_dependencies("tst_utils_vala" "src") + + add_test(NAME "TstUtilsVala" COMMAND "${CMAKE_CURRENT_BINARY_DIR}/tst_utils_vala" "${CMAKE_CURRENT_BINARY_DIR}") +endif() -- cgit v1.2.3