Files
cd/cmake/FindCD.cmake
2022-08-08 15:36:54 +03:00

136 lines
3.4 KiB
CMake

#[[
Create imported targets:
* CD::Core
* CD::Qt
These targets include directories and dependencies
]]
cmake_policy(SET CMP0011 NEW) # don`t affect includer policies
cmake_policy(SET CMP0020 NEW) # Automatically link Qt executables to qtmain target on Windows
find_package(PIP REQUIRED)
find_package(QAD QUIET)
include(QtWraps)
include(SHSTKMacros)
shstk_is_parent_exists(hasParent PARENT_DIRECTORY)
shstk_set_find_dirs(CD)
if (NOT BUILDING_CD)
shstk_find_header(CD "cd_version.h" ${CD_INCDIR})
endif()
if(CD_FIND_VERSION VERSION_GREATER CD_VERSION)
message(FATAL_ERROR "CD version ${CD_VERSION} is available, but ${CD_FIND_VERSION} requested!")
endif()
set(__libs "core")
set(__module_core Core)
set( __inc_core "")
set(__libs_core "")
set(__deps_core "PIP")
if (BUILDING_CD)
if (NOT SET_TARGETS_CD)
#message("create aliases")
foreach (_l ${__libs})
set(_m ${__module_${_l}})
if((NOT TARGET CD::${_m}) AND TARGET cd_${_l})
#message("alias CD::${_m} = cd_${_l}")
add_library(CD::${_m} ALIAS cd_${_l})
endif()
endforeach()
endif()
else()
#message("create interfaces")
foreach (_l ${__libs})
set(_m ${__module_${_l}})
find_library(CD_LIBRARY_${_l} cd_${_l} HINTS ${CD_LIBDIR})
if((NOT TARGET CD::${_m}) AND CD_LIBRARY_${_l})
add_library(CD::${_m} UNKNOWN IMPORTED)
set_target_properties(CD::${_m} PROPERTIES
IMPORTED_LOCATION "${CD_LIBRARY_${_l}}"
INTERFACE_INCLUDE_DIRECTORIES "${CD_INCLUDES};${__inc_${_l}}"
INTERFACE_LINK_LIBRARIES "${__deps_${_l}};${__libs_${_l}}")
#message("imported CD::${_m} = ${CD_LIBRARY_${_l}} ${__deps_${_l}} ${__libs_${_l}} ${__inc_${_l}}")
endif()
endforeach()
endif()
if (QAD_FOUND OR BUILDING_qad)
set(__libs "qt")
set(__module_qt Qt)
set( __inc_qt "")
set(__libs_qt "")
set(__deps_qt "QAD::PIQt;QAD::Graphic;CD::Core")
if (BUILDING_CD)
if (NOT SET_TARGETS_CD)
set(SET_TARGETS_CD ON CACHE BOOL "")
#message("create aliases")
foreach(_l ${__libs})
foreach(_v ${_QT_VERSIONS_})
set(_m ${__module_${_l}})
if((NOT TARGET CD::${_m}${_v}) AND TARGET cd_${_l}${_v})
#message("alias CD::${_m}${_v} = cd_${_l}${_v}")
set(MULTILIB_CD__${_m}_SUFFIX_Qt${_v} ${_v} CACHE STRING "")
add_library(CD::${_m}${_v} ALIAS cd_${_l}${_v})
endif()
endforeach()
list(APPEND QT_MULTILIB_LIST CD::${_m})
endforeach()
endif()
else()
#message("create interfaces")
foreach(_l ${__libs})
foreach(_v ${_QT_VERSIONS_})
set(_m ${__module_${_l}})
find_library(CD_LIBRARY_${_l}${_v} cd_${_l}${_v} HINTS ${CD_LIBDIR})
#message("found ${_l}${_v} = ${CD_LIBRARY_${_l}${_v}}")
if((NOT TARGET CD::${_m}${_v}) AND CD_LIBRARY_${_l}${_v})
#message("imported CD::${_m}${_v} = ${CD_LIBRARY_${_l}${_v}}")
set(MULTILIB_CD__${_m}_SUFFIX_Qt${_v} ${_v} CACHE STRING "")
add_library(CD::${_m}${_v} UNKNOWN IMPORTED)
set(_deps)
foreach (_d ${__deps_${_l}})
if (${_d} MATCHES "QAD::*")
list(APPEND _deps ${_d}${_v})
else()
list(APPEND _deps ${_d})
endif()
endforeach()
set_target_properties(CD::${_m}${_v} PROPERTIES
IMPORTED_LOCATION "${CD_LIBRARY_${_l}${_v}}"
INTERFACE_INCLUDE_DIRECTORIES "${CD_INCLUDES}"
INTERFACE_LINK_LIBRARIES "${_deps}")
endif()
endforeach()
list(APPEND QT_MULTILIB_LIST CD::${_m})
endforeach()
endif()
if(hasParent)
set(QT_MULTILIB_LIST ${QT_MULTILIB_LIST} PARENT_SCOPE)
endif()
endif()
set(CD_FOUND ON CACHE BOOL "")