cmake: improve style

This commit is contained in:
zdenop 2023-03-23 20:20:51 +01:00
parent f779c434b0
commit 484d427c67

View File

@ -151,10 +151,10 @@ set(MARCH_NATIVE_OPT OFF)
if(ENABLE_NATIVE) if(ENABLE_NATIVE)
check_cxx_compiler_flag("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) check_cxx_compiler_flag("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
if(COMPILER_SUPPORTS_MARCH_NATIVE) if(COMPILER_SUPPORTS_MARCH_NATIVE)
set(MARCH_NATIVE_FLAGS "${MARCH_NATIVE_FLAGS} -march=native") set(DOTPRODUCT_FLAGS "${DOTPRODUCT_FLAGS} -march=native")
if(NOT CLANG AND MSVC) if(NOT CLANG AND MSVC)
# clang-cl does not know this argument # clang-cl does not know this argument
set(MARCH_NATIVE_FLAGS "${MARCH_NATIVE_FLAGS} -mtune=native") set(DOTPRODUCT_FLAGS "${DOTPRODUCT_FLAGS} -mtune=native")
endif() endif()
set(MARCH_NATIVE_OPT ON) set(MARCH_NATIVE_OPT ON)
endif(COMPILER_SUPPORTS_MARCH_NATIVE) endif(COMPILER_SUPPORTS_MARCH_NATIVE)
@ -196,7 +196,7 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86|x86_64|AMD64|amd64|i386|i686")
set(SSE4_1_COMPILE_FLAGS "-msse4.1 ${SSE4_1_COMPILE_FLAGS}") set(SSE4_1_COMPILE_FLAGS "-msse4.1 ${SSE4_1_COMPILE_FLAGS}")
endif(HAVE_SSE4_1) endif(HAVE_SSE4_1)
endif(CLANG) endif(CLANG)
else() # if not MSVC else() # if not MSVC
check_cxx_compiler_flag("-mavx" HAVE_AVX) check_cxx_compiler_flag("-mavx" HAVE_AVX)
if(HAVE_AVX) if(HAVE_AVX)
set(AVX_COMPILE_FLAGS "-mavx") set(AVX_COMPILE_FLAGS "-mavx")
@ -281,9 +281,9 @@ elseif(MSVC)
# loss of data wd4275 non dll-interface class wd4305 ...truncation from # loss of data wd4275 non dll-interface class wd4305 ...truncation from
# 'double' to 'float' # 'double' to 'float'
set(CMAKE_CXX_FLAGS_RELEASE set(CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_FLAGS_RELEASE} /wd4244 /wd4305 /wd4267 /wd4251 /wd4275 /wd4005") "${CMAKE_CXX_FLAGS_RELEASE} /wd4244 /wd4305 /wd4267 /wd4251 /wd4275 /wd4005"
set(CMAKE_CXX_FLAGS_RELEASE )
"${CMAKE_CXX_FLAGS_RELEASE} /wd4068") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /wd4068")
# Don't use /Wall because it generates too many warnings. # Don't use /Wall because it generates too many warnings.
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W0 /bigobj") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W0 /bigobj")
# MT flag # MT flag
@ -326,10 +326,10 @@ if(OPENMP_BUILD)
add_definitions(-D_OPENMP=201107) add_definitions(-D_OPENMP=201107)
endif() endif()
if(MSVC) if(MSVC)
# Note: -openmp:llvm is available for X64 from MSVC 16.9 # Note: -openmp:llvm is available for X64 from MSVC 16.9 from MSVC 16.10
# from MSVC 16.10 Preview 2 there is support also for x86 and arm64 # Preview 2 there is support also for x86 and arm64
# https://devblogs.microsoft.com/cppblog/openmp-updates-and-fixes-for-cpp-in-visual-studio-2019-16-10/ # https://devblogs.microsoft.com/cppblog/openmp-updates-and-fixes-for-cpp-in-visual-studio-2019-16-10/
if ("${OpenMP_CXX_FLAGS}" STREQUAL "-openmp") if("${OpenMP_CXX_FLAGS}" STREQUAL "-openmp")
set(OpenMP_CXX_FLAGS "-openmp:llvm") set(OpenMP_CXX_FLAGS "-openmp:llvm")
endif() endif()
# 'simd': requires '-openmp:experimental' # 'simd': requires '-openmp:experimental'
@ -339,7 +339,7 @@ if(OPENMP_BUILD)
if(OpenMP_FOUND) if(OpenMP_FOUND)
message(">> OpenMP_FOUND ${OpenMP_FOUND} version: ${OpenMP_CXX_VERSION}") message(">> OpenMP_FOUND ${OpenMP_FOUND} version: ${OpenMP_CXX_VERSION}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
if (NOT TARGET OpenMP::OpenMP_CXX) if(NOT TARGET OpenMP::OpenMP_CXX)
add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE) add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE)
endif() endif()
endif() endif()
@ -431,9 +431,9 @@ else()
endif(DISABLE_CURL) endif(DISABLE_CURL)
endif() endif()
IF(ENABLE_OPENCL) if(ENABLE_OPENCL)
find_package(OpenCL) find_package(OpenCL)
if (OpenCL_FOUND) if(OpenCL_FOUND)
include_directories(${OpenCL_INCLUDE_DIRS}) include_directories(${OpenCL_INCLUDE_DIRS})
message(STATUS "OpenCL_INCLUDE_DIRS: ${OpenCL_INCLUDE_DIRS}") message(STATUS "OpenCL_INCLUDE_DIRS: ${OpenCL_INCLUDE_DIRS}")
message(STATUS "OpenCL_LIBRARY: ${OpenCL_LIBRARY}") message(STATUS "OpenCL_LIBRARY: ${OpenCL_LIBRARY}")
@ -450,7 +450,7 @@ endif(ENABLE_OPENCL)
# ############################################################################## # ##############################################################################
if(NOT MSVC) if(NOT MSVC)
set(MARCH_NATIVE_FLAGS "${MARCH_NATIVE_FLAGS} -O3 -ffast-math") set(DOTPRODUCT_FLAGS "${DOTPRODUCT_FLAGS} -O3 -ffast-math")
endif() endif()
if(NOT DEFINED CMAKE_INSTALL_LIBDIR) if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
@ -535,10 +535,13 @@ message(STATUS "Build training tools [BUILD_TRAINING_TOOLS]: "
"${BUILD_TRAINING_TOOLS}") "${BUILD_TRAINING_TOOLS}")
message(STATUS "Build tests [BUILD_TESTS]: ${BUILD_TESTS}") message(STATUS "Build tests [BUILD_TESTS]: ${BUILD_TESTS}")
if(ENABLE_OPENCL) if(ENABLE_OPENCL)
message(STATUS "Enable unsupported experimental OpenCL [ENABLE_OPENCL]: ${USE_OPENCL}") message(
STATUS
"Enable unsupported experimental OpenCL [ENABLE_OPENCL]: ${USE_OPENCL}")
endif(ENABLE_OPENCL) endif(ENABLE_OPENCL)
message(STATUS "Use system ICU Library [USE_SYSTEM_ICU]: ${USE_SYSTEM_ICU}") message(STATUS "Use system ICU Library [USE_SYSTEM_ICU]: ${USE_SYSTEM_ICU}")
message(STATUS "Install tesseract configs [INSTALL_CONFIGS]: ${INSTALL_CONFIGS}") message(
STATUS "Install tesseract configs [INSTALL_CONFIGS]: ${INSTALL_CONFIGS}")
message(STATUS "--------------------------------------------------------") message(STATUS "--------------------------------------------------------")
message(STATUS) message(STATUS)
@ -591,7 +594,7 @@ if(DISABLED_LEGACY_ENGINE)
PARENT_SCOPE) PARENT_SCOPE)
endfunction() endfunction()
set(TESSERACT_SRC_LEGACY set(TESSERACT_SRC_LEGACY
src/ccmain/adaptions.cpp src/ccmain/adaptions.cpp
src/ccmain/docqual.cpp src/ccmain/docqual.cpp
src/ccmain/equationdetect.cpp src/ccmain/equationdetect.cpp
@ -661,10 +664,10 @@ endif(DISABLED_LEGACY_ENGINE)
list(APPEND arch_files src/arch/dotproduct.cpp src/arch/simddetect.cpp list(APPEND arch_files src/arch/dotproduct.cpp src/arch/simddetect.cpp
src/arch/intsimdmatrix.cpp) src/arch/intsimdmatrix.cpp)
if(MARCH_NATIVE_FLAGS) if(DOTPRODUCT_FLAGS)
set_source_files_properties(src/arch/dotproduct.cpp set_source_files_properties(src/arch/dotproduct.cpp
PROPERTIES COMPILE_FLAGS ${MARCH_NATIVE_FLAGS}) PROPERTIES COMPILE_FLAGS ${DOTPRODUCT_FLAGS})
endif(MARCH_NATIVE_FLAGS) endif(DOTPRODUCT_FLAGS)
if(HAVE_AVX) if(HAVE_AVX)
list(APPEND arch_files_opt src/arch/dotproductavx.cpp) list(APPEND arch_files_opt src/arch/dotproductavx.cpp)
set_source_files_properties(src/arch/dotproductavx.cpp set_source_files_properties(src/arch/dotproductavx.cpp
@ -732,40 +735,37 @@ set(TESSERACT_SRC
src/api/wordstrboxrenderer.cpp) src/api/wordstrboxrenderer.cpp)
set(TESSERACT_CONFIGS set(TESSERACT_CONFIGS
tessdata/configs/alto tessdata/configs/alto
tessdata/configs/ambigs.train tessdata/configs/ambigs.train
tessdata/configs/api_config tessdata/configs/api_config
tessdata/configs/bazaar tessdata/configs/bazaar
tessdata/configs/bigram tessdata/configs/bigram
tessdata/configs/box.train tessdata/configs/box.train
tessdata/configs/box.train.stderr tessdata/configs/box.train.stderr
tessdata/configs/digits tessdata/configs/digits
tessdata/configs/get.images tessdata/configs/get.images
tessdata/configs/hocr tessdata/configs/hocr
tessdata/configs/inter tessdata/configs/inter
tessdata/configs/kannada tessdata/configs/kannada
tessdata/configs/linebox tessdata/configs/linebox
tessdata/configs/logfile tessdata/configs/logfile
tessdata/configs/lstm.train tessdata/configs/lstm.train
tessdata/configs/lstmbox tessdata/configs/lstmbox
tessdata/configs/lstmdebug tessdata/configs/lstmdebug
tessdata/configs/makebox tessdata/configs/makebox
tessdata/configs/pdf tessdata/configs/pdf
tessdata/configs/quiet tessdata/configs/quiet
tessdata/configs/rebox tessdata/configs/rebox
tessdata/configs/strokewidth tessdata/configs/strokewidth
tessdata/configs/tsv tessdata/configs/tsv
tessdata/configs/txt tessdata/configs/txt
tessdata/configs/unlv tessdata/configs/unlv
tessdata/configs/wordstrbox) tessdata/configs/wordstrbox)
set(TESSERACT_TESSCONFIGS set(TESSERACT_TESSCONFIGS
tessdata/tessconfigs/batch tessdata/tessconfigs/batch tessdata/tessconfigs/batch.nochop
tessdata/tessconfigs/batch.nochop tessdata/tessconfigs/matdemo tessdata/tessconfigs/msdemo
tessdata/tessconfigs/matdemo tessdata/tessconfigs/nobatch tessdata/tessconfigs/segdemo)
tessdata/tessconfigs/msdemo
tessdata/tessconfigs/nobatch
tessdata/tessconfigs/segdemo)
set(LIBTESSFILES ${TESSERACT_SRC} ${arch_files} ${arch_files_opt} set(LIBTESSFILES ${TESSERACT_SRC} ${arch_files} ${arch_files_opt}
${TESSERACT_HDR}) ${TESSERACT_HDR})
@ -774,8 +774,7 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${LIBTESSFILES})
add_library(libtesseract ${LIBTESSFILES}) add_library(libtesseract ${LIBTESSFILES})
target_include_directories( target_include_directories(
libtesseract libtesseract BEFORE
BEFORE
PRIVATE src PRIVATE src
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/arch> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/arch>
@ -816,13 +815,19 @@ if(CURL_FOUND)
endif() endif()
endif(CURL_FOUND) endif(CURL_FOUND)
set_target_properties(libtesseract set_target_properties(
PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) libtesseract PROPERTIES VERSION
set_target_properties(libtesseract ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
PROPERTIES SOVERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) set_target_properties(
libtesseract PROPERTIES SOVERSION
${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set_target_properties(libtesseract set_target_properties(
PROPERTIES OUTPUT_NAME tesseract$<$<BOOL:${WIN32}>:${VERSION_MAJOR}${VERSION_MINOR}$<$<CONFIG:DEBUG>:d>>) libtesseract
PROPERTIES
OUTPUT_NAME
tesseract$<$<BOOL:${WIN32}>:${VERSION_MAJOR}${VERSION_MINOR}$<$<CONFIG:DEBUG>:d>>
)
if(SW_BUILD) if(SW_BUILD)
target_link_libraries(libtesseract PUBLIC org.sw.demo.danbloomberg.leptonica target_link_libraries(libtesseract PUBLIC org.sw.demo.danbloomberg.leptonica
@ -850,11 +855,13 @@ if(WIN32
target_link_libraries(libtesseract PRIVATE ${OpenMP_LIBRARY}) target_link_libraries(libtesseract PRIVATE ${OpenMP_LIBRARY})
endif() endif()
if (ANDROID) if(ANDROID)
add_definitions(-DANDROID) add_definitions(-DANDROID)
find_package(CpuFeaturesNdkCompat REQUIRED) find_package(CpuFeaturesNdkCompat REQUIRED)
target_include_directories(libtesseract PRIVATE "${CpuFeaturesNdkCompat_DIR}/../../../include/ndk_compat") target_include_directories(
target_link_libraries (libtesseract PRIVATE CpuFeatures::ndk_compat) libtesseract
PRIVATE "${CpuFeaturesNdkCompat_DIR}/../../../include/ndk_compat")
target_link_libraries(libtesseract PRIVATE CpuFeatures::ndk_compat)
endif() endif()
# ############################################################################## # ##############################################################################
@ -873,8 +880,9 @@ endif()
# ############################################################################## # ##############################################################################
if(BUILD_TESTS AND EXISTS if(BUILD_TESTS
${CMAKE_CURRENT_SOURCE_DIR}/unittest/third_party/googletest/CMakeLists.txt AND EXISTS
${CMAKE_CURRENT_SOURCE_DIR}/unittest/third_party/googletest/CMakeLists.txt
) )
add_subdirectory(unittest/third_party/googletest) add_subdirectory(unittest/third_party/googletest)
endif() endif()
@ -890,7 +898,10 @@ get_target_property(tesseract_OUTPUT_NAME libtesseract OUTPUT_NAME)
configure_file(tesseract.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/tesseract.pc.in configure_file(tesseract.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/tesseract.pc.in
@ONLY) @ONLY)
# to resolve generator expression in OUTPUT_NAME # to resolve generator expression in OUTPUT_NAME
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/tesseract_$<CONFIG>.pc INPUT ${CMAKE_CURRENT_BINARY_DIR}/tesseract.pc.in) file(
GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/tesseract_$<CONFIG>.pc
INPUT ${CMAKE_CURRENT_BINARY_DIR}/tesseract.pc.in)
configure_package_config_file( configure_package_config_file(
cmake/templates/TesseractConfig.cmake.in cmake/templates/TesseractConfig.cmake.in
@ -902,8 +913,10 @@ write_basic_package_version_file(
VERSION ${PACKAGE_VERSION} VERSION ${PACKAGE_VERSION}
COMPATIBILITY SameMajorVersion) COMPATIBILITY SameMajorVersion)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tesseract_$<CONFIG>.pc install(
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig RENAME tesseract.pc) FILES ${CMAKE_CURRENT_BINARY_DIR}/tesseract_$<CONFIG>.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
RENAME tesseract.pc)
install(TARGETS tesseract DESTINATION bin) install(TARGETS tesseract DESTINATION bin)
install( install(
TARGETS libtesseract TARGETS libtesseract
@ -935,10 +948,10 @@ install(
DESTINATION include/tesseract) DESTINATION include/tesseract)
if(INSTALL_CONFIGS) if(INSTALL_CONFIGS)
install(FILES ${TESSERACT_CONFIGS} install(FILES ${TESSERACT_CONFIGS}
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/tessdata/configs) DESTINATION ${CMAKE_INSTALL_PREFIX}/share/tessdata/configs)
install(FILES ${TESSERACT_TESSCONFIGS} install(FILES ${TESSERACT_TESSCONFIGS}
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/tessdata/tessconfigs) DESTINATION ${CMAKE_INSTALL_PREFIX}/share/tessdata/tessconfigs)
endif() endif()
# ############################################################################## # ##############################################################################