From e87dc5b1f23058ccd63ac944d377a3595a14d84d Mon Sep 17 00:00:00 2001 From: Joel Gallant Date: Tue, 30 Oct 2018 12:00:32 -0600 Subject: [PATCH 1/4] Uses PROJECT_ variables instead of CMAKE_ variables so it can be included using add_subdirectory --- CMakeLists.txt | 54 +++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a5a1c880..8e19e1e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ cmake_minimum_required(VERSION 2.8.11) # In-source builds are disabled. -if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) +if ("${CMAKE_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") message(FATAL_ERROR "CMake generation is not possible within the source directory!" "\n Remove the CMakeCache.txt file and try again from another folder, e.g.:" @@ -25,7 +25,7 @@ endif() set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake") -set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin") +set(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/bin") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}") # Use solution folders. @@ -119,30 +119,30 @@ option(BUILD_TESTS "Build tests" OFF) # ############################################################################### -set(AUTOCONFIG_SRC ${CMAKE_BINARY_DIR}/config_auto.h.in) -set(AUTOCONFIG ${CMAKE_BINARY_DIR}/config_auto.h) +set(AUTOCONFIG_SRC ${PROJECT_BINARY_DIR}/config_auto.h.in) +set(AUTOCONFIG ${PROJECT_BINARY_DIR}/config_auto.h) -include(Configure) +include(${PROJECT_SOURCE_DIR}/cmake/Configure.cmake) configure_file(${AUTOCONFIG_SRC} ${AUTOCONFIG} @ONLY) set(INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include" "${CMAKE_INSTALL_PREFIX}/include/tesseract") configure_file( - ${CMAKE_SOURCE_DIR}/src/api/tess_version.h.in - ${CMAKE_BINARY_DIR}/api/tess_version.h @ONLY) + ${PROJECT_SOURCE_DIR}/src/api/tess_version.h.in + ${PROJECT_BINARY_DIR}/api/tess_version.h @ONLY) configure_file( - ${CMAKE_SOURCE_DIR}/src/vs2010/tesseract/tesseract.rc.in - ${CMAKE_BINARY_DIR}/vs2010/tesseract/tesseract.rc @ONLY) + ${PROJECT_SOURCE_DIR}/src/vs2010/tesseract/tesseract.rc.in + ${PROJECT_BINARY_DIR}/vs2010/tesseract/tesseract.rc @ONLY) configure_file( - ${CMAKE_SOURCE_DIR}/src/vs2010/tesseract/libtesseract.rc.in - ${CMAKE_BINARY_DIR}/vs2010/tesseract/libtesseract.rc @ONLY) + ${PROJECT_SOURCE_DIR}/src/vs2010/tesseract/libtesseract.rc.in + ${PROJECT_BINARY_DIR}/vs2010/tesseract/libtesseract.rc @ONLY) configure_file( - ${CMAKE_SOURCE_DIR}/cmake/templates/TesseractConfig-version.cmake.in - ${CMAKE_BINARY_DIR}/TesseractConfig-version.cmake @ONLY) + ${PROJECT_SOURCE_DIR}/cmake/templates/TesseractConfig-version.cmake.in + ${PROJECT_BINARY_DIR}/TesseractConfig-version.cmake @ONLY) configure_file( - ${CMAKE_SOURCE_DIR}/cmake/templates/TesseractConfig.cmake.in - ${CMAKE_BINARY_DIR}/TesseractConfig.cmake @ONLY) + ${PROJECT_SOURCE_DIR}/cmake/templates/TesseractConfig.cmake.in + ${PROJECT_BINARY_DIR}/TesseractConfig.cmake @ONLY) ############################################################################### # @@ -150,8 +150,8 @@ configure_file( # ############################################################################### -include(BuildFunctions) -include(SourceGroups) +include(${PROJECT_SOURCE_DIR}/cmake/BuildFunctions.cmake) +include(${PROJECT_SOURCE_DIR}/cmake/SourceGroups.cmake) add_definitions(-DHAVE_CONFIG_H) add_definitions(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS=1) @@ -159,10 +159,10 @@ add_definitions(-DWINDLLNAME="libtesseract${VERSION_MAJOR}${VERSION_MINOR}.dll") include_directories(${Leptonica_INCLUDE_DIRS}) -include_directories(${CMAKE_BINARY_DIR}) +include_directories(${PROJECT_BINARY_DIR}) include_directories(src/api) -include_directories(${CMAKE_BINARY_DIR}/api) +include_directories(${PROJECT_BINARY_DIR}/api) include_directories(src/arch) include_directories(src/ccmain) include_directories(src/ccstruct) @@ -230,7 +230,7 @@ if (WIN32) set(tesseract_hdr ${tesseract_hdr} ${CMAKE_CURRENT_SOURCE_DIR}/src/vs2010/tesseract/resource.h) - set(tesseract_rsc ${CMAKE_BINARY_DIR}/vs2010/tesseract/libtesseract.rc) + set(tesseract_rsc ${PROJECT_BINARY_DIR}/vs2010/tesseract/libtesseract.rc) set_source_files_properties( ${CMAKE_CURRENT_SOURCE_DIR}/src/arch/dotproductsse.cpp PROPERTIES COMPILE_DEFINITIONS __SSE4_1__) @@ -281,11 +281,11 @@ endif() if (NOT CPPAN_BUILD) target_link_libraries (libtesseract ${Leptonica_LIBRARIES}) - export(TARGETS libtesseract FILE ${CMAKE_BINARY_DIR}/TesseractTargets.cmake) + export(TARGETS libtesseract FILE ${PROJECT_BINARY_DIR}/TesseractTargets.cmake) else() target_link_libraries (libtesseract pvt.cppan.demo.danbloomberg.leptonica) - file(WRITE ${CMAKE_BINARY_DIR}/TesseractTargets.cmake "include(${CMAKE_BINARY_DIR}/cppan.cmake)\n") - export(TARGETS libtesseract APPEND FILE ${CMAKE_BINARY_DIR}/TesseractTargets.cmake) + file(WRITE ${PROJECT_BINARY_DIR}/TesseractTargets.cmake "include(${PROJECT_BINARY_DIR}/cppan.cmake)\n") + export(TARGETS libtesseract APPEND FILE ${PROJECT_BINARY_DIR}/TesseractTargets.cmake) endif() ######################################## @@ -294,7 +294,7 @@ endif() set(tesseractmain_src src/api/tesseractmain.cpp) if (MSVC) - set(tesseractmain_rsc ${CMAKE_BINARY_DIR}/vs2010/tesseract/tesseract.rc) + set(tesseractmain_rsc ${PROJECT_BINARY_DIR}/vs2010/tesseract/tesseract.rc) endif() add_executable (tesseract ${tesseractmain_src} ${tesseractmain_rsc}) @@ -321,8 +321,8 @@ install(TARGETS tesseract RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIV install(TARGETS libtesseract EXPORT TesseractTargets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(EXPORT TesseractTargets DESTINATION cmake) install(FILES - ${CMAKE_BINARY_DIR}/TesseractConfig.cmake - ${CMAKE_BINARY_DIR}/TesseractConfig-version.cmake + ${PROJECT_BINARY_DIR}/TesseractConfig.cmake + ${PROJECT_BINARY_DIR}/TesseractConfig-version.cmake DESTINATION cmake) install(FILES @@ -394,7 +394,7 @@ install(FILES src/lstm/tfnetwork.h src/lstm/weightmatrix.h - #${CMAKE_BINARY_DIR}/src/endianness.h + #${PROJECT_BINARY_DIR}/src/endianness.h DESTINATION include/tesseract) From a4cb790e1d8cfb11580eaab0c826ed5f1adb5f11 Mon Sep 17 00:00:00 2001 From: Joel Gallant Date: Tue, 30 Oct 2018 12:27:34 -0600 Subject: [PATCH 2/4] Reverts change on EXECUTABLE_OUTPUT_PATH --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e19e1e2..43f8dbfd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ endif() set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake") -set(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/bin") +set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}") # Use solution folders. From 58328405ec9402b06f03f11eac5fae1c154ab947 Mon Sep 17 00:00:00 2001 From: Joel Gallant Date: Tue, 30 Oct 2018 12:49:14 -0600 Subject: [PATCH 3/4] Adjusts CMAKE_MODULE_PATH instead of the include()'s --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 43f8dbfd..3c459ac0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ if ("${CMAKE_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") ) endif() -set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake") +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake;${PROJECT_SOURCE_DIR}/cmake") set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}") @@ -122,7 +122,7 @@ option(BUILD_TESTS "Build tests" OFF) set(AUTOCONFIG_SRC ${PROJECT_BINARY_DIR}/config_auto.h.in) set(AUTOCONFIG ${PROJECT_BINARY_DIR}/config_auto.h) -include(${PROJECT_SOURCE_DIR}/cmake/Configure.cmake) +include(Configure) configure_file(${AUTOCONFIG_SRC} ${AUTOCONFIG} @ONLY) @@ -150,8 +150,8 @@ configure_file( # ############################################################################### -include(${PROJECT_SOURCE_DIR}/cmake/BuildFunctions.cmake) -include(${PROJECT_SOURCE_DIR}/cmake/SourceGroups.cmake) +include(BuildFunctions) +include(SourceGroups) add_definitions(-DHAVE_CONFIG_H) add_definitions(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS=1) From 422d1ca25a5c90c45b1b37a87fd35cf52ce0cb9e Mon Sep 17 00:00:00 2001 From: Joel Gallant Date: Tue, 30 Oct 2018 12:58:50 -0600 Subject: [PATCH 4/4] Uses CMAKE_CURRENT_ variables instead of PROJECT_ --- CMakeLists.txt | 52 +++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c459ac0..c05661b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ cmake_minimum_required(VERSION 2.8.11) # In-source builds are disabled. -if ("${CMAKE_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") +if ("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") message(FATAL_ERROR "CMake generation is not possible within the source directory!" "\n Remove the CMakeCache.txt file and try again from another folder, e.g.:" @@ -23,7 +23,7 @@ if ("${CMAKE_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") ) endif() -set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake;${PROJECT_SOURCE_DIR}/cmake") +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake") set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}") @@ -91,7 +91,7 @@ endif() # ############################################################################### -if(NOT EXISTS ${PROJECT_SOURCE_DIR}/.cppan) +if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.cppan) if (NOT Leptonica_DIR AND NOT MSVC) find_package(PkgConfig REQUIRED) pkg_check_modules(Leptonica REQUIRED lept>=${MINIMUM_LEPTONICA_VERSION}) @@ -119,8 +119,8 @@ option(BUILD_TESTS "Build tests" OFF) # ############################################################################### -set(AUTOCONFIG_SRC ${PROJECT_BINARY_DIR}/config_auto.h.in) -set(AUTOCONFIG ${PROJECT_BINARY_DIR}/config_auto.h) +set(AUTOCONFIG_SRC ${CMAKE_CURRENT_BINARY_DIR}/config_auto.h.in) +set(AUTOCONFIG ${CMAKE_CURRENT_BINARY_DIR}/config_auto.h) include(Configure) @@ -129,20 +129,20 @@ configure_file(${AUTOCONFIG_SRC} ${AUTOCONFIG} @ONLY) set(INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include" "${CMAKE_INSTALL_PREFIX}/include/tesseract") configure_file( - ${PROJECT_SOURCE_DIR}/src/api/tess_version.h.in - ${PROJECT_BINARY_DIR}/api/tess_version.h @ONLY) + ${CMAKE_CURRENT_SOURCE_DIR}/src/api/tess_version.h.in + ${CMAKE_CURRENT_BINARY_DIR}/api/tess_version.h @ONLY) configure_file( - ${PROJECT_SOURCE_DIR}/src/vs2010/tesseract/tesseract.rc.in - ${PROJECT_BINARY_DIR}/vs2010/tesseract/tesseract.rc @ONLY) + ${CMAKE_CURRENT_SOURCE_DIR}/src/vs2010/tesseract/tesseract.rc.in + ${CMAKE_CURRENT_BINARY_DIR}/vs2010/tesseract/tesseract.rc @ONLY) configure_file( - ${PROJECT_SOURCE_DIR}/src/vs2010/tesseract/libtesseract.rc.in - ${PROJECT_BINARY_DIR}/vs2010/tesseract/libtesseract.rc @ONLY) + ${CMAKE_CURRENT_SOURCE_DIR}/src/vs2010/tesseract/libtesseract.rc.in + ${CMAKE_CURRENT_BINARY_DIR}/vs2010/tesseract/libtesseract.rc @ONLY) configure_file( - ${PROJECT_SOURCE_DIR}/cmake/templates/TesseractConfig-version.cmake.in - ${PROJECT_BINARY_DIR}/TesseractConfig-version.cmake @ONLY) + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/TesseractConfig-version.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/TesseractConfig-version.cmake @ONLY) configure_file( - ${PROJECT_SOURCE_DIR}/cmake/templates/TesseractConfig.cmake.in - ${PROJECT_BINARY_DIR}/TesseractConfig.cmake @ONLY) + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/TesseractConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/TesseractConfig.cmake @ONLY) ############################################################################### # @@ -159,10 +159,10 @@ add_definitions(-DWINDLLNAME="libtesseract${VERSION_MAJOR}${VERSION_MINOR}.dll") include_directories(${Leptonica_INCLUDE_DIRS}) -include_directories(${PROJECT_BINARY_DIR}) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(src/api) -include_directories(${PROJECT_BINARY_DIR}/api) +include_directories(${CMAKE_CURRENT_BINARY_DIR}/api) include_directories(src/arch) include_directories(src/ccmain) include_directories(src/ccstruct) @@ -230,7 +230,7 @@ if (WIN32) set(tesseract_hdr ${tesseract_hdr} ${CMAKE_CURRENT_SOURCE_DIR}/src/vs2010/tesseract/resource.h) - set(tesseract_rsc ${PROJECT_BINARY_DIR}/vs2010/tesseract/libtesseract.rc) + set(tesseract_rsc ${CMAKE_CURRENT_BINARY_DIR}/vs2010/tesseract/libtesseract.rc) set_source_files_properties( ${CMAKE_CURRENT_SOURCE_DIR}/src/arch/dotproductsse.cpp PROPERTIES COMPILE_DEFINITIONS __SSE4_1__) @@ -281,11 +281,11 @@ endif() if (NOT CPPAN_BUILD) target_link_libraries (libtesseract ${Leptonica_LIBRARIES}) - export(TARGETS libtesseract FILE ${PROJECT_BINARY_DIR}/TesseractTargets.cmake) + export(TARGETS libtesseract FILE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake) else() target_link_libraries (libtesseract pvt.cppan.demo.danbloomberg.leptonica) - file(WRITE ${PROJECT_BINARY_DIR}/TesseractTargets.cmake "include(${PROJECT_BINARY_DIR}/cppan.cmake)\n") - export(TARGETS libtesseract APPEND FILE ${PROJECT_BINARY_DIR}/TesseractTargets.cmake) + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake "include(${CMAKE_CURRENT_BINARY_DIR}/cppan.cmake)\n") + export(TARGETS libtesseract APPEND FILE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake) endif() ######################################## @@ -294,7 +294,7 @@ endif() set(tesseractmain_src src/api/tesseractmain.cpp) if (MSVC) - set(tesseractmain_rsc ${PROJECT_BINARY_DIR}/vs2010/tesseract/tesseract.rc) + set(tesseractmain_rsc ${CMAKE_CURRENT_BINARY_DIR}/vs2010/tesseract/tesseract.rc) endif() add_executable (tesseract ${tesseractmain_src} ${tesseractmain_rsc}) @@ -302,7 +302,7 @@ target_link_libraries (tesseract libtesseract) ######################################## -if (BUILD_TESTS AND EXISTS ${PROJECT_SOURCE_DIR}/googletest/CMakeLists.txt) +if (BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/googletest/CMakeLists.txt) add_subdirectory(googletest) add_executable(tesseract_tests tests/tesseracttests.cpp) target_link_libraries(tesseract_tests gtest_main) @@ -321,8 +321,8 @@ install(TARGETS tesseract RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIV install(TARGETS libtesseract EXPORT TesseractTargets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(EXPORT TesseractTargets DESTINATION cmake) install(FILES - ${PROJECT_BINARY_DIR}/TesseractConfig.cmake - ${PROJECT_BINARY_DIR}/TesseractConfig-version.cmake + ${CMAKE_CURRENT_BINARY_DIR}/TesseractConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/TesseractConfig-version.cmake DESTINATION cmake) install(FILES @@ -394,7 +394,7 @@ install(FILES src/lstm/tfnetwork.h src/lstm/weightmatrix.h - #${PROJECT_BINARY_DIR}/src/endianness.h + #${CMAKE_CURRENT_BINARY_DIR}/src/endianness.h DESTINATION include/tesseract)