cmake: check_leptonica_tiff_support() works with cmake>=3.25

This commit is contained in:
zdenop 2023-07-15 19:43:50 +02:00
parent d1abdf353a
commit 54b9fe4de9
2 changed files with 31 additions and 27 deletions

View File

@ -408,10 +408,10 @@ else()
include_directories(${Leptonica_INCLUDE_DIRS}) include_directories(${Leptonica_INCLUDE_DIRS})
check_leptonica_tiff_support() check_leptonica_tiff_support()
if (NOT LEPT_TIFF_RESULT EQUAL 0) if ((NOT LEPT_TIFF_RESULT EQUAL 0) AND LEPT_TIFF_COMPILE_SUCCESS)
message(NOTICE "Leptonica was build without TIFF support! Disabling TIFF support...") message(NOTICE "Leptonica was build without TIFF support! Disabling TIFF support...")
set(DISABLE_TIFF ON) set(DISABLE_TIFF ON)
else() elseif(NOT ${CMAKE_VERSION} VERSION_LESS "3.25")
message(STATUS "Leptonica was build with TIFF support.") message(STATUS "Leptonica was build with TIFF support.")
endif() endif()

View File

@ -18,31 +18,35 @@ function(check_leptonica_tiff_support)
# check if leptonica was build with tiff support set result to # check if leptonica was build with tiff support set result to
# LEPT_TIFF_RESULT # LEPT_TIFF_RESULT
set(TIFF_TEST set(TIFF_TEST
"#include <leptonica/allheaders.h>\n" "#include \"leptonica/allheaders.h\"\n"
"int main() {\n" "int main() {\n"
" l_uint8 *data = NULL;\n" " l_uint8 *data = NULL;\n"
" size_t size = 0;\n" " size_t size = 0;\n"
" PIX* pix = pixCreate(3, 3, 4);\n" " PIX* pix = pixCreate(3, 3, 4);\n"
" l_int32 ret_val = pixWriteMemTiff(&data, &size, pix, IFF_TIFF_G3);\n" " l_int32 ret_val = pixWriteMemTiff(&data, &size, pix, IFF_TIFF_G3);\n"
" pixDestroy(&pix);\n" " pixDestroy(&pix);\n"
" lept_free(data);\n" " lept_free(data);\n"
" return ret_val;}\n") " return ret_val;}\n")
set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE}) if(${CMAKE_VERSION} VERSION_LESS "3.25")
try_run( message(STATUS "Testing TIFF support in Leptonica is available with CMake >= 3.25 (you have ${CMAKE_VERSION}))")
LEPT_TIFF_RESULT else()
LEPT_TIFF_COMPILE set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
SOURCE_FROM_CONTENT tiff_test.cpp "${TIFF_TEST}" try_run(
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${Leptonica_INCLUDE_DIRS}" LEPT_TIFF_RESULT
LINK_LIBRARIES ${Leptonica_LIBRARIES} LEPT_TIFF_COMPILE_SUCCESS
COMPILE_OUTPUT_VARIABLE SOURCE_FROM_CONTENT tiff_test.cpp "${TIFF_TEST}"
COMPILE_OUTPUT) CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${Leptonica_INCLUDE_DIRS}"
if(NOT LEPT_TIFF_COMPILE) LINK_LIBRARIES ${Leptonica_LIBRARIES}
message(STATUS "COMPILE_OUTPUT: ${COMPILE_OUTPUT}") COMPILE_OUTPUT_VARIABLE
message(STATUS "Leptonica_INCLUDE_DIRS: ${Leptonica_INCLUDE_DIRS}") COMPILE_OUTPUT)
message(STATUS "Leptonica_LIBRARIES: ${Leptonica_LIBRARIES}") if(NOT LEPT_TIFF_COMPILE_SUCCESS)
message(STATUS "LEPT_TIFF_RESULT: ${LEPT_TIFF_RESULT}") message(STATUS "COMPILE_OUTPUT: ${COMPILE_OUTPUT}")
message(STATUS "LEPT_TIFF_COMPILE: ${LEPT_TIFF_COMPILE}") message(STATUS "Leptonica_INCLUDE_DIRS: ${Leptonica_INCLUDE_DIRS}")
message(WARNING "Failed to compile test") message(STATUS "Leptonica_LIBRARIES: ${Leptonica_LIBRARIES}")
message(STATUS "LEPT_TIFF_RESULT: ${LEPT_TIFF_RESULT}")
message(STATUS "LEPT_TIFF_COMPILE: ${LEPT_TIFF_COMPILE}")
message(WARNING "Failed to compile test")
endif()
endif() endif()
endfunction(check_leptonica_tiff_support) endfunction(check_leptonica_tiff_support)