Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify cmake libxml build logic #1597

Merged
merged 1 commit into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/testpythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
run: |
echo "CMAKE_GENERATOR=Visual Studio 17 2022" >> $GITHUB_ENV
echo "CMAKE_GENERATOR_PLATFORM=x64" >> $GITHUB_ENV
echo "FORCE_BUILD_LIBXML2=ON" >> $GITHUB_ENV
shell: bash

- name: Install dependencies
Expand Down
38 changes: 29 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,35 @@ set(ANTLR4_TAG tags/4.9.3)
include(ExternalAntlr4Cpp)


FIND_PACKAGE(LibXml2)
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)
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")
if (DEFINED ENV{FORCE_BUILD_LIBXML2} OR ("${CMAKE_SYSTEM}" MATCHES "Linux" AND NOT DEFINED ENV{FORCE_SYSTEM_LIBXML2}))
set(BUILD_STATIC_LIBXML2 TRUE)
else()
FIND_PACKAGE(LibXml2)
if (${LibXml2_FOUND})
set(BUILD_STATIC_LIBXML2 FALSE)
elseif (DEFINED ENV{FORCE_SYSTEM_LIBXML2})
message(FATAL_ERROR "FORCE_SYSTEM_LIBXML2 set but LibXML2 not found")
else()
set(BUILD_STATIC_LIBXML2 TRUE)
endif()
endif()

if (${BUILD_STATIC_LIBXML2})
message(STATUS "LibXML2 not found or overridden -- will download and statically link")
set(LIBXML2_TAG tags/v2.9.13)
include(ExternalLibXML2)
include_directories(${LIBXML2_STATIC_INCLUDE_DIR})
set(NEED_LIBXML2_DEPEND TRUE)
if (WIN32)
set(CHOSEN_LIBXML2_LIBRARY ${LIBXML2_WIN_LIBRARIES})
else()
set(CHOSEN_LIBXML2_LIBRARY ${LIBXML2_NONWIN_LIBRARIES})
endif()
else()
include_directories(${LIBXML2_INCLUDE_DIR})
set(NEED_LIBXML2_DEPEND FALSE)
set(CHOSEN_LIBXML2_LIBRARY ${LIBXML2_LIBRARY})
endif()

# sanitizer support
# work around https://github.com/pypa/setuptools/issues/1928 with environment
Expand Down
11 changes: 3 additions & 8 deletions c/makeotf/lib/cffread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@ add_library(makeotf_cffread STATIC cffread.c)

target_include_directories(makeotf_cffread PRIVATE AFTER $<$<COMPILE_LANGUAGE:CXX>:${ANTLR4_INCLUDE_DIRS}>)

