From 3afc76dbaa8cb3f78516f1d1df0815cdc06ddb93 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Thu, 29 Mar 2018 09:59:04 +0300 Subject: [PATCH] Adjust CMakeLists to make dependency downloading optional --- CMakeLists.txt | 120 ++++++++++++++------------------------ cmake/CompilerFlags.cmake | 25 ++++++++ cmake/LMDB.cmake | 29 +++++++++ cmake/LMDBXX.cmake | 4 +- cmake/MatrixStructs.cmake | 16 ++--- cmake/Translations.cmake | 23 ++++++++ cmake/Tweeny.cmake | 4 +- 7 files changed, 127 insertions(+), 94 deletions(-) create mode 100644 cmake/CompilerFlags.cmake create mode 100644 cmake/LMDB.cmake create mode 100644 cmake/Translations.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 7931ee6f..1f2badd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,26 +31,7 @@ add_project_meta(META_FILES_TO_INCLUDE) # # LMDB # -if(APPVEYOR_BUILD) - set(LMDB_VERSION "LMDB_0.9.21") - set(NTDLIB "C:/WINDDK/7600.16385.1/lib/win7/amd64/ntdll.lib") - - execute_process( - COMMAND git clone --depth=1 --branch ${LMDB_VERSION} https://github.com/LMDB/lmdb) - - set(LMDB_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/lmdb/libraries/liblmdb) - - add_library(lmdb - ${CMAKE_SOURCE_DIR}/lmdb/libraries/liblmdb/lmdb.h - ${CMAKE_SOURCE_DIR}/lmdb/libraries/liblmdb/mdb.c - ${CMAKE_SOURCE_DIR}/lmdb/libraries/liblmdb/midl.h - ${CMAKE_SOURCE_DIR}/lmdb/libraries/liblmdb/midl.c) -else() - find_path (LMDB_INCLUDE_DIR NAMES lmdb.h PATHS "$ENV{LMDB_DIR}/include") - find_library (LMDB_LIBRARY NAMES lmdb PATHS "$ENV{LMDB_DIR}/lib" ) - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(LMDB DEFAULT_MSG LMDB_INCLUDE_DIR LMDB_LIBRARY) -endif() +include(LMDB) # # Discover Qt dependencies. @@ -76,10 +57,10 @@ endif(Qt5Widgets_FOUND) # Set up compiler flags. # set(CMAKE_C_COMPILER gcc) - set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) +include(CompilerFlags) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING @@ -109,31 +90,6 @@ cmake_host_system_information(RESULT BUILD_HOST QUERY HOSTNAME) set(BUILD_USER $ENV{USER}) configure_file(cmake/version.hpp config/version.hpp) -if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ - -Wall \ - -Wextra \ - -Werror \ - -pipe \ - -pedantic \ - -Wunreachable-code") - - if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") - execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) - - if (GCC_VERSION VERSION_GREATER 4.9) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always" ) - endif() - endif() - - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always" ) - endif() -endif() - -if(NOT APPLE AND NOT MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") -endif() # # Declare source and header files. @@ -216,30 +172,46 @@ set(SRC_FILES src/main.cc ) +# ExternalProject dependencies +set(EXTERNAL_PROJECT_DEPS "") + # # matrix-structs # -include(MatrixStructs) -include_directories(${MATRIX_STRUCTS_INCLUDE_DIRS}) +find_library(MATRIX_STRUCTS_LIBRARY + NAMES matrix_structs + PATHS ${MATRIX_STRUCTS_ROOT} + ${MATRIX_STRUCTS_ROOT}/lib + ${MATRIX_STRUCTS_ROOT}/lib/static) + +if(NOT MATRIX_STRUCTS_LIBRARY) + include(MatrixStructs) + set(EXTERNAL_PROJECT_DEPS ${EXTERNAL_PROJECT_DEPS} MatrixStructs) +endif() +include_directories(SYSTEM ${MATRIX_STRUCTS_INCLUDE_DIR}) # -# libtweeny +# tweeny # -include(Tweeny) -include_directories(${TWEENY_INCLUDE_DIRS}) +if(NOT TWEENY_INCLUDE_DIR) + include(Tweeny) + set(EXTERNAL_PROJECT_DEPS ${EXTERNAL_PROJECT_DEPS} Tweeny) +endif() +include_directories(SYSTEM ${TWEENY_INCLUDE_DIR}) # # lmdbxx # -include(LMDBXX) -include_directories(${LMDBXX_INCLUDE_DIRS}) +if(NOT LMDBXX_INCLUDE_DIR) + include(LMDBXX) + set(EXTERNAL_PROJECT_DEPS ${EXTERNAL_PROJECT_DEPS} lmdbxx) +endif() +include_directories(SYSTEM ${LMDBXX_INCLUDE_DIR}) include_directories(include) include_directories(include/ui) include_directories(${CMAKE_CURRENT_BINARY_DIR}/config) -include_directories(${LMDB_INCLUDE_DIR}) - qt5_wrap_cpp(MOC_HEADERS # Dialogs include/dialogs/CreateRoom.h @@ -314,27 +286,14 @@ qt5_wrap_cpp(MOC_HEADERS # # Bundle translations. # -FILE(GLOB LANG_TS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/resources/langs/*.ts") +include(Translations) +set(TRANSLATION_DEPS ${LANG_QRC} ${QRC} ${QM_SRC}) -qt5_add_translation(QM_SRC ${LANG_TS_SRC}) -add_custom_target(LANG_QRC ALL DEPENDS ${QM_SRC}) - -# Generate a qrc file for the translations -set(_qrc ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc) - -if(NOT EXISTS ${_qrc}) - file(WRITE ${_qrc} " ") - foreach(_lang ${QM_SRC}) - get_filename_component(_filename ${_lang} NAME) - file(APPEND ${_qrc} "${_filename}") - endforeach(_lang) - file(APPEND ${_qrc} " ") -endif() - -qt5_add_resources(LANG_QRC ${_qrc}) -qt5_add_resources(QRC resources/res.qrc) - -set(COMMON_LIBS matrix_structs Qt5::Widgets Qt5::Network Qt5::Concurrent) +set(COMMON_LIBS + ${MATRIX_STRUCTS_LIBRARY} + Qt5::Widgets + Qt5::Network + Qt5::Concurrent) if(APPVEYOR_BUILD) set(NHEKO_LIBS ${COMMON_LIBS} lmdb) @@ -342,7 +301,12 @@ else() set(NHEKO_LIBS ${COMMON_LIBS} ${LMDB_LIBRARY}) endif() -set (NHEKO_DEPS ${SRC_FILES} ${UI_HEADERS} ${MOC_HEADERS} ${QRC} ${LANG_QRC} ${QM_SRC} ${META_FILES_TO_INCLUDE}) +set(NHEKO_DEPS + ${SRC_FILES} + ${UI_HEADERS} + ${MOC_HEADERS} + ${TRANSLATION_DEPS} + ${META_FILES_TO_INCLUDE}) if(APPLE) add_executable (nheko ${OS_BUNDLE} ${NHEKO_DEPS}) @@ -355,7 +319,9 @@ else() target_link_libraries (nheko ${NHEKO_LIBS} Qt5::Multimedia) endif() -add_dependencies(nheko MatrixStructs Tweeny lmdbxx) +if(EXTERNAL_PROJECT_DEPS) + add_dependencies(nheko ${EXTERNAL_PROJECT_DEPS}) +endif() if(UNIX AND NOT APPLE) install (TARGETS nheko RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") diff --git a/cmake/CompilerFlags.cmake b/cmake/CompilerFlags.cmake new file mode 100644 index 00000000..2aa92e54 --- /dev/null +++ b/cmake/CompilerFlags.cmake @@ -0,0 +1,25 @@ +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ + -Wall \ + -Wextra \ + -Werror \ + -pipe \ + -pedantic \ + -Wunreachable-code") + + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) + + if (GCC_VERSION VERSION_GREATER 4.9) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always" ) + endif() + endif() + + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always" ) + endif() +endif() + +if(NOT APPLE AND NOT MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") +endif() diff --git a/cmake/LMDB.cmake b/cmake/LMDB.cmake new file mode 100644 index 00000000..2d8184de --- /dev/null +++ b/cmake/LMDB.cmake @@ -0,0 +1,29 @@ +# +# Find the lmdb library & include dir. +# Build lmdb on Appveyor. +# + +if(APPVEYOR_BUILD) + set(LMDB_VERSION "LMDB_0.9.21") + set(NTDLIB "C:/WINDDK/7600.16385.1/lib/win7/amd64/ntdll.lib") + + execute_process( + COMMAND git clone --depth=1 --branch ${LMDB_VERSION} https://github.com/LMDB/lmdb) + + set(LMDB_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/lmdb/libraries/liblmdb) + + add_library(lmdb + ${CMAKE_SOURCE_DIR}/lmdb/libraries/liblmdb/lmdb.h + ${CMAKE_SOURCE_DIR}/lmdb/libraries/liblmdb/mdb.c + ${CMAKE_SOURCE_DIR}/lmdb/libraries/liblmdb/midl.h + ${CMAKE_SOURCE_DIR}/lmdb/libraries/liblmdb/midl.c) + + set(LMDB_LIBRARY lmdb) +else() + find_path (LMDB_INCLUDE_DIR NAMES lmdb.h PATHS "$ENV{LMDB_DIR}/include") + find_library (LMDB_LIBRARY NAMES lmdb PATHS "$ENV{LMDB_DIR}/lib" ) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(LMDB DEFAULT_MSG LMDB_INCLUDE_DIR LMDB_LIBRARY) +endif() + +include_directories(${LMDB_INCLUDE_DIR}) diff --git a/cmake/LMDBXX.cmake b/cmake/LMDBXX.cmake index 502d6b6c..3b9817d9 100644 --- a/cmake/LMDBXX.cmake +++ b/cmake/LMDBXX.cmake @@ -7,7 +7,7 @@ include(ExternalProject) set(THIRD_PARTY_ROOT ${CMAKE_SOURCE_DIR}/.third-party) set(LMDBXX_ROOT ${THIRD_PARTY_ROOT}/lmdbxx) -set(LMDBXX_INCLUDE_DIRS ${LMDBXX_ROOT}) +set(LMDBXX_INCLUDE_DIR ${LMDBXX_ROOT}) ExternalProject_Add( lmdbxx @@ -21,5 +21,3 @@ ExternalProject_Add( BUILD_COMMAND "" INSTALL_COMMAND "" ) - -include_directories(SYSTEM ${LMDBXX_ROOT}) diff --git a/cmake/MatrixStructs.cmake b/cmake/MatrixStructs.cmake index 9b8baba6..cef00f61 100644 --- a/cmake/MatrixStructs.cmake +++ b/cmake/MatrixStructs.cmake @@ -6,12 +6,10 @@ include(ExternalProject) set(THIRD_PARTY_ROOT ${CMAKE_SOURCE_DIR}/.third-party) set(MATRIX_STRUCTS_ROOT ${THIRD_PARTY_ROOT}/matrix_structs) +set(MATRIX_STRUCTS_INCLUDE_DIR ${MATRIX_STRUCTS_ROOT}/include) +set(MATRIX_STRUCTS_LIBRARY matrix_structs) -set(MATRIX_STRUCTS_INCLUDE_DIRS ${MATRIX_STRUCTS_ROOT}/deps) - -include_directories(SYSTEM ${MATRIX_STRUCTS_ROOT}/deps) -include_directories(SYSTEM ${MATRIX_STRUCTS_ROOT}/include) -link_directories(${MATRIX_STRUCTS_ROOT}/lib) +link_directories(${MATRIX_STRUCTS_ROOT}) set(WINDOWS_FLAGS "") @@ -23,17 +21,13 @@ ExternalProject_Add( MatrixStructs GIT_REPOSITORY https://github.com/mujx/matrix-structs - GIT_TAG 45e2671d9e5a5de46834c834e282da006f1689a0 + GIT_TAG 91bb2b85a75d664007ef81aeb500d35268425922 BUILD_IN_SOURCE 1 SOURCE_DIR ${MATRIX_STRUCTS_ROOT} CONFIGURE_COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release ${MATRIX_STRUCTS_ROOT} - -DCMAKE_INSTALL_PREFIX=${MATRIX_STRUCTS_ROOT} ${WINDOWS_FLAGS} BUILD_COMMAND ${CMAKE_COMMAND} --build ${MATRIX_STRUCTS_ROOT} --config Release - INSTALL_COMMAND ${CMAKE_COMMAND} - --build ${MATRIX_STRUCTS_ROOT} - --config Release - --target install + INSTALL_COMMAND "" ) diff --git a/cmake/Translations.cmake b/cmake/Translations.cmake new file mode 100644 index 00000000..16ca72ed --- /dev/null +++ b/cmake/Translations.cmake @@ -0,0 +1,23 @@ +# +# Generate the translation resource file +# + +FILE(GLOB LANG_TS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/resources/langs/*.ts") + +qt5_add_translation(QM_SRC ${LANG_TS_SRC}) +add_custom_target(LANG_QRC ALL DEPENDS ${QM_SRC}) + +# Generate a qrc file for the translations +set(_qrc ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc) + +if(NOT EXISTS ${_qrc}) + file(WRITE ${_qrc} " ") + foreach(_lang ${QM_SRC}) + get_filename_component(_filename ${_lang} NAME) + file(APPEND ${_qrc} "${_filename}") + endforeach(_lang) + file(APPEND ${_qrc} " ") +endif() + +qt5_add_resources(LANG_QRC ${_qrc}) +qt5_add_resources(QRC resources/res.qrc) diff --git a/cmake/Tweeny.cmake b/cmake/Tweeny.cmake index 87a2ade8..537ac92c 100644 --- a/cmake/Tweeny.cmake +++ b/cmake/Tweeny.cmake @@ -7,7 +7,7 @@ include(ExternalProject) set(THIRD_PARTY_ROOT ${CMAKE_SOURCE_DIR}/.third-party) set(TWEENY_ROOT ${THIRD_PARTY_ROOT}/tweeny) -set(TWEENY_INCLUDE_DIRS ${TWEENY_ROOT}/include) +set(TWEENY_INCLUDE_DIR ${TWEENY_ROOT}/include) ExternalProject_Add( Tweeny @@ -21,5 +21,3 @@ ExternalProject_Add( BUILD_COMMAND "" INSTALL_COMMAND "" ) - -include_directories(SYSTEM ${TWEENY_ROOT}/include)