Skip to content
Merged
14 changes: 14 additions & 0 deletions cmake/Modules/Platform/Emscripten.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ if (NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
endif()

set(_em_pkgconfig_libdir "${EMSCRIPTEN_SYSROOT}/local/lib/pkgconfig" "${EMSCRIPTEN_SYSROOT}/lib/pkgconfig")
if("${CMAKE_VERSION}" VERSION_LESS "3.20")
file(TO_NATIVE_PATH "${_em_pkgconfig_libdir}" _em_pkgconfig_libdir)
if(CMAKE_HOST_UNIX)
string(REPLACE ";" ":" _em_pkgconfig_libdir "${_em_pkgconfig_libdir}")
string(REPLACE "\\ " " " _em_pkgconfig_libdir "${_em_pkgconfig_libdir}")
endif()
else()
cmake_path(CONVERT "${_em_pkgconfig_libdir}" TO_NATIVE_PATH_LIST _em_pkgconfig_libdir)
endif()
set(ENV{PKG_CONFIG_LIBDIR} "${_em_pkgconfig_libdir}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should also set PKG_CONFIG_SYSROOT_DIR here? (doesn't have to be part of this change).

Copy link
Contributor Author

@nthirtyone nthirtyone May 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to leave it out for now. We'd want to get consistent behaviour for CMake and building.py and PKG_CONFIG_SYSROOT_DIR can easily become a journey on its own (LIBDIR is good enough for most use cases, and SYSROOT affects only the PATH, not LIBDIR).

set(ENV{PKG_CONFIG_PATH} "$ENV{EM_PKG_CONFIG_PATH}") # Stops caller's PKG_CONFIG_PATH from propagating.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should forget about EM_PKG_CONFIG_PATH. I'm not sure why use it ever had.

If somebody explicitly sets PKG_CONFIG_PATH when building an emscripten project I don't see why should ignore it. That seems like a deliberate act.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behaviour was based on tools.building.get_building_env().

I agree that it seems a bit out of place, but that would introduce inconsistency in how caller's variables are used across tools. If it's acceptable for you then I'm happy to do it.

Or should I update get_building_env? For example: create a backwards-compatible behaviour that prioritises EM_PKG_CONFIG_PATH but also allows for PKG_CONFIG_PATH, and then implement it consistently inget_building_env and here in toolchain.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should ignore EM_PKG_CONFIG_PATH in this patch and we should try to remove it from get_building_env as separate change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, removed the line in question.

unset(_em_pkgconfig_libdir)

option(EMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES "If set, static library targets generate LLVM bitcode files (.bc). If disabled (default), UNIX ar archives (.a) are generated." OFF)
if (EMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES)
message(FATAL_ERROR "EMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES is not compatible with the llvm backend")
Expand Down