microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.86k stars 6.3k forks source link

configure/make build failure when cpp definitions are passed in VCPKG_C_FLAGS #20158

Open BobIsOnFire opened 3 years ago

BobIsOnFire commented 3 years ago

Describe the bug I want to build a project using configure/make with a cpp definition which contains another definition I use (e.g., -DABC -DABCD). Vcpkg build fails at configuring stage.

Environment

To Reproduce So my triplet file looks like this:

set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)

set(VCPKG_CMAKE_SYSTEM_NAME Linux)

set(VCPKG_C_FLAGS "-DABC -DABCD")
set(VCPKG_CXX_FLAGS "-DABC -DABCD")

Steps to reproduce the behavior:

  1. ./vcpkg install icu
  2. See error

Tried on 2021.05.12 and master.

Expected behavior Successful build

Failure logs stdout

Computing installation plan...
The following packages will be built and installed:
    icu[core]:x64-linux -> 69.1#14
Detecting compiler hash for triplet x64-linux...
Restored 0 packages from <home>/.cache/vcpkg/archives in 6.581 us. Use --debug to see more details.
Starting package 1/1: icu:x64-linux
Building package icu[core]:x64-linux...
-- Downloading https://github.com/unicode-org/icu/releases/download/release-69-1/icu4c-69_1-src.tgz -> icu4c-69_1-src.tgz...
-- Cleaning sources at <home>/vcpkg/buildtrees/icu/src/c-69_1-src-78c1b28057.clean. Use --editable to skip cleaning for the packages you specify.
-- Extracting source <home>/vcpkg/downloads/icu4c-69_1-src.tgz
-- Applying patch <home>/vcpkg/ports/icu/disable-escapestr-tool.patch
-- Applying patch <home>/vcpkg/ports/icu/remove-MD-from-configure.patch
-- Applying patch <home>/vcpkg/ports/icu/fix_parallel_build_on_windows.patch
-- Applying patch <home>/vcpkg/ports/icu/fix-extra.patch
-- Using source at <home>/vcpkg/buildtrees/icu/src/c-69_1-src-78c1b28057.clean
-- Found external ninja('1.10.2').
-- Getting CMake variables for x64-linux-dbg
-- Getting CMake variables for x64-linux-rel
-- Configuring x64-linux-dbg
CMake Error at scripts/cmake/vcpkg_execute_required_process.cmake:127 (message):
    Command failed: /usr/bin/bash ./../src/c-69_1-src-78c1b28057.clean/source/configure --disable-samples --disable-tests --disable-layoutex --disable-silent-rules --verbose --disable-shared --enable-static --enable-debug --disable-release --prefix=<home>/vcpkg/installed/x64-linux/debug --bindir=${prefix}/../tools/icu/debug/bin --sbindir=${prefix}/../tools/icu/debug/sbin --includedir=${prefix}/../include --datarootdir=${prefix}/share/icu
    Working Directory: <home>/vcpkg/buildtrees/icu/x64-linux-dbg
    Error code: 77
    See logs for more information:
      <home>/vcpkg/buildtrees/icu/config-x64-linux-dbg-out.log
      <home>/vcpkg/buildtrees/icu/config-x64-linux-dbg-err.log

Call Stack (most recent call first):
  scripts/cmake/vcpkg_configure_make.cmake:820 (vcpkg_execute_required_process)
  ports/icu/portfile.cmake:44 (vcpkg_configure_make)
  scripts/ports.cmake:140 (include)

Error: Building package icu:x64-linux failed with: BUILD_FAILED
Please ensure you're using the latest portfiles with `./vcpkg update`, then
submit an issue at https://github.com/Microsoft/vcpkg/issues including:
  Package: icu:x64-linux
  Vcpkg version: 2021-09-10-unknownhash

Additionally, attach any relevant sections from the log files above.

config-x64-linux-dbg-out.log

checking for ICU version numbers... release 69.1, library 69.1, unicode version 13.0
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking whether to build debug libraries... yes
checking whether to build release libraries... no
checking for clang... clang
checking whether the C compiler works... no

config-x64-linux-dbg-err.log

configure: WARNING: unrecognized options: --disable-silent-rules
configure: error: in `/mnt/ssd1/nikita.akatiev/vcpkg/buildtrees/icu/x64-linux-dbg':
configure: error: C compiler cannot create executables
See `config.log' for more details

config.log

[...]
configure:3061: checking whether the C compiler works
configure:3083: clang -fPICD -g -DABC -DABCD   conftest.c  >&5
clang-10: error: unknown argument '-fPICD'; did you mean '-fPIC'?
configure:3087: $? = 1
configure:3125: result: no
[...]
## ----------------- ##
## Output variables. ##
## ----------------- ##
[...]
CFLAGS='-fPICD -g'
CPPFLAGS='-DABC -DABCD'
[...]

cmake-vars-x64-linux-dbg.cmake.log

[...]
set(VCPKG_DETECTED_CMAKE_C_FLAGS_DEBUG "-fPIC -DABC -DABCD -g")
[...]

Additional context Vcpkg detected my CFLAGS correctly, but passed some weird -fPICD to configure call. I believe this is due to bad regex matcher when CPPFLAGS are extracted over here: https://github.com/microsoft/vcpkg/blob/master/scripts/cmake/vcpkg_configure_make.cmake

Neumann-A commented 3 years ago

bad regex matcher when CPPFLAGS are extracted over here:

yes, because ABC is matched before ABCD so ABCD will be replaced to D only. Either we need to sort the list by length first or try to do exact matches (this also requires length sorting first.)

JackBoosY commented 3 years ago

@Neumann-A Are you interested in fixing this issue?

github-actions[bot] commented 5 days ago

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 180 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.