diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -199,27 +199,17 @@ ### Cantorlibs (optional) ############################### IF (ENABLE_CANTOR) -FIND_LIBRARY (CANTOR_LIBS cantorlibs) -FIND_PATH (CANTOR_INCLUDE_DIR cantor/worksheetaccess.h - /usr/include - /usr/local/include +FIND_PACKAGE (Cantor) +SET_PACKAGE_PROPERTIES(Cantor PROPERTIES + URL "https://edu.kde.org/cantor/" ) -IF (CANTOR_LIBS AND CANTOR_INCLUDE_DIR AND KF5Service_FOUND AND KF5Parts_FOUND) - SET (CANTOR_LIBS_FOUND TRUE) - FIND_PATH (CANTOR_VERSION_FILE cantor/cantorlibs_version.h - /usr/include - /usr/local/include - ) - IF (NOT CANTOR_VERSION_FILE) +IF (Cantor_FOUND) + MESSAGE (STATUS "Found Cantor Library") + add_definitions (-DHAVE_CANTOR_LIBS) + + IF (NOT ${Cantor_VERSION} VERSION_GREATER "0") add_definitions (-DOLD_CANTORLIBS_VERSION) ENDIF() -ELSE () - SET (CANTOR_LIBS_FOUND FALSE) - SET (CANTOR_LIBS "") -ENDIF() -IF (CANTOR_LIBS_FOUND) - MESSAGE (STATUS "Found Cantor Library: ${CANTOR_INCLUDE_DIR} ${CANTOR_LIBS}") - add_definitions (-DHAVE_CANTOR_LIBS) ELSE () MESSAGE (STATUS "Cantor Library NOT FOUND") ENDIF () diff --git a/cmake/FindCantor.cmake b/cmake/FindCantor.cmake new file mode 100644 --- /dev/null +++ b/cmake/FindCantor.cmake @@ -0,0 +1,77 @@ +#============================================================================= +# Copyright (c) 2019 Harald Sitter +# +# 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. +#============================================================================= + +# Try to find via config. If that isn't available fall back to manual lookup. +# Config is vastly preferrable because it will also make sure link dependencies +# are found and actually in the target link interface. +find_package(Cantor ${Cantor_FIND_VERSION} ${Cantor_FIND_REQUIRED} CONFIG QUIET) +if(Cantor_FOUND) + return() +endif() + +find_library(Cantor_LIBRARIES cantorlibs) +find_path(Cantor_INCLUDE_DIR cantor/worksheetaccess.h) + +if(EXISTS "${Cantor_INCLUDE_DIR}/cantor/cantorlibs_version.h") + file(READ "${Cantor_INCLUDE_DIR}/cantor/cantorlibs_version.h" Cantorlibs_version_H_CONTENT) + + string(REGEX MATCH "#define CANTOR_VERSION_MAJOR[ ]+[0-9]+" Cantor_VERSION_MAJOR_MATCH ${Cantorlibs_version_H_CONTENT}) + string(REGEX MATCH "#define CANTOR_VERSION_MINOR[ ]+[0-9]+" Cantor_VERSION_MINOR_MATCH ${Cantorlibs_version_H_CONTENT}) + string(REGEX MATCH "#define CANTOR_VERSION_PATCH[ ]+[0-9]+" Cantor_VERSION_PATCH_MATCH ${Cantorlibs_version_H_CONTENT}) + + string(REGEX REPLACE ".*_MAJOR[ ]+(.*)" "\\1" Cantor_VERSION_MAJOR ${Cantor_VERSION_MAJOR_MATCH}) + string(REGEX REPLACE ".*_MINOR[ ]+(.*)" "\\1" Cantor_VERSION_MINOR ${Cantor_VERSION_MINOR_MATCH}) + string(REGEX REPLACE ".*_PATCH[ ]+(.*)" "\\1" Cantor_VERSION_PATCH ${Cantor_VERSION_PATCH_MATCH}) + + set(Cantor_VERSION "${Cantor_VERSION_MAJOR}.${Cantor_VERSION_MINOR}.${Cantor_VERSION_PATCH}") +else() + set(Cantor_VERSION "0.0.0") +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Cantor + FOUND_VAR + Cantor_FOUND + REQUIRED_VARS + Cantor_LIBRARIES + Cantor_INCLUDE_DIR + VERSION_VAR + Cantor_VERSION +) + +if(Cantor_FOUND AND NOT TARGET Cantor::cantorlibs) + add_library(Cantor::cantorlibs UNKNOWN IMPORTED) + set_target_properties(Cantor::cantorlibs PROPERTIES + IMPORTED_LOCATION "${Cantor_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${Cantor_INCLUDE_DIR}" + ) +endif() + +mark_as_advanced(Cantor_LIBRARIES Cantor_INCLUDE_DIR Cantor_VERSION) + +include(FeatureSummary) + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -327,7 +327,7 @@ ${COMMONFRONTEND_DIR}/datapicker/DatapickerImageView.cpp ) -IF (${CANTOR_LIBS_FOUND}) +IF (${Cantor_FOUND}) set(CANTOR_SOURCES ${KDEFRONTEND_DIR}/dockwidgets/CantorWorksheetDock.cpp ${BACKEND_DIR}/cantorWorksheet/VariableParser.cpp @@ -395,8 +395,8 @@ ENDIF () #TODO: KF5::NewStuff -IF (CANTOR_LIBS_FOUND) - target_link_libraries( labplot2lib ${CANTOR_LIBS} KF5::Service KF5::Parts) +IF (Cantor_FOUND) + target_link_libraries( labplot2lib Cantor::cantorlibs KF5::Service KF5::Parts) ENDIF () IF (HDF5_FOUND) target_link_libraries( labplot2lib ${HDF5_LIBRARIES} ) diff --git a/tests/import_export/ASCII/CMakeLists.txt b/tests/import_export/ASCII/CMakeLists.txt --- a/tests/import_export/ASCII/CMakeLists.txt +++ b/tests/import_export/ASCII/CMakeLists.txt @@ -11,8 +11,8 @@ ENDIF () #TODO: KF5::NewStuff -IF (CANTOR_LIBS_FOUND) - target_link_libraries(asciifiltertest ${CANTOR_LIBS} ) +IF (Cantor_FOUND) + target_link_libraries(asciifiltertest Cantor::cantorlibs ) ENDIF () IF (HDF5_FOUND) target_link_libraries(asciifiltertest ${HDF5_C_LIBRARIES} ) diff --git a/tests/import_export/JSON/CMakeLists.txt b/tests/import_export/JSON/CMakeLists.txt --- a/tests/import_export/JSON/CMakeLists.txt +++ b/tests/import_export/JSON/CMakeLists.txt @@ -11,8 +11,8 @@ ENDIF () #TODO: KF5::NewStuff -IF (CANTOR_LIBS_FOUND) - target_link_libraries(jsonfiltertest ${CANTOR_LIBS} ) +IF (Cantor_FOUND) + target_link_libraries(jsonfiltertest Cantor::cantorlibs ) ENDIF () IF (HDF5_FOUND) target_link_libraries(jsonfiltertest ${HDF5_C_LIBRARIES} ) diff --git a/tests/import_export/MQTT/CMakeLists.txt b/tests/import_export/MQTT/CMakeLists.txt --- a/tests/import_export/MQTT/CMakeLists.txt +++ b/tests/import_export/MQTT/CMakeLists.txt @@ -13,8 +13,8 @@ ENDIF () #TODO: KF5::NewStuff -IF (CANTOR_LIBS_FOUND) - target_link_libraries(mqttunittest ${CANTOR_LIBS} ) +IF (Cantor_FOUND) + target_link_libraries(mqttunittest Cantor::cantorlibs ) ENDIF () IF (HDF5_FOUND) target_link_libraries(mqttunittest ${HDF5_C_LIBRARIES} ) diff --git a/tests/import_export/project/CMakeLists.txt b/tests/import_export/project/CMakeLists.txt --- a/tests/import_export/project/CMakeLists.txt +++ b/tests/import_export/project/CMakeLists.txt @@ -11,8 +11,8 @@ ENDIF () #TODO: KF5::NewStuff -IF (CANTOR_LIBS_FOUND) - target_link_libraries(projectimporttest ${CANTOR_LIBS} ) +IF (Cantor_FOUND) + target_link_libraries(projectimporttest Cantor::cantorlibs ) ENDIF () IF (HDF5_FOUND) target_link_libraries(projectimporttest ${HDF5_C_LIBRARIES} )