I running Arch Linux and I have the latest libxml2 package installed through pacman. When I try to build my Zephyr project with CMake I run into this error:
/usr/include/libxml2/libxml/encoding.h:31:10: fatal error: unicode/ucnv.h: No such file or directory
31 | #include <unicode/ucnv.h>
ucnv.h
would actually be located at ../../unicode/ucnv.h
relative to /usr/include/libxml2/libxml
, so I'm not sure why libxml2's structure was installed this way.
Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.13.4)
# Determine the build type
if (NOT BUILD_TYPE)
set(BUILD_TYPE debug)
endif()
# Print out build type
message(STATUS "Build type: ${BUILD_TYPE} 🚀")
# Set environment variables
# set(ZEPHYR_TOOLCHAIN_VARIANT gnuarmemb)
# set(GNUARMEMB_TOOLCHAIN_PATH /home/jforgue/.local/gcc-arm-none-eabi-10.3-2021.10)
# Set auto generation notice
file(WRITE conf/version.conf "# File is autogenerated. Do not modify.\n\n")
# Get the version from Git
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(
COMMAND git describe --tags --long
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE version
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE stderr
RESULT_VARIABLE return_code
)
if(return_code)
message(STATUS "git describe failed: ${stderr}; ${KERNEL_VERSION_STRING} will be used instead")
elseif(CMAKE_VERBOSE_MAKEFILE)
message(STATUS "git describe stderr: ${stderr}")
endif()
endif()
if(version)
string(REGEX REPLACE "^([0-9]+).*$" "\\1" version_major ${version})
string(REGEX REPLACE "^[0-9]+\.([0-9]+).*$" "\\1" version_minor "${version}")
string(REGEX REPLACE "^[0-9]+\.[0-9]+\.([0-9]+).*$" "\\1" version_patch "${version}")
string(REGEX REPLACE "^[0-9]+\.[0-9]+\.[0-9]+-([0-9]+)-.*$" "\\1" version_commit "${version}")
string(REGEX REPLACE "^[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-(.*)$" "\\1" version_hash "${version}")
# Create version.conf
file(APPEND conf/version.conf "CONFIG_APP_VERSION_MAJOR=${version_major}\n")
file(APPEND conf/version.conf "CONFIG_APP_VERSION_MINOR=${version_minor}\n")
file(APPEND conf/version.conf "CONFIG_APP_VERSION_PATCH=${version_patch}\n")
file(APPEND conf/version.conf "CONFIG_APP_VERSION_COMMIT=${version_commit}\n")
file(APPEND conf/version.conf "CONFIG_APP_VERSION_HASH=\"${version_hash}\"\n")
file(APPEND conf/version.conf "CONFIG_APP_VERSION=\"${version}\"\n")
file(APPEND conf/version.conf "CONFIG_MCUBOOT_IMAGE_VERSION=\"${version_major}.${version_minor}.${version_patch}+${version_commit}\"\n")
message(STATUS "Version: ${version_major}.${version_minor}.${version_patch}-${version_commit}-${version_hash}")
endif()
if(BUILD_TYPE)
file(APPEND conf/version.conf "CONFIG_APP_RELEASE_TYPE=\"${BUILD_TYPE}\"\n")
endif()
# Define configuration files.
list(APPEND CONF_FILE
${CMAKE_CURRENT_SOURCE_DIR}/conf/prj.conf
${CMAKE_CURRENT_SOURCE_DIR}/conf/version.conf
${CMAKE_CURRENT_SOURCE_DIR}/conf/${BUILD_TYPE}.conf
${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD}.conf
)
# MCUboot related
list(APPEND mcuboot_OVERLAY_CONFIG
"${CMAKE_CURRENT_SOURCE_DIR}/conf/mcuboot/mcuboot.conf"
)
# Adding custom overlay to add settings that aren't included in the SDK (yet) for the nRF9160 Feather
if(${BOARD} STREQUAL circuitdojo_feather_nrf9160ns)
message(STATUS "Adding .overlay for mcuboot.")
list(APPEND mcuboot_DTC_OVERLAY_FILE
"${CMAKE_CURRENT_SOURCE_DIR}/conf/mcuboot/circuitdojo_feather_nrf9160ns.overlay"
)
endif()
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(application)
add_subdirectory(src/event_manager)
add_subdirectory(src/version)
# Include EXPAT
# find_package(EXPAT REQUIRED)
# target_link_libraries(app PUBLIC EXPAT::EXPAT)
find_package(LibXml2 REQUIRED)
target_link_libraries(app PUBLIC LibXml2::LibXml2)
target_sources(app PRIVATE src/main.c)
As a side note, CMake also cant find Expat using find_package(EXPAT REQUIRED)
. Expat is also installed through pacman.
As @DavidGrayson suggested, I was trying to cross compile. I wasn't setting the correct PATH so CMake was attempting to use the native libxml2 version.