From 5c1f039913ce2362d754bdee4f805e2cdb46f285 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 29 May 2022 22:41:01 +0200 Subject: [PATCH 1/9] Drafted pkgconfig variables support in CMake toolchain file --- cmake/Modules/Platform/Emscripten.cmake | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmake/Modules/Platform/Emscripten.cmake b/cmake/Modules/Platform/Emscripten.cmake index 88f0c28b4c43b..2af4be6332d0f 100644 --- a/cmake/Modules/Platform/Emscripten.cmake +++ b/cmake/Modules/Platform/Emscripten.cmake @@ -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}") +set(ENV{PKG_CONFIG_PATH} "$ENV{EM_PKG_CONFIG_PATH}") # Stops caller's PKG_CONFIG_PATH from propagating. +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") From cc7b0f71e597c159e6aaa2ad8cd5f2e75adefb84 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 30 May 2022 19:59:38 +0200 Subject: [PATCH 2/9] Added test for pc files finding via CMake --- tests/cmake/find_pkg_config/CMakeLists.txt | 10 ++++++++++ tests/test_other.py | 6 ++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/cmake/find_pkg_config/CMakeLists.txt diff --git a/tests/cmake/find_pkg_config/CMakeLists.txt b/tests/cmake/find_pkg_config/CMakeLists.txt new file mode 100644 index 0000000000000..fb0c9f4dc4d55 --- /dev/null +++ b/tests/cmake/find_pkg_config/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.0) +project(find_pkg_config) + +message(STATUS "PKG_CONFIG_LIBDIR: $ENV{PKG_CONFIG_LIBDIR}") + +find_package(PkgConfig REQUIRED) + +pkg_check_modules(EGL REQUIRED egl) +pkg_check_modules(GLESV2 REQUIRED glesv2) +pkg_check_modules(SDL2 REQUIRED sdl) diff --git a/tests/test_other.py b/tests/test_other.py index c76f7748ac25f..963137160aaca 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -805,6 +805,12 @@ def test_cmake_find_modules(self): self.assertContained('AL_VERSION: 1.1', output) self.assertContained('SDL version: 2.0.', output) + def test_cmake_find_pkg_config(self): + out = self.run_process([EMCMAKE, 'cmake', test_file('cmake/find_pkg_config')]).stdout + libdir = shared.Cache.get_sysroot_dir('local', 'lib', 'pkgconfig') + libdir += os.path.pathsep + shared.Cache.get_sysroot_dir('lib', 'pkgconfig') + self.assertContained('PKG_CONFIG_LIBDIR: ' + libdir, out) + def test_system_include_paths(self): # Verify that all default include paths are within `emscripten/system` From 8bc8ec23867dbf5ad3398520326ba33a21d31806 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 30 May 2022 20:01:18 +0200 Subject: [PATCH 3/9] Removed {EM_,}PKG_CONFIG_PATH from toolchain --- cmake/Modules/Platform/Emscripten.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/Modules/Platform/Emscripten.cmake b/cmake/Modules/Platform/Emscripten.cmake index 2af4be6332d0f..f6e220bcc68ed 100644 --- a/cmake/Modules/Platform/Emscripten.cmake +++ b/cmake/Modules/Platform/Emscripten.cmake @@ -272,7 +272,6 @@ else() cmake_path(CONVERT "${_em_pkgconfig_libdir}" TO_NATIVE_PATH_LIST _em_pkgconfig_libdir) endif() set(ENV{PKG_CONFIG_LIBDIR} "${_em_pkgconfig_libdir}") -set(ENV{PKG_CONFIG_PATH} "$ENV{EM_PKG_CONFIG_PATH}") # Stops caller's PKG_CONFIG_PATH from propagating. 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) From 6e8ae1c9b8d29b5433d02cd3b9be97b20f5fe2f9 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 30 May 2022 20:48:42 +0200 Subject: [PATCH 4/9] Fixed missing redirection from cmake run --- tests/test_other.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_other.py b/tests/test_other.py index 963137160aaca..c0ad18bcf4f76 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -806,7 +806,7 @@ def test_cmake_find_modules(self): self.assertContained('SDL version: 2.0.', output) def test_cmake_find_pkg_config(self): - out = self.run_process([EMCMAKE, 'cmake', test_file('cmake/find_pkg_config')]).stdout + out = self.run_process([EMCMAKE, 'cmake', test_file('cmake/find_pkg_config')], stdout=PIPE).stdout libdir = shared.Cache.get_sysroot_dir('local', 'lib', 'pkgconfig') libdir += os.path.pathsep + shared.Cache.get_sysroot_dir('lib', 'pkgconfig') self.assertContained('PKG_CONFIG_LIBDIR: ' + libdir, out) From f3a4d519095b1b0643fe954285065029de77f555 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 30 May 2022 20:51:24 +0200 Subject: [PATCH 5/9] Added pkgconfiglite to choco packages for windows tests --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 87d720ae8f750..7ed1139877e71 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -429,7 +429,7 @@ jobs: - run: name: Install packages command: | - choco install cmake.portable ninja + choco install cmake.portable ninja pkgconfiglite - run: name: Add python to bash path command: echo "export PATH=\"$PATH:/c/Python27amd64/\"" >> $BASH_ENV From d439aa8c4aec9392e6a961255707fc58ef84539c Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 30 May 2022 22:07:32 +0200 Subject: [PATCH 6/9] Added pkg-config to Mac CI test environment --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7ed1139877e71..64c70344e00d0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -455,6 +455,7 @@ jobs: command: | brew list cmake || brew install cmake brew list python3 || brew install python3 + brew list pkg-config || brew install pkg-config - checkout - build # note we do *not* build all libraries and freeze the cache; as we run From 86b81fafdd43e4f3424ea0027ef35f8930a6e302 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 31 May 2022 18:37:20 +0200 Subject: [PATCH 7/9] pkg-config test will now be skipped if no pkg-config --- tests/test_other.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_other.py b/tests/test_other.py index c0ad18bcf4f76..9e32e829274f0 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -806,6 +806,8 @@ def test_cmake_find_modules(self): self.assertContained('SDL version: 2.0.', output) def test_cmake_find_pkg_config(self): + if not utils.which('pkg-config'): + self.skipTest('Skipping cmake with pkg-config test since pkg-config is not found') out = self.run_process([EMCMAKE, 'cmake', test_file('cmake/find_pkg_config')], stdout=PIPE).stdout libdir = shared.Cache.get_sysroot_dir('local', 'lib', 'pkgconfig') libdir += os.path.pathsep + shared.Cache.get_sysroot_dir('lib', 'pkgconfig') From 15f781224a2a06b2a8e46bd5405e23664117b155 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 31 May 2022 18:44:46 +0200 Subject: [PATCH 8/9] Increased verbosity of CMake output for the pkg-config test --- tests/cmake/find_pkg_config/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/cmake/find_pkg_config/CMakeLists.txt b/tests/cmake/find_pkg_config/CMakeLists.txt index fb0c9f4dc4d55..d266f741f310e 100644 --- a/tests/cmake/find_pkg_config/CMakeLists.txt +++ b/tests/cmake/find_pkg_config/CMakeLists.txt @@ -3,8 +3,12 @@ project(find_pkg_config) message(STATUS "PKG_CONFIG_LIBDIR: $ENV{PKG_CONFIG_LIBDIR}") -find_package(PkgConfig REQUIRED) +find_package(PkgConfig REQUIRED QUIET) +if (NOT PKG_CONFIG_FOUND) + message(FATAL_ERROR "Could not find pkg-config executable!") +endif() +message(STATUS "Check that all .pc files shipped with Emscripten can be located correctly") pkg_check_modules(EGL REQUIRED egl) pkg_check_modules(GLESV2 REQUIRED glesv2) pkg_check_modules(SDL2 REQUIRED sdl) From bfc2f5ad373a884e52633cb397a099708b42c10a Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 31 May 2022 18:56:53 +0200 Subject: [PATCH 9/9] Test will now fail instead of skipping in case of missing pkg-config --- tests/test_other.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_other.py b/tests/test_other.py index 9e32e829274f0..cd3f8a2709e67 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -807,7 +807,7 @@ def test_cmake_find_modules(self): def test_cmake_find_pkg_config(self): if not utils.which('pkg-config'): - self.skipTest('Skipping cmake with pkg-config test since pkg-config is not found') + self.fail('pkg-config is required to run this test') out = self.run_process([EMCMAKE, 'cmake', test_file('cmake/find_pkg_config')], stdout=PIPE).stdout libdir = shared.Cache.get_sysroot_dir('local', 'lib', 'pkgconfig') libdir += os.path.pathsep + shared.Cache.get_sysroot_dir('lib', 'pkgconfig')