From 04e9643766837593b051efeac2c6ba23f9c286d1 Mon Sep 17 00:00:00 2001 From: Kamile Demir Date: Wed, 29 Jun 2022 14:17:57 -0700 Subject: [PATCH] [CMake] Statically link libxml2 for Linux --- CMakeLists.txt | 11 +++++++---- c/makeotf/lib/cffread/CMakeLists.txt | 4 +++- c/makeotf/lib/hotconv/CMakeLists.txt | 2 +- c/makeotf/lib/pstoken/CMakeLists.txt | 2 +- c/makeotf/lib/typecomp/CMakeLists.txt | 2 +- c/makeotf/source/CMakeLists.txt | 2 +- c/mergefonts/source/CMakeLists.txt | 2 +- c/rotatefont/source/CMakeLists.txt | 2 +- c/shared/source/CMakeLists.txt | 7 ++++--- c/tx/source/CMakeLists.txt | 2 +- cmake/ExternalLibXML2.cmake | 5 ++++- docs/FDK_Build_Notes.md | 3 +++ 12 files changed, 28 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ce80598c..a24230225 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,13 +42,16 @@ set(ANTLR4_WITH_STATIC_CRT OFF) set(ANTLR4_TAG tags/4.9.3) include(ExternalAntlr4Cpp) + FIND_PACKAGE(LibXml2) -IF (NOT ${LibXml2_FOUND}) - MESSAGE(STATUS "Could not locate LibXml2, will install externally.") +IF ((NOT ${LibXml2_FOUND}) OR "${CMAKE_SYSTEM}" MATCHES "Linux") + MESSAGE(STATUS "Could not locate LibXml2 or system is Linux, will install externally & statically link") set(LIBXML2_TAG tags/v2.9.13) include(ExternalLibXML2) -ENDIF(NOT ${LibXml2_FOUND}) -include_directories(${LIBXML2_INCLUDE_DIR}) + include_directories(${LIBXML2_STATIC_INCLUDE_DIR}) +ELSE ((NOT ${LibXml2_FOUND}) OR "${CMAKE_SYSTEM}" MATCHES "Linux") + include_directories(${LIBXML2_INCLUDE_DIR}) +ENDIF((NOT ${LibXml2_FOUND}) OR "${CMAKE_SYSTEM}" MATCHES "Linux") # sanitizer support # work around https://github.com/pypa/setuptools/issues/1928 with environment diff --git a/c/makeotf/lib/cffread/CMakeLists.txt b/c/makeotf/lib/cffread/CMakeLists.txt index 9a400fdef..289c6deb1 100644 --- a/c/makeotf/lib/cffread/CMakeLists.txt +++ b/c/makeotf/lib/cffread/CMakeLists.txt @@ -2,9 +2,11 @@ add_library(makeotf_cffread STATIC cffread.c) target_include_directories(makeotf_cffread PRIVATE AFTER $<$:${ANTLR4_INCLUDE_DIRS}>) -if (${LibXml2_FOUND}) +if ((${LibXml2_FOUND}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux")) + message("====IN (LIBXML2 FOUND)=====") target_link_libraries(makeotf_cffread PUBLIC ${LIBXML2_LIBRARY}) else () + message("====IN (LINUX, CORRECT)=====") add_dependencies(makeotf_cffread ${LIBXML2_TARGET}) if (WIN32) target_link_libraries(makeotf_cffread PUBLIC ${LIBXML2_WIN_LIBRARIES}) diff --git a/c/makeotf/lib/hotconv/CMakeLists.txt b/c/makeotf/lib/hotconv/CMakeLists.txt index 3cceceeab..14e5c3cdf 100644 --- a/c/makeotf/lib/hotconv/CMakeLists.txt +++ b/c/makeotf/lib/hotconv/CMakeLists.txt @@ -71,7 +71,7 @@ set_property(TARGET hotconv PROPERTY C_STANDARD 99) target_include_directories(hotconv PRIVATE AFTER $<$:${ANTLR4_INCLUDE_DIRS}>) target_link_libraries(hotconv PUBLIC antlr4_static) -if (${LibXml2_FOUND}) +if ((${LibXml2_FOUND}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux")) target_link_libraries(hotconv PUBLIC ${LIBXML2_LIBRARY}) else () add_dependencies(hotconv ${LIBXML2_TARGET}) diff --git a/c/makeotf/lib/pstoken/CMakeLists.txt b/c/makeotf/lib/pstoken/CMakeLists.txt index 1f928976f..a0fd67d3e 100644 --- a/c/makeotf/lib/pstoken/CMakeLists.txt +++ b/c/makeotf/lib/pstoken/CMakeLists.txt @@ -1,6 +1,6 @@ add_library(makeotf_pstoken STATIC pstoken.c) -if (${LibXml2_FOUND}) +if ((${LibXml2_FOUND}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux")) target_link_libraries(makeotf_pstoken PUBLIC ${LIBXML2_LIBRARY}) else () add_dependencies(makeotf_pstoken ${LIBXML2_TARGET}) diff --git a/c/makeotf/lib/typecomp/CMakeLists.txt b/c/makeotf/lib/typecomp/CMakeLists.txt index 39cbd8a58..ce6e3592e 100644 --- a/c/makeotf/lib/typecomp/CMakeLists.txt +++ b/c/makeotf/lib/typecomp/CMakeLists.txt @@ -45,7 +45,7 @@ add_library(typecomp STATIC tc.c ) -if (${LibXml2_FOUND}) +if ((${LibXml2_FOUND}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux")) target_link_libraries(typecomp PUBLIC ${LIBXML2_LIBRARY}) else () add_dependencies(typecomp ${LIBXML2_TARGET}) diff --git a/c/makeotf/source/CMakeLists.txt b/c/makeotf/source/CMakeLists.txt index 5f15b3a02..625c4b0ba 100644 --- a/c/makeotf/source/CMakeLists.txt +++ b/c/makeotf/source/CMakeLists.txt @@ -27,7 +27,7 @@ if (HAVE_M_LIB) target_link_libraries(makeotfexe PRIVATE m) endif () -if (${LibXml2_FOUND}) +if ((${LibXml2_FOUND}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux")) target_link_libraries(makeotfexe PUBLIC ${LIBXML2_LIBRARY}) else () if (WIN32) diff --git a/c/mergefonts/source/CMakeLists.txt b/c/mergefonts/source/CMakeLists.txt index b77d1ef4c..4c87283b5 100644 --- a/c/mergefonts/source/CMakeLists.txt +++ b/c/mergefonts/source/CMakeLists.txt @@ -9,7 +9,7 @@ target_include_directories(mergefonts PRIVATE ../../shared/include ../../shared/ target_link_libraries(mergefonts PUBLIC tx_shared) -if (${LibXml2_FOUND}) +if ((${LibXml2_FOUND}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux")) target_link_libraries(mergefonts PUBLIC ${LIBXML2_LIBRARY}) else () add_dependencies(mergefonts ${LIBXML2_TARGET}) diff --git a/c/rotatefont/source/CMakeLists.txt b/c/rotatefont/source/CMakeLists.txt index 6d3660d32..69bfcebfe 100644 --- a/c/rotatefont/source/CMakeLists.txt +++ b/c/rotatefont/source/CMakeLists.txt @@ -9,7 +9,7 @@ target_include_directories(rotatefont PRIVATE ../../shared/include ../../shared/ target_link_libraries(rotatefont PUBLIC tx_shared) -if(${LibXml2_FOUND}) +if ((${LibXml2_FOUND}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux")) target_link_libraries(rotatefont PUBLIC ${LIBXML2_LIBRARY}) else() add_dependencies(rotatefont ${LIBXML2_TARGET}) diff --git a/c/shared/source/CMakeLists.txt b/c/shared/source/CMakeLists.txt index f6a4ca04e..e48c51334 100644 --- a/c/shared/source/CMakeLists.txt +++ b/c/shared/source/CMakeLists.txt @@ -3,9 +3,10 @@ include_directories(../include ../resource) MACRO(ADD_AFDKOLIB lm) file(GLOB sl_sources "${lm}/*") add_library(${lm} STATIC ${sl_sources}) - if(NOT ${LibXml2_FOUND}) + if((NOT ${LibXml2_FOUND}) OR "${CMAKE_SYSTEM}" MATCHES "Linux") + message("dependency being added...") add_dependencies(${lm} ${LIBXML2_TARGET}) - endif(NOT ${LibXml2_FOUND}) + endif((NOT ${LibXml2_FOUND}) OR "${CMAKE_SYSTEM}" MATCHES "Linux") ENDMACRO(ADD_AFDKOLIB) ADD_AFDKOLIB(absfont) @@ -47,7 +48,7 @@ target_compile_definitions(t1write PRIVATE $<$:T1W_DEBUG=1>) target_compile_definitions(ttread PRIVATE $<$:TTR_DEBUG=1>) target_compile_definitions(tx_shared PRIVATE $<$:CFW_DEBUG=1>) -if(${LibXml2_FOUND}) +if ((${LibXml2_FOUND}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux")) target_link_libraries(tx_shared PUBLIC ${LIBXML2_LIBRARY}) else() target_compile_definitions(tx_shared PUBLIC -DLIBXML_STATIC) diff --git a/c/tx/source/CMakeLists.txt b/c/tx/source/CMakeLists.txt index 684cb7ed1..dad21cc67 100644 --- a/c/tx/source/CMakeLists.txt +++ b/c/tx/source/CMakeLists.txt @@ -8,7 +8,7 @@ add_executable(tx target_include_directories(tx PRIVATE ../../shared/include ../../shared/resource ../../shared/source/tx_shared) target_link_libraries(tx PUBLIC tx_shared) -if(${LibXml2_FOUND}) +if ((${LibXml2_FOUND}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux")) target_link_libraries(tx PUBLIC ${LIBXML2_LIBRARY}) else() add_dependencies(tx ${LIBXML2_TARGET}) diff --git a/cmake/ExternalLibXML2.cmake b/cmake/ExternalLibXML2.cmake index df4233b9b..b18e528b4 100644 --- a/cmake/ExternalLibXML2.cmake +++ b/cmake/ExternalLibXML2.cmake @@ -43,7 +43,10 @@ set_target_properties(libxml2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${SOURCE_DIR}/include) target_include_directories(libxml2 INTERFACE ${SOURCE_DIR}/include INTERFACE ${BINARY_DIR}) -set(LIBXML2_INCLUDE_DIR ${SOURCE_DIR}/include ${BINARY_DIR}) +message("SOURCEDIR/INCLUDE: ${SOURCE_DIR}/include") +message("BINARYDIR/INCLUDE: ${BINARY_DIR}") + +set(LIBXML2_STATIC_INCLUDE_DIR ${SOURCE_DIR}/include ${BINARY_DIR}) set(LIBXML2_WIN_LIBRARIES wsock32 ws2_32 libxml2) diff --git a/docs/FDK_Build_Notes.md b/docs/FDK_Build_Notes.md index f0af7d9e1..ea59c7fa3 100644 --- a/docs/FDK_Build_Notes.md +++ b/docs/FDK_Build_Notes.md @@ -48,6 +48,9 @@ Note that unless you are using macOS or Windows you must have `libuuid` and its If the build is successful each program (e.g. makeotfexe) will be built as `build/bin/[program]`. If you would like to install them in `/usr/local/bin` you can then run `cmake --build build -- install`. +AFDKO uses libxml2 for parsing in tx. If libxml2 is not found in the system, it will be installed through CMake externally in `ExternalLibXML2.cmake` and statically linked. This is usually the case for Windows. +Currently, libxml2 will also be statically linked in Linux due to a [bug found in the linux python wheels when dynamically linked](https://github.com/adobe-type-tools/afdko/issues/1525). + ### Noted CMake options These options can be added to the end of the first CMake command above: