diff --git a/CMakeLists.txt b/CMakeLists.txt index e0281992..465c7d47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ OPTION(ENABLE_TESTING "Enable the unit tests" OFF) OPTION(FORCE_INTERNAL_ANTLR "Don't use the distribution's Antlr library even if there is one" OFF) OPTION(FORCE_INTERNAL_QSCINTILLA "Don't use the distribution's QScintilla library even if there is one" OFF) OPTION(FORCE_INTERNAL_QCUSTOMPLOT "Don't use distribution's QCustomPlot even if available" ON) +OPTION(FORCE_INTERNAL_QHEXEDIT "Don't use distribution's QHexEdit even if available" ON) OPTION(ALL_WARNINGS "Enable some useful warning flags" OFF) if(NOT CMAKE_BUILD_TYPE) @@ -82,8 +83,11 @@ if(FORCE_INTERNAL_QCUSTOMPLOT) else() find_package(QCustomPlot) endif() -set(QHEXEDIT_DIR libs/qhexedit) -set(QHEXEDIT_INCL_DIR ${QHEXEDIT_DIR}/src) +if(FORCE_INTERNAL_QHEXEDIT) + set(QHEXEDIT_FOUND FALSE) +else() + find_package(QHexEdit) +endif() set(JSON_DIR libs/json) if(NOT ANTLR2_FOUND) @@ -94,7 +98,11 @@ if(NOT QSCINTILLA_FOUND) set(QSCINTILLA_DIR libs/qscintilla/Qt4Qt5) add_subdirectory(${QSCINTILLA_DIR}) endif() -add_subdirectory(${QHEXEDIT_DIR}) +if(NOT QHEXEDIT_FOUND) + set(QHEXEDIT_DIR libs/qhexedit) + set(QHEXEDIT_INCL_DIR ${QHEXEDIT_DIR}/src) + add_subdirectory(${QHEXEDIT_DIR}) +endif() add_subdirectory(${JSON_DIR}) if(NOT QCUSTOMPLOT_FOUND) set(QCUSTOMPLOT_DIR libs/qcustomplot-source) @@ -371,10 +379,14 @@ endif() include_directories( "${CMAKE_CURRENT_BINARY_DIR}" - ${QHEXEDIT_INCL_DIR} ${JSON_DIR} ${ADDITIONAL_INCLUDE_PATHS} src) +if(QHEXEDIT_FOUND) + include_directories(${QHEXEDIT_INCLUDE_DIR}) +else() + include_directories(${QHEXEDIT_INCL_DIR}) +endif() if(QCUSTOMPLOT_FOUND) include_directories(${QCUSTOMPLOT_INCLUDE_DIR}) else() @@ -409,7 +421,9 @@ if (ALL_WARNINGS AND CMAKE_COMPILER_IS_GNUCC) endif() endif() -add_dependencies(${PROJECT_NAME} qhexedit) +if(NOT QHEXEDIT_FOUND) + add_dependencies(${PROJECT_NAME} qhexedit) +endif() if(NOT QCUSTOMPLOT_FOUND) add_dependencies(${PROJECT_NAME} qcustomplot) endif() @@ -420,7 +434,9 @@ if(NOT QSCINTILLA_FOUND) add_dependencies(${PROJECT_NAME} qscintilla2) endif() -link_directories("${CMAKE_CURRENT_BINARY_DIR}/${QHEXEDIT_DIR}") +if(NOT QHEXEDIT_FOUND) + link_directories("${CMAKE_CURRENT_BINARY_DIR}/${QHEXEDIT_DIR}") +endif() if(NOT QCUSTOMPLOT_FOUND) link_directories("${CMAKE_CURRENT_BINARY_DIR}/${QCUSTOMPLOT_DIR}") endif() @@ -434,12 +450,16 @@ endif() set(QT_LIBS Qt5::Gui Qt5::Test Qt5::PrintSupport Qt5::Widgets Qt5::Network Qt5::Concurrent Qt5::Xml) target_link_libraries(${PROJECT_NAME} - qhexedit ${LPTHREAD} ${QT_LIBS} ${WIN32_STATIC_LINK} ${LIBSQLITE} ${ADDITIONAL_LIBS}) +if(QHEXEDIT_FOUND) + target_link_libraries(${PROJECT_NAME} ${QHEXEDIT_LIBRARIES}) +else() + target_link_libraries(${PROJECT_NAME} qhexedit) +endif() if(QCUSTOMPLOT_FOUND) target_link_libraries(${PROJECT_NAME} ${QCUSTOMPLOT_LIBRARIES}) else() diff --git a/cmake/FindQHexEdit.cmake b/cmake/FindQHexEdit.cmake new file mode 100644 index 00000000..248abfe2 --- /dev/null +++ b/cmake/FindQHexEdit.cmake @@ -0,0 +1,51 @@ +# Attempt to locate QHexEdit +# Once done this will define: +# +# QHEXEDIT_FOUND - system has QHexEdit +# QHEXEDIT_INCLUDE_DIRS - the include directories for QHexEdit +# QHEXEDIT_LIBRARIES - Link these to use QHexEdit +# +# Copyright (C) 2019, Scott Furry, +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. The name of the author may not be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +find_library(QHEXEDIT_LIBRARY qhexedit) +set(QHEXEDIT_LIBRARIES "${QHEXEDIT_LIBRARY}") + +find_path(QHEXEDIT_INCLUDE_DIR qhexedit.h) +set(QHEXEDIT_INCLUDE_DIRS "${QHEXEDIT_INCLUDE_DIR}") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + QHEXEDIT + DEFAULT_MSG + QHEXEDIT_LIBRARIES + QHEXEDIT_INCLUDE_DIRS +) + +mark_as_advanced( + QHEXEDIT_INCLUDE_DIRS + QHEXEDIT_LIBRARIES +)