CheckFunctions.cmake 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Licensed under the Apache License, Version 2.0 (the "License"); you may not
  2. # use this file except in compliance with the License. You may obtain a copy of
  3. # the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
  4. # applicable law or agreed to in writing, software distributed under the License
  5. # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  6. # KIND, either express or implied. See the License for the specific language
  7. # governing permissions and limitations under the License.
  8. # ##############################################################################
  9. #
  10. # macros and functions
  11. #
  12. # ##############################################################################
  13. # ##############################################################################
  14. # FUNCTION check_leptonica_tiff_support
  15. # ##############################################################################
  16. function(check_leptonica_tiff_support)
  17. # check if leptonica was build with tiff support set result to
  18. # LEPT_TIFF_RESULT
  19. set(TIFF_TEST
  20. "#include \"leptonica/allheaders.h\"\n"
  21. "int main() {\n"
  22. " l_uint8 *data = NULL;\n"
  23. " size_t size = 0;\n"
  24. " PIX* pix = pixCreate(3, 3, 4);\n"
  25. " l_int32 ret_val = pixWriteMemTiff(&data, &size, pix, IFF_TIFF_G3);\n"
  26. " pixDestroy(&pix);\n"
  27. " lept_free(data);\n"
  28. " return ret_val;}\n")
  29. if(${CMAKE_VERSION} VERSION_LESS "3.25")
  30. message(STATUS "Testing TIFF support in Leptonica is available with CMake >= 3.25 (you have ${CMAKE_VERSION}))")
  31. else()
  32. set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
  33. try_run(
  34. LEPT_TIFF_RESULT
  35. LEPT_TIFF_COMPILE_SUCCESS
  36. SOURCE_FROM_CONTENT tiff_test.cpp "${TIFF_TEST}"
  37. CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${Leptonica_INCLUDE_DIRS}"
  38. LINK_LIBRARIES ${Leptonica_LIBRARIES}
  39. COMPILE_OUTPUT_VARIABLE
  40. COMPILE_OUTPUT)
  41. if(NOT LEPT_TIFF_COMPILE_SUCCESS)
  42. message(STATUS "COMPILE_OUTPUT: ${COMPILE_OUTPUT}")
  43. message(STATUS "Leptonica_INCLUDE_DIRS: ${Leptonica_INCLUDE_DIRS}")
  44. message(STATUS "Leptonica_LIBRARIES: ${Leptonica_LIBRARIES}")
  45. message(STATUS "LEPT_TIFF_RESULT: ${LEPT_TIFF_RESULT}")
  46. message(STATUS "LEPT_TIFF_COMPILE: ${LEPT_TIFF_COMPILE}")
  47. message(WARNING "Failed to compile test")
  48. endif()
  49. endif()
  50. endfunction(check_leptonica_tiff_support)
  51. # ##############################################################################