diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,9 +7,7 @@ project(Kexi VERSION ${PROJECT_VERSION}) include(KexiAddTests) -include(KexiAddExamples) kexi_add_tests(OFF) -kexi_add_examples(OFF) # ECM include(ECMAddAppIcon) @@ -122,20 +120,21 @@ -DQT_USE_QSTRINGBUILDER ) -# only with COMPILING_TESTS definition will all the FOO_TEST_EXPORT macros do something -# TODO: check if this can be moved to only those places which make use of it, -# to reduce global compiler definitions that would trigger a recompile of -# everything on a change (like adding/removing tests to/from the build) -macro_bool_to_01(BUILD_TESTING COMPILING_TESTS) - # overcome some platform incompatibilities if(WIN32) find_package(KDEWin REQUIRED) endif() # set custom Kexi plugin installdir set(KEXI_PLUGIN_INSTALL_DIR ${PLUGIN_INSTALL_DIR}/${KEXI_BASE_PATH}) +simple_option(BUILD_EXAMPLES "Build and install examples" ON) + +macro_bool_to_01(BUILD_EXAMPLES COMPILING_EXAMPLES) + +# set custom Kexi examples installdir +set(KEXI_EXAMPLES_INSTALL_DIR ${SHARE_INSTALL_PREFIX}/examples/${KEXI_BASE_PATH}) + # TEMPORARY: for initial Qt5/KF5 build porting phase deprecation warnings are only annoying noise # remove once code porting phase starts, perhaps first locally in product subdirs #if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUC) diff --git a/cmake/modules/KexiAddExamples.cmake b/cmake/modules/KexiAddExamples.cmake deleted file mode 100644 --- a/cmake/modules/KexiAddExamples.cmake +++ /dev/null @@ -1,27 +0,0 @@ -# Additional CMake macros -# -# Copyright (C) 2015-2017 Jarosław Staniek -# -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. - -if(__kexi_add_examples) - return() -endif() -set(__kexi_add_examples YES) - -include(KexiAddSimpleOption) - -# Adds BUILD_EXAMPLES option to enable examples. If enabled, build in examples/ subdirectory -# is enabled. If optional argument ARG1 is ON, building examples will be ON by default. -# Otherwise building examples will be OFF. ARG1 is OFF by default. -macro(kexi_add_examples) - set(_SET ${ARGV0}) - if (NOT "${_SET}" STREQUAL ON) - set(_SET OFF) - endif() - simple_option(BUILD_EXAMPLES "Build example applications" ${_SET}) - if (BUILD_EXAMPLES AND EXISTS ${CMAKE_SOURCE_DIR}/examples) - add_subdirectory(examples) - endif() -endmacro() diff --git a/cmake/modules/KexiAddTests.cmake b/cmake/modules/KexiAddTests.cmake --- a/cmake/modules/KexiAddTests.cmake +++ b/cmake/modules/KexiAddTests.cmake @@ -13,6 +13,7 @@ set(__kexi_add_tests YES) include(KexiAddSimpleOption) +include(MacroBoolTo01) # Adds BUILD_TESTING option to enable all kinds of tests. If enabled, build in autotests/ # and tests/ subdirectory is enabled. If optional argument ARG1 is ON, building tests will @@ -34,4 +35,10 @@ set(BUILD_COVERAGE OFF) simple_option(BUILD_COVERAGE "Build test coverage (disabled because BUILD_TESTING is OFF)" OFF) endif() + + # only with COMPILING_TESTS definition will all the FOO_TEST_EXPORT macros do something + # TODO: check if this can be moved to only those places which make use of it, + # to reduce global compiler definitions that would trigger a recompile of + # everything on a change (like adding/removing tests to/from the build) + macro_bool_to_01(BUILD_TESTING COMPILING_TESTS) endmacro() diff --git a/cmake/modules/KexiMacros.cmake b/cmake/modules/KexiMacros.cmake --- a/cmake/modules/KexiMacros.cmake +++ b/cmake/modules/KexiMacros.cmake @@ -206,17 +206,22 @@ endif() # Sets file or directory read-only for all (non-root) users. -# The _path should exist. +# The _path should exist. If it is not absolute, ${CMAKE_CURRENT_SOURCE_DIR} path is prepended. # TODO: implement for WIN32 macro(kexi_set_file_read_only _path) if(NOT kexi_chmod_program) return() endif() - if(NOT EXISTS ${_path}) - message(FATAL_ERROR "File or directory \"${_path}\" does not exist") + if(IS_ABSOLUTE ${_path}) + set(_fullpath ${_path}) + else() + set(_fullpath ${CMAKE_CURRENT_SOURCE_DIR}/${_path}) + endif() + if(NOT EXISTS ${_fullpath}) + message(FATAL_ERROR "File or directory \"${_fullpath}\" does not exist") return() endif() - set(_command "${kexi_chmod_program}" a-w "${_path}") + set(_command "${kexi_chmod_program}" a-w "${_fullpath}") execute_process( COMMAND ${_command} RESULT_VARIABLE _result @@ -227,3 +232,11 @@ message(FATAL_ERROR "Command failed (${_result}): ${_command}\n\nOutput:\n${_output}") endif() endmacro() + +# Adds example KEXI project (.kexi file) +# - sets it read-only +# - installs to SHARE/examples/VERSION/ +macro(kexi_add_example_project _path) + kexi_set_file_read_only(${_path}) + install(FILES ${_path} DESTINATION ${KEXI_EXAMPLES_INSTALL_DIR}) +endmacro() diff --git a/src/config-kexi.h.cmake b/src/config-kexi.h.cmake --- a/src/config-kexi.h.cmake +++ b/src/config-kexi.h.cmake @@ -62,6 +62,10 @@ //! @brief if defined, tests are enabled #cmakedefine COMPILING_TESTS +//! @def COMPILING_EXAMPLES +//! @brief if defined, examples are enabled and installed +#cmakedefine COMPILING_EXAMPLES + //! @def KEXI_DEBUG_GUI //! @brief If defined, a debugging GUI for Kexi is enabled #cmakedefine KEXI_DEBUG_GUI diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt --- a/src/examples/CMakeLists.txt +++ b/src/examples/CMakeLists.txt @@ -1 +1 @@ -kexi_set_file_read_only("${CMAKE_CURRENT_SOURCE_DIR}/Simple_Database.kexi") +kexi_add_example_project(Simple_Database.kexi)