aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt61
1 files changed, 44 insertions, 17 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d2d8c218..faaa6a34 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.1)
+cmake_minimum_required(VERSION 3.5)
project(qmatrixclient CXX)
@@ -48,11 +48,17 @@ find_package(Qt5 5.4.1 REQUIRED Network Gui Multimedia)
get_filename_component(Qt5_Prefix "${Qt5_DIR}/../../../.." ABSOLUTE)
if (GTAD_PATH)
- get_filename_component(ABS_GTAD_PATH "${GTAD_PATH}" ABSOLUTE)
+ get_filename_component(ABS_GTAD_PATH "${GTAD_PATH}" PROGRAM)
endif ()
if (MATRIX_DOC_PATH)
- get_filename_component(ABS_API_DEF_PATH "${MATRIX_DOC_PATH}/api" ABSOLUTE)
+ get_filename_component(ABS_API_DEF_PATH "${MATRIX_DOC_PATH}/api" REALPATH)
endif ()
+if (ABS_GTAD_PATH AND ABS_API_DEF_PATH)
+ if (NOT CLANG_FORMAT)
+ set(CLANG_FORMAT clang-format)
+ endif()
+ get_filename_component(ABS_CLANG_FORMAT "${CLANG_FORMAT}" PROGRAM)
+endif()
message( STATUS )
message( STATUS "=============================================================================" )
@@ -63,10 +69,15 @@ if (CMAKE_BUILD_TYPE)
endif(CMAKE_BUILD_TYPE)
message( STATUS "Using compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}" )
message( STATUS "Using Qt ${Qt5_VERSION} at ${Qt5_Prefix}" )
-if (MATRIX_DOC_PATH AND GTAD_PATH)
- message( STATUS "Generating API stubs enabled" )
+if (ABS_API_DEF_PATH AND ABS_GTAD_PATH)
+ message( STATUS "Generating API stubs enabled (use --target update-api)" )
message( STATUS " Using GTAD at ${ABS_GTAD_PATH}" )
message( STATUS " Using API files at ${ABS_API_DEF_PATH}" )
+ if (ABS_CLANG_FORMAT)
+ message( STATUS "clang-format is at ${ABS_CLANG_FORMAT}")
+ else ()
+ message( STATUS "${CLANG_FORMAT} is NOT FOUND; --target update-format-api disabled")
+ endif ()
endif ()
message( STATUS "=============================================================================" )
message( STATUS )
@@ -109,11 +120,23 @@ set(libqmatrixclient_SRCS
)
set(CSAPI_DIR csapi)
-set(FULL_CSAPI_DIR lib/${CSAPI_DIR})
-set(FULL_CSAPI_SRC_DIR ${ABS_API_DEF_PATH}/client-server)
set(ASAPI_DEF_DIR application-service/definitions)
set(ISAPI_DEF_DIR identity/definitions)
+
+foreach (D ${CSAPI_DIR} ${ASAPI_DEF_DIR} ${ISAPI_DEF_DIR})
+ aux_source_directory(lib/${D} api_SRCS)
+endforeach()
+
+# Make no mistake: CMake cannot run gtad first and then populate the list of
+# resulting api_SRCS files. In other words, placing the above foreach after
+# the custom targets definition won't bring the desired result:
+# CMake will execute it at cmake invocation and gtad will only run later
+# when building the update-api target. If you see that gtad has created
+# new files you have to re-run cmake.
+# TODO: check `file(GLOB_RECURSE ... CONFIGURE_DEPENDS)` (from CMake 3.14)
if (MATRIX_DOC_PATH AND GTAD_PATH)
+ set(FULL_CSAPI_DIR lib/${CSAPI_DIR})
+ set(FULL_CSAPI_SRC_DIR ${ABS_API_DEF_PATH}/client-server)
file(GLOB_RECURSE API_DEFS RELATIVE ${PROJECT_SOURCE_DIR}
${FULL_CSAPI_SRC_DIR}/*.yaml
${ABS_API_DEF_PATH}/${ASAPI_DEF_DIR}/*.yaml
@@ -131,20 +154,24 @@ if (MATRIX_DOC_PATH AND GTAD_PATH)
${API_DEFS}
VERBATIM
)
+ if (CLANG_FORMAT)
+ set(api_HDRS ${api_SRCS})
+ list(TRANSFORM api_HDRS REPLACE ".cpp$" ".h")
+ set(CLANG_FORMAT_ARGS -i -sort-includes -verbose)
+ add_custom_target(update-format-api
+ COMMAND ${ABS_CLANG_FORMAT} ${CLANG_FORMAT_ARGS} ${api_SRCS}
+ COMMAND ${ABS_CLANG_FORMAT} ${CLANG_FORMAT_ARGS} ${api_HDRS}
+ DEPENDS update-api
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ VERBATIM
+ SOURCES .clang-format
+ )
+ endif()
endif()
-aux_source_directory(${FULL_CSAPI_DIR} libqmatrixclient_job_SRCS)
-aux_source_directory(${FULL_CSAPI_DIR}/definitions libqmatrixclient_csdef_SRCS)
-aux_source_directory(${FULL_CSAPI_DIR}/definitions/wellknown libqmatrixclient_cswellknown_SRCS)
-aux_source_directory(lib/${ASAPI_DEF_DIR} libqmatrixclient_asdef_SRCS)
-aux_source_directory(lib/${ISAPI_DEF_DIR} libqmatrixclient_isdef_SRCS)
-
set(example_SRCS examples/qmc-example.cpp)
-add_library(QMatrixClient ${libqmatrixclient_SRCS}
- ${libqmatrixclient_job_SRCS} ${libqmatrixclient_csdef_SRCS}
- ${libqmatrixclient_cswellknown_SRCS}
- ${libqmatrixclient_asdef_SRCS} ${libqmatrixclient_isdef_SRCS})
+add_library(QMatrixClient ${libqmatrixclient_SRCS} ${api_SRCS})
set(API_VERSION "0.5")
set_property(TARGET QMatrixClient PROPERTY VERSION "${API_VERSION}.0")
set_property(TARGET QMatrixClient PROPERTY SOVERSION ${API_VERSION} )