def build(self): if not self.is_emscripten( ) and self.settings.os == "Windows" and self.settings.compiler == "gcc": tools.replace_in_file( "%s/CMakeListsOriginal.txt" % self.source_subfolder, 'COMMAND "${CMAKE_COMMAND}" -E copy_if_different $<TARGET_LINKER_FILE_NAME:${S_TARGET}> $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE}', 'COMMAND "${CMAKE_COMMAND}" -E copy_if_different $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/$<TARGET_LINKER_FILE_NAME:${S_TARGET}> $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE}' ) # do not use _static suffix on VS if not self.is_emscripten( ) and self.settings.os == "Windows" and self.settings.compiler == "Visual Studio": tools.replace_in_file( "%s/CMakeListsOriginal.txt" % self.source_subfolder, 'OUTPUT_NAME "${PNG_LIB_NAME}_static', 'OUTPUT_NAME "${PNG_LIB_NAME}') if self.settings.build_type == 'Debug': tools.replace_in_file( os.path.join(self.source_subfolder, 'libpng.pc.in'), '-lpng@PNGLIB_MAJOR@@PNGLIB_MINOR@', '-lpng@PNGLIB_MAJOR@@PNGLIB_MINOR@d') if not self.is_emscripten( ) and 'arm' in self.settings.arch and self.settings.os == "Linux": tools.replace_in_file( os.path.join(self.source_subfolder, 'CMakeListsOriginal.txt'), 'PATHS /usr/lib /usr/local/lib', 'PATHS /usr/lib /usr/local/lib /usr/arm-linux-gnueabihf/lib /usr/arm-linux-gnueabi/lib ' ) if self.is_emscripten(): tools.replace_in_file( os.path.join(self.source_subfolder, 'CMakeListsOriginal.txt'), 'symbol_prefix()', '#symbol_prefix()') tools.replace_in_file( os.path.join(self.source_subfolder, 'CMakeListsOriginal.txt'), 'if(NOT M_LIBRARY)', 'set(M_LIBRARY "")\n if(NOT M_LIBRARY)') cmake = CMake(self) cmake.definitions['CMAKE_INSTALL_LIBDIR'] = 'lib' cmake.definitions['CMAKE_INSTALL_BINDIR'] = 'bin' cmake.definitions['CMAKE_INSTALL_INCLUDEDIR'] = 'include' cmake.definitions["PNG_TESTS"] = "OFF" if self.is_emscripten(): cmake.definitions["PNG_SHARED"] = "ON" cmake.definitions["PNG_STATIC"] = "OFF" else: cmake.definitions["PNG_SHARED"] = self.options.shared cmake.definitions["PNG_STATIC"] = not self.options.shared cmake.definitions[ "PNG_DEBUG"] = "OFF" if self.settings.build_type == "Release" else "ON" cmake.configure(source_folder=self.source_subfolder) cmake.build() cmake.install()
def build(self): emcc = self.is_emscripten() if self.options.with_openjpeg: # patch prefix for openjpeg pc file. # note the difference between pc name and package name shutil.copy( os.path.join(self.deps_cpp_info['openjpeg'].rootpath, 'lib', 'pkgconfig', 'libopenjp2.pc'), 'libopenjp2.pc') tools.replace_prefix_in_pc_file( "libopenjp2.pc", self.deps_cpp_info['openjpeg'].rootpath) # leptonica finds openjpeg.h in a wrong directory. just patch a pc file tools.replace_in_file("libopenjp2.pc", 'includedir=${prefix}/include/openjpeg-2.3', 'includedir=${prefix}/include') with tools.environment_append({'PKG_CONFIG_PATH': self.build_folder}): cmake = CMake(self) cmake.definitions[ 'STATIC'] = False if emcc else not self.options.shared cmake.definitions['BUILD_PROG'] = False # avoid finding system libs cmake.definitions[ 'CMAKE_DISABLE_FIND_PACKAGE_GIF'] = not self.options.with_gif cmake.definitions[ 'CMAKE_DISABLE_FIND_PACKAGE_PNG'] = not self.options.with_png cmake.definitions[ 'CMAKE_DISABLE_FIND_PACKAGE_TIFF'] = not self.options.with_tiff cmake.definitions[ 'CMAKE_DISABLE_FIND_PACKAGE_JPEG'] = not self.options.with_jpeg # avoid finding system libs by pkg-config by removing finders because they have no off switch if self.options.with_openjpeg: # check_include_files need to know where openjp2k resides tools.replace_in_file( os.path.join(self.source_subfolder, "CMakeListsOriginal.txt"), "pkg_check_modules(JP2K libopenjp2)", 'pkg_check_modules(JP2K libopenjp2)\n' 'list(APPEND CMAKE_REQUIRED_INCLUDES "${JP2K_INCLUDE_DIRS}")' ) else: tools.replace_in_file( os.path.join(self.source_subfolder, "CMakeListsOriginal.txt"), "pkg_check_modules(JP2K libopenjp2)", "") # webp does not provide .pc file but provide cmake configs. so use find_package instead if self.options.with_webp: tools.replace_in_file( os.path.join(self.source_subfolder, "CMakeListsOriginal.txt"), "pkg_check_modules(WEBP libwebp)", "find_package(WEBP REQUIRED NAMES WEBP WebP NO_SYSTEM_ENVIRONMENT_PATH)" ) else: tools.replace_in_file( os.path.join(self.source_subfolder, "CMakeListsOriginal.txt"), "pkg_check_modules(WEBP libwebp)", "") cmake.configure(source_folder=self.source_subfolder) cmake.build() cmake.install() self._fix_absolute_paths()
def build(self): with tools.chdir(os.path.join(self.source_folder, self.ZIP_FOLDER_NAME)): for filename in ['zconf.h', 'zconf.h.cmakein', 'zconf.h.in']: tools.replace_in_file(filename, '#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */', '#if defined(HAVE_UNISTD_H) && (1-HAVE_UNISTD_H-1 != 0)') tools.replace_in_file(filename, '#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */', '#if defined(HAVE_STDARG_H) && (1-HAVE_STDARG_H-1 != 0)') if self.is_emscripten(): tools.replace_in_file('CMakeLists.txt', 'add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})', '#iadd_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})') tools.replace_in_file('CMakeLists.txt', 'set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z)', 'set_target_properties(zlib PROPERTIES OUTPUT_NAME z)') tools.replace_in_file('CMakeLists.txt', 'install(TARGETS zlib zlibstatic', 'install(TARGETS zlib ') files.mkdir("_build") with tools.chdir("_build"): if not tools.os_info.is_windows and not self.is_emscripten(): env_build = AutoToolsBuildEnvironment(self) if self.settings.arch in ["x86", "x86_64"] and self.settings.compiler in ["apple-clang", "clang", "gcc"]: env_build.flags.append('-mstackrealign') env_build.fpic = True if self.settings.os == "Macos": old_str = '-install_name $libdir/$SHAREDLIBM' new_str = '-install_name $SHAREDLIBM' tools.replace_in_file("../configure", old_str, new_str) if self.settings.os == "Windows": # Cross building to Linux tools.replace_in_file( "../configure", 'LDSHAREDLIBC="${LDSHAREDLIBC--lc}"', 'LDSHAREDLIBC=""') # Zlib configure doesnt allow this parameters if self.settings.os == "iOS": tools.replace_in_file( "../gzguts.h", '#ifdef _LARGEFILE64_SOURCE', '#include <unistd.h>\n\n#ifdef _LARGEFILE64_SOURCE') if self.settings.os == "Windows" and tools.os_info.is_linux: # Let our profile to declare what is needed. tools.replace_in_file( "../win32/Makefile.gcc", 'LDFLAGS = $(LOC)', '') tools.replace_in_file( "../win32/Makefile.gcc", 'AS = $(CC)', '') tools.replace_in_file( "../win32/Makefile.gcc", 'AR = $(PREFIX)ar', '') tools.replace_in_file( "../win32/Makefile.gcc", 'CC = $(PREFIX)gcc', '') tools.replace_in_file( "../win32/Makefile.gcc", 'RC = $(PREFIX)windres', '') self.run("cd .. && make -f win32/Makefile.gcc") else: _args = ["--prefix=%s/build"%(os.getcwd())] if not self.options.shared: _args.extend(['--static']) env_build.configure( "../", build=False, host=False, target=False, args=_args) env_build.make() env_build.install() else: cmake = CMake(self) cmake.configure(build_dir=".") cmake.build(build_dir=".")
def build(self): emcc = self.is_emscripten() cmake = CMake(self) cmake.definitions['BUILD_TRAINING_TOOLS'] = False cmake.definitions["BUILD_SHARED_LIBS"] = True if emcc else self.options.shared cmake.definitions["STATIC"] = False if emcc else not self.options.shared if emcc: shutil.copy("helpers.js", os.path.join(self.source_subfolder, "helpers.js")) tools.replace_in_file(os.path.join(self.source_subfolder, "src/viewer/svpaint.cpp"), 'int main(int argc, char** argv) {', 'static int svpaint_main(int argc, char** argv) {') tools.replace_in_file(os.path.join(self.source_subfolder, "CMakeListsOriginal.txt"), 'PROPERTIES COMPILE_FLAGS "-msse4.1")', 'PROPERTIES COMPILE_FLAGS "")') tools.replace_in_file(os.path.join(self.source_subfolder, "CMakeListsOriginal.txt"), 'PROPERTIES COMPILE_FLAGS "-mavx")', 'PROPERTIES COMPILE_FLAGS "")') tools.replace_in_file(os.path.join(self.source_subfolder, "CMakeListsOriginal.txt"), 'PROPERTIES COMPILE_FLAGS "-mavx2")', 'PROPERTIES COMPILE_FLAGS "")') tools.replace_in_file(os.path.join(self.source_subfolder, "CMakeListsOriginal.txt"), 'target_link_libraries (tesseract libtesseract)', 'target_link_libraries (tesseract libtesseract)\n' + 'set(JS_HELPER "${CMAKE_CURRENT_SOURCE_DIR}/helpers.js")\n' + 'set(EMSCRIPTEN_LINK_FLAGS "--memory-init-file 0 -s TOTAL_MEMORY=134217728 ' + '-s ALLOW_MEMORY_GROWTH=1 -s DEMANGLE_SUPPORT=1")\n' + 'set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -Wno-missing-prototypes")\n' + 'set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} --pre-js ${JS_HELPER}")\n' + 'set_target_properties(tesseract PROPERTIES LINK_FLAGS ${EMSCRIPTEN_LINK_FLAGS})') tools.replace_in_file(os.path.join(self.source_subfolder, "src/api/baseapi.cpp"), 'locale = std::setlocale(LC_ALL, nullptr);', 'locale = std::setlocale(LC_ALL, nullptr);\n' + ' #ifdef __emscripten__\n' + " if (locale[0]=='C')\n" + ' locale="C"; // workaround for emscripten \n' + '#endif\n' ) # provide patched lept.pc shutil.copy(os.path.join(self.deps_cpp_info['leptonica'].rootpath, 'lib', 'pkgconfig', 'lept.pc'), 'lept.pc') tools.replace_prefix_in_pc_file("lept.pc", self.deps_cpp_info['leptonica'].rootpath) # VS build uses cmake to locate leptonica use_pkg_config = self.settings.compiler != "Visual Studio" # use cmake-based configure even for unix use_pkg_config = False # if static leptonica used with pkg-config, tesseract must use Leptonica_STATIC_LIBRARIES # which use static dependencies like jpeg, png etc provided by lept.pc if not emcc and not self.options['leptonica'].shared and use_pkg_config: tools.replace_in_file(os.path.join(self.source_subfolder, "CMakeListsOriginal.txt"), "target_link_libraries (libtesseract ${Leptonica_LIBRARIES})", "target_link_libraries (libtesseract ${Leptonica_STATIC_LIBRARIES})") if self.version == "3.05.01": # upstream bug: output name is not substituted for tesseract.pc # fixed in master but still an issue for stable tools.replace_in_file( os.path.join(self.source_subfolder, "CMakeListsOriginal.txt"), "set_target_properties (libtesseract PROPERTIES DEBUG_OUTPUT_NAME tesseract${VERSION_MAJOR}${VERSION_MINOR}d)", "set_target_properties (libtesseract PROPERTIES DEBUG_OUTPUT_NAME tesseract${VERSION_MAJOR}${VERSION_MINOR}d)\n" "else()\n" "set_target_properties (libtesseract PROPERTIES OUTPUT_NAME tesseract)\n") if not use_pkg_config: cmake.definitions['Leptonica_DIR'] = self.deps_cpp_info['leptonica'].rootpath with tools.environment_append({'PKG_CONFIG_PATH': self.build_folder}) if use_pkg_config else tools.no_op(): cmake.configure(source_folder=self.source_subfolder) cmake.build() cmake.install() self._fix_absolute_paths()
def build_cmake(self): # fix cmake that gather install targets from the wrong dir for bin_program in ['tjbench', 'cjpeg', 'djpeg', 'jpegtran']: tools.replace_in_file( "%s/CMakeLists_original.txt" % self.source_subfolder, '${CMAKE_CURRENT_BINARY_DIR}/' + bin_program + '-static.exe', '${CMAKE_CURRENT_BINARY_DIR}/bin/' + bin_program + '-static.exe') if self.is_emscripten(): tools.replace_in_file( "%s/CMakeLists_original.txt" % self.source_subfolder, 'message(FATAL_ERROR "Platform not supported by this build system. Use autotools instead.")', '#message(FATAL_ERROR "Platform not supported by this build system. Use autotools instead.")' ) tools.replace_in_file( "%s/CMakeLists_original.txt" % self.source_subfolder, 'set(COMPILE_FLAGS "-DGIF_SUPPORTED -DPPM_SUPPORTED -DUSE_SETMODE")', 'set(COMPILE_FLAGS "-DPPM_SUPPORTED")') tools.replace_in_file( "%s/CMakeLists_original.txt" % self.source_subfolder, 'set(COMPILE_FLAGS "-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED -DUSE_SETMODE")', 'set(COMPILE_FLAGS "-DBMP_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED")' ) #sharedlib tools.replace_in_file( "%s/sharedlib/CMakeLists.txt" % self.source_subfolder, 'set_property(TARGET jpegtran PROPERTY COMPILE_FLAGS "-DUSE_SETMODE")', '\n' + 'set_property(TARGET cjpeg PROPERTY LINK_FLAGS ${LINK_FLAGS})\n' + 'set_property(TARGET djpeg PROPERTY LINK_FLAGS ${LINK_FLAGS})\n' + 'set_property(TARGET jpegtran PROPERTY LINK_FLAGS ${LINK_FLAGS})\n' ) tools.replace_in_file( "%s/sharedlib/CMakeLists.txt" % self.source_subfolder, 'add_executable(cjpeg ../cjpeg.c ../cdjpeg.c ../rdgif.c ../rdppm.c', '\n' + 'set(JS_HELPER "${CMAKE_CURRENT_SOURCE_DIR}/helpers.js")\n' + 'set(COMPILE_FLAGS "-DBMP_SUPPORTED -DPPM_SUPPORTED -Wno-missing-prototypes")\n' + 'set(LINK_FLAGS " -s FORCE_FILESYSTEM=1 --pre-js ${JS_HELPER} -Wno-missing-prototypes")\n' + 'if(NOT WITH_12BIT)\n' + ' set(COMPILE_FLAGS "${COMPILE_FLAGS} -DTARGA_SUPPORTED")\n' + 'endif()\n' + 'add_executable(cjpeg ../cjpeg.c ../cdjpeg.c ../rdgif.c ../rdppm.c', '\n') os.system("ls -l && ls helpers -l") shutil.copy( "helpers/helpers.js", os.path.join(self.source_subfolder, "sharedlib/helpers.js")) for name in ['cjpeg', 'djpeg', 'jpegtran', 'md5cmp', 'tjunittest']: shutil.copy("helpers/%s" % name, name) else: tools.replace_in_file( "%s/CMakeLists_original.txt" % self.source_subfolder, 'add_test(tjunittest${suffix} tjunittest${suffix})', 'add_test(tjunittest${suffix} bin/tjunittest${suffix})') tools.replace_in_file( "%s/CMakeLists_original.txt" % self.source_subfolder, 'add_test(tjunittest${suffix}-alloc tjunittest${suffix} -alloc)', 'add_test(tjunittest${suffix}-alloc bin/tjunittest${suffix} -alloc)' ) tools.replace_in_file( "%s/CMakeLists_original.txt" % self.source_subfolder, 'add_test(tjunittest${suffix}-yuv tjunittest${suffix} -yuv)', 'add_test(tjunittest${suffix}-yuv bin/tjunittest${suffix} -yuv)' ) tools.replace_in_file( "%s/CMakeLists_original.txt" % self.source_subfolder, 'add_test(tjunittest${suffix}-yuv-alloc tjunittest${suffix} -yuv -alloc)', 'add_test(tjunittest${suffix}-yuv-alloc bin/tjunittest${suffix} -yuv -alloc)' ) tools.replace_in_file( "%s/CMakeLists_original.txt" % self.source_subfolder, 'add_test(tjunittest${suffix}-yuv-nopad tjunittest${suffix} -yuv -noyuvpad)', 'add_test(tjunittest${suffix}-yuv-nopad bin/tjunittest${suffix} -yuv -noyuvpad)' ) tools.replace_in_file( "%s/CMakeLists_original.txt" % self.source_subfolder, '# These tests are carefully chosen to provide full coverage of as many of the', '\n' + 'if(CMAKE_SYSTEM_NAME STREQUAL Emscripten)\n' + ' set(dir "" )\n' + ' set(MD5CMP "md5cmp")\n' + ' set(MD5_JPEG_3x2_FLOAT_PROG 9bca803d2042bd1eb03819e2bf92b3e5)\n' + ' set(MD5_PPM_3x2_FLOAT f6bfab038438ed8f5522fbd33595dcdc)\n' + 'else()\n' + ' set(dir "bin/" )\n' + ' set(MD5CMP "bin/md5cmp")\n' + 'endif()\n' + '# These tests are carefully chosen to provide full coverage of as many of the' ) cmake = CMake(self) cmake.definitions['ENABLE_STATIC'] = False if self.is_emscripten( ) else not self.options.shared cmake.definitions['ENABLE_SHARED'] = True if self.is_emscripten( ) else self.options.shared cmake.definitions['WITH_SIMD'] = False if self.is_emscripten( ) else self.options.SIMD cmake.definitions['WITH_ARITH_ENC'] = self.options.arithmetic_encoder cmake.definitions['WITH_ARITH_DEC'] = self.options.arithmetic_decoder cmake.definitions['WITH_JPEG7'] = self.options.libjpeg7_compatibility cmake.definitions['WITH_JPEG8'] = self.options.libjpeg8_compatibility cmake.definitions['WITH_MEM_SRCDST'] = self.options.mem_src_dst cmake.definitions['WITH_TURBOJPEG'] = self.options.turbojpeg cmake.definitions['WITH_JAVA'] = self.options.java cmake.definitions['WITH_12BIT'] = self.options.enable12bit cmake.configure(source_dir=self.source_subfolder) cmake.build() cmake.test() cmake.install()