if ((${LibXml2_FOUND}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux"))
target_link_libraries(makeotf_cffread PUBLIC ${LIBXML2_LIBRARY})
else ()
target_link_libraries(makeotf_cffread PUBLIC ${CHOSEN_LIBXML2_LIBRARY})

if (${NEED_LIBXML2_DEPEND})
add_dependencies(makeotf_cffread ${LIBXML2_TARGET})
if (WIN32)
target_link_libraries(makeotf_cffread PUBLIC ${LIBXML2_WIN_LIBRARIES})
else ()
target_link_libraries(makeotf_cffread PUBLIC ${LIBXML2_NONWIN_LIBRARIES})
endif()
endif()

target_link_libraries(makeotf_cffread PUBLIC antlr4_static)
Expand Down
11 changes: 3 additions & 8 deletions c/makeotf/lib/hotconv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,10 @@ set_property(TARGET hotconv PROPERTY C_STANDARD 99)
target_include_directories(hotconv PRIVATE AFTER $<$<COMPILE_LANGUAGE:CXX>:${ANTLR4_INCLUDE_DIRS}>)
target_link_libraries(hotconv PUBLIC antlr4_static)

if ((${LibXml2_FOUND}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux"))
target_link_libraries(hotconv PUBLIC ${LIBXML2_LIBRARY})
else ()
target_link_libraries(hotconv PUBLIC ${CHOSEN_LIBXML2_LIBRARY})

if (${NEED_LIBXML2_DEPEND})
add_dependencies(hotconv ${LIBXML2_TARGET})
if (WIN32)
target_link_libraries(hotconv PUBLIC ${LIBXML2_WIN_LIBRARIES})
else ()
target_link_libraries(hotconv PUBLIC ${LIBXML2_NONWIN_LIBRARIES})
endif()
endif()

if ( CMAKE_COMPILER_IS_GNUCC )
Expand Down
11 changes: 3 additions & 8 deletions c/makeotf/lib/pstoken/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
add_library(makeotf_pstoken STATIC pstoken.c)

if ((${LibXml2_FOUND}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux"))
target_link_libraries(makeotf_pstoken PUBLIC ${LIBXML2_LIBRARY})
else ()
target_link_libraries(makeotf_pstoken PUBLIC ${CHOSEN_LIBXML2_LIBRARY})

if (${NEED_LIBXML2_DEPEND})
add_dependencies(makeotf_pstoken ${LIBXML2_TARGET})
if (WIN32)
target_link_libraries(makeotf_pstoken PUBLIC ${LIBXML2_WIN_LIBRARIES})
else ()
target_link_libraries(makeotf_pstoken PUBLIC ${LIBXML2_NONWIN_LIBRARIES})
endif()
endif()

target_compile_definitions(makeotf_pstoken PRIVATE PSTOKEN_DEBUG=1 CFF_DEBUG=1 CFF_T13_SUPPORT=0)
10 changes: 2 additions & 8 deletions c/makeotf/lib/typecomp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,9 @@ add_library(typecomp STATIC
tc.c
)

if ((${LibXml2_FOUND}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux"))
target_link_libraries(typecomp PUBLIC ${LIBXML2_LIBRARY})
else ()
target_link_libraries(typecomp PUBLIC ${CHOSEN_LIBXML2_LIBRARY})
if (${NEED_LIBXML2_DEPEND})
add_dependencies(typecomp ${LIBXML2_TARGET})
if (WIN32)
target_link_libraries(typecomp PUBLIC ${LIBXML2_WIN_LIBRARIES})
else ()
target_link_libraries(typecomp PUBLIC ${LIBXML2_NONWIN_LIBRARIES})
endif()
endif()

target_compile_definitions(typecomp PRIVATE
Expand Down
10 changes: 1 addition & 9 deletions c/makeotf/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,7 @@ if (HAVE_M_LIB)
target_link_libraries(makeotfexe PRIVATE m)
endif ()

if ((${LibXml2_FOUND}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux"))
target_link_libraries(makeotfexe PUBLIC ${LIBXML2_LIBRARY})
else ()
if (WIN32)
target_link_libraries(makeotfexe PUBLIC ${LIBXML2_WIN_LIBRARIES})
else ()
target_link_libraries(makeotfexe PUBLIC ${LIBXML2_NONWIN_LIBRARIES})
endif()
endif()
target_link_libraries(makeotfexe PUBLIC ${CHOSEN_LIBXML2_LIBRARY})

target_compile_definitions(makeotfexe PRIVATE MAKEOTFLIB_EXPORTS=1)

Expand Down
10 changes: 2 additions & 8 deletions c/mergefonts/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,11 @@ add_executable(mergefonts
target_include_directories(mergefonts PRIVATE ../../shared/include ../../shared/resource ../../shared/source/tx_shared)

target_link_libraries(mergefonts PUBLIC tx_shared)
target_link_libraries(mergefonts PUBLIC ${CHOSEN_LIBXML2_LIBRARY})

if ((${LibXml2_FOUND}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux"))
target_link_libraries(mergefonts PUBLIC ${LIBXML2_LIBRARY})
else ()
if (${NEED_LIBXML_DEPEND})
add_dependencies(mergefonts ${LIBXML2_TARGET})
target_compile_definitions(mergefonts PUBLIC -DLIBXML_STATIC)
if (WIN32)
target_link_libraries(mergefonts PUBLIC ${LIBXML2_WIN_LIBRARIES})
else ()
target_link_libraries(mergefonts PUBLIC ${LIBXML2_NONWIN_LIBRARIES})
endif()
endif()

install(TARGETS mergefonts DESTINATION bin)
11 changes: 3 additions & 8 deletions c/rotatefont/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@ target_include_directories(rotatefont PRIVATE ../../shared/include ../../shared/

target_link_libraries(rotatefont PUBLIC tx_shared)

if ((${LibXml2_FOUND}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux"))
target_link_libraries(rotatefont PUBLIC ${LIBXML2_LIBRARY})
else()
target_link_libraries(rotatefont PUBLIC ${CHOSEN_LIBXML2_LIBRARY})

if (${NEED_LIBXML2_DEPEND})
add_dependencies(rotatefont ${LIBXML2_TARGET})
target_compile_definitions(rotatefont PUBLIC -DLIBXML_STATIC)
if (WIN32)
target_link_libraries(rotatefont PUBLIC ${LIBXML2_WIN_LIBRARIES})
else ()
target_link_libraries(rotatefont PUBLIC ${LIBXML2_NONWIN_LIBRARIES})
endif()
endif()

install(TARGETS rotatefont DESTINATION bin)
15 changes: 5 additions & 10 deletions c/shared/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ include_directories(../include ../resource)
MACRO(ADD_AFDKOLIB lm)
file(GLOB sl_sources "${lm}/*")
add_library(${lm} STATIC ${sl_sources})
if((NOT ${LibXml2_FOUND}) OR "${CMAKE_SYSTEM}" MATCHES "Linux")
if(${NEED_LIBXML2_DEPEND})
add_dependencies(${lm} ${LIBXML2_TARGET})
endif((NOT ${LibXml2_FOUND}) OR "${CMAKE_SYSTEM}" MATCHES "Linux")
endif(${NEED_LIBXML2_DEPEND})
ENDMACRO(ADD_AFDKOLIB)

ADD_AFDKOLIB(absfont)
Expand Down Expand Up @@ -47,15 +47,10 @@ target_compile_definitions(t1write PRIVATE $<$<CONFIG:Debug>:T1W_DEBUG=1>)
target_compile_definitions(ttread PRIVATE $<$<CONFIG:Debug>:TTR_DEBUG=1>)
target_compile_definitions(tx_shared PRIVATE $<$<CONFIG:Debug>:CFW_DEBUG=1>)

if ((${LibXml2_FOUND}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux"))
target_link_libraries(tx_shared PUBLIC ${LIBXML2_LIBRARY})
else()
target_link_libraries(tx_shared PUBLIC ${CHOSEN_LIBXML2_LIBRARY})

if (${NEED_LIBXML2_DEPEND})
target_compile_definitions(tx_shared PUBLIC -DLIBXML_STATIC)
if (WIN32)
target_link_libraries(tx_shared PUBLIC ${LIBXML2_WIN_LIBRARIES})
else ()
target_link_libraries(tx_shared PUBLIC ${LIBXML2_NONWIN_LIBRARIES})
endif()
endif()

# These libraries are partially ordered
Expand Down
10 changes: 2 additions & 8 deletions c/tx/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@ 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}) AND (NOT "${CMAKE_SYSTEM}" MATCHES "Linux"))
target_link_libraries(tx PUBLIC ${LIBXML2_LIBRARY})
else()
target_link_libraries(tx PUBLIC ${CHOSEN_LIBXML2_LIBRARY})
if (${NEED_LIBXML2_DEPEND})
add_dependencies(tx ${LIBXML2_TARGET})
target_compile_definitions(tx PUBLIC -DLIBXML_STATIC)
if (WIN32)
target_link_libraries(tx PUBLIC ${LIBXML2_WIN_LIBRARIES})
else ()
target_link_libraries(tx PUBLIC ${LIBXML2_NONWIN_LIBRARIES})
endif()
endif()

install(TARGETS tx DESTINATION bin)
1 change: 1 addition & 0 deletions cmake/ExternalLibXML2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ endif()
ExternalProject_Add(${LIBXML2_TARGET}
GIT_REPOSITORY ${LIBXML2_GIT_REPOSITORY}
GIT_TAG ${LIBXML2_TAG}
GIT_SHALLOW 1
BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${LIBXML2_OUTPUT_DIR}/${LIBXML2_LIBNAME}
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/${LIBXML2_TARGET}/src
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${LIBXML2_TARGET}/bin
Expand Down