Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Commit

Permalink
Adjust CMakeLists to make dependency downloading optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mujx committed Mar 29, 2018
1 parent 00549e0 commit 3afc76d
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 94 deletions.
120 changes: 43 additions & 77 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -314,35 +286,27 @@ 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} "<RCC> <qresource prefix=\"/translations\">")
foreach(_lang ${QM_SRC})
get_filename_component(_filename ${_lang} NAME)
file(APPEND ${_qrc} "<file>${_filename}</file>")
endforeach(_lang)
file(APPEND ${_qrc} "</qresource> </RCC>")
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)
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})
Expand All @@ -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}")
Expand Down
25 changes: 25 additions & 0 deletions cmake/CompilerFlags.cmake
Original file line number Diff line number Diff line change
@@ -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()
29 changes: 29 additions & 0 deletions cmake/LMDB.cmake
Original file line number Diff line number Diff line change
@@ -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})
4 changes: 1 addition & 3 deletions cmake/LMDBXX.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,5 +21,3 @@ ExternalProject_Add(
BUILD_COMMAND ""
INSTALL_COMMAND ""
)

include_directories(SYSTEM ${LMDBXX_ROOT})
16 changes: 5 additions & 11 deletions cmake/MatrixStructs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")

Expand All @@ -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 ""
)
23 changes: 23 additions & 0 deletions cmake/Translations.cmake
Original file line number Diff line number Diff line change
@@ -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} "<RCC> <qresource prefix=\"/translations\">")
foreach(_lang ${QM_SRC})
get_filename_component(_filename ${_lang} NAME)
file(APPEND ${_qrc} "<file>${_filename}</file>")
endforeach(_lang)
file(APPEND ${_qrc} "</qresource> </RCC>")
endif()

qt5_add_resources(LANG_QRC ${_qrc})
qt5_add_resources(QRC resources/res.qrc)
4 changes: 1 addition & 3 deletions cmake/Tweeny.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,5 +21,3 @@ ExternalProject_Add(
BUILD_COMMAND ""
INSTALL_COMMAND ""
)

include_directories(SYSTEM ${TWEENY_ROOT}/include)

0 comments on commit 3afc76d

Please sign in to comment.