diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright © 2015 Hasan Yavuz Özderya +# Copyright © 2015-2016 Hasan Yavuz Özderya # # This file is part of serialplot. # @@ -36,17 +36,23 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PAT # Find the QtWidgets library find_package(Qt5Widgets) -# Find QWT or use static +# If set, cmake will download Qwt over SVN, build and use it as a static library. +set(BUILD_QWT true CACHE BOOL "Download and build Qwt automatically.") +# Find QWT or use static manually provided by user set(QWT_USE_STATIC false CACHE BOOL "Use a static version of Qwt provided by user.") set(QWT_STATIC_LIBRARY "" CACHE FILEPATH "Path to the static Qwt library, libqwt.a.") set(QWT_STATIC_INCLUDE "" CACHE PATH "Path to the Qwt include directory when building Qwt static.") -if (QWT_USE_STATIC) - set(QWT_LIBRARY ${QWT_STATIC_LIBRARY}) - set(QWT_INCLUDE_DIR ${QWT_STATIC_INCLUDE}) -else (QWT_USE_STATIC) - find_package(Qwt 6.1 REQUIRED) -endif (QWT_USE_STATIC) +if (BUILD_QWT) + include(BuildQwt) +else (BUILD_QWT) + if (QWT_USE_STATIC) + set(QWT_LIBRARY ${QWT_STATIC_LIBRARY}) + set(QWT_INCLUDE_DIR ${QWT_STATIC_INCLUDE}) + else (QWT_USE_STATIC) + find_package(Qwt 6.1 REQUIRED) + endif (QWT_USE_STATIC) +endif (BUILD_QWT) # includes include_directories("./src" ${QWT_INCLUDE_DIR}) @@ -117,6 +123,10 @@ add_executable(${PROGRAM_NAME} WIN32 target_link_libraries(${PROGRAM_NAME} ${QWT_LIBRARY}) qt5_use_modules(${PROGRAM_NAME} Widgets SerialPort Svg) +if (BUILD_QWT) + add_dependencies(${PROGRAM_NAME} QWT) +endif (BUILD_QWT) + # set compiler flags set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") diff --git a/cmake/modules/BuildQwt.cmake b/cmake/modules/BuildQwt.cmake new file mode 100644 --- /dev/null +++ b/cmake/modules/BuildQwt.cmake @@ -0,0 +1,36 @@ +# +# Copyright © 2016 Hasan Yavuz Özderya +# +# This file is part of serialplot. +# +# serialplot is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# serialplot is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with serialplot. If not, see . +# + +include(ExternalProject) + +ExternalProject_Add(QWT + PREFIX qwt + SVN_REPOSITORY svn://svn.code.sf.net/p/qwt/code/branches/qwt-6.1 + # disable QwtDesigner plugin and enable static build + PATCH_COMMAND sed -i -r -e "s/QWT_CONFIG\\s*\\+=\\s*QwtDesigner/#&/" + -e "s/QWT_CONFIG\\s*\\+=\\s*QwtDll/#&/" + -e "s:/usr/local/.*::" + /qwtconfig.pri + CONFIGURE_COMMAND qmake /qwt.pro + ) + +ExternalProject_Get_Property(QWT install_dir) +set(QWT_ROOT ${install_dir}) +set(QWT_LIBRARY ${QWT_ROOT}/lib/libqwt.a) +set(QWT_INCLUDE_DIR ${QWT_ROOT}/include)