I am working on a project that requires conditional compilation based on the presence of certain files, specifically for integrating IPOPT (an optimization library). My development environment is Windows Subsystem for Linux (WSL), and I face cross-compilation challenges.
In my configure.ac, I have a custom macro IPOPT_ARG_CHECK that checks for the existence of IpStdCInterface.h as part of determining whether to compile with IPOPT support. Here's the relevant part of the macro:
AC_DEFUN([IPOPT_ARG_CHECK],
[
...
AC_ARG_WITH([$1],
[AS_HELP_STRING([--$2],
[IPOPT installation directory @<:@default=check@:>@])],
[$1=$withval],
[$3=no])
AS_IF([test "x$$3" = xno],
[...],
[AC_CHECK_FILE($$1/include/$coin/IpStdCInterface.h,
[],
[AC_MSG_FAILURE([--$2 option was specified but does not seem to point at a valid IPOPT installation])])])
AM_CONDITIONAL([$8],[test "x$$3" != xno])
...
])
However, I get a warning when I run autoreconf:
configure.ac:242: warning: cannot check for file existence when cross compiling
I'm looking for guidance on the canonical way to perform this check in a cross-compilation-friendly manner.
I understand that
AC_CHECK_FILEis not recommended for cross-compilation scenarios. Based on suggestions (here and here), I replaced it with a simpletest -fcheck:And that resolved the issue.
However, I believe the canonical way to perform this check in a cross-compilation-friendly manner is to rewrite the
IPOPT_ARG_CHECKfunction using thePKG_CHECK_MODULESmacro from the pkg-config system. It seems to be a more robust and common approach to handling dependencies inconfigure.ac, especially for cross-compilation scenarios. This macro checks for the existence of a package and its version and sets upCFLAGSandLIBSvariables accordingly, which can then be used in the Makefiles.P.S. I had already mentioned this method in the question as a failed attempt, but then later, I realized that I had a syntax error, and by fixing that, this worked. I also wrote about this solution here.