jasper-software / jasper

Official Repository for the JasPer Image Coding Toolkit
http://www.ece.uvic.ca/~mdadams/jasper
Other
223 stars 101 forks source link

JasGetStdcVersion.cmake can work in cross-compiles #366

Closed rossburton closed 8 months ago

rossburton commented 10 months ago

JasGetStdcVersion.cmake is guarded with cross-compile detection because you can't run code in cross-builds.

Whilst this is mostly true (apart from that cmake supports running target code in a qemu-user), you don't need to run code to get the value of a preprocessor define:

$ cat foo.c
__STDC_VERSION__
$ aarch64-poky-linux-gcc -E -P foo.c
201710L

I'm no CMake expert but cmake must have a macro to do this for you.

mdadams commented 10 months ago

The comment in your bug report basically amounts to saying, "I don't like your implementation and there might be a better way to do what you are doing but I don't know what it is." This kind of comment is not particularly helpful. If there is a better solution, I would be happy to hear it. I am using try_run in CMake (which is commonly used for introspection). As you noted, this runs the compiler. Any solution will have to run the compiler, however, since you have to ensure that the compiler flags used for this introspection match the flags used to build JasPer (and not all compilers can necessarily be invoked in the way you have done above). Your implied solution above also compiles code. So, I see no significant difference in your proposed approach, except that it will not work on platforms where you cannot invoke the C processor in the matter you have done. Also, you need to consider STDC as well, not just __STDC_VERSION__.

mdadams commented 8 months ago

Since the approach used by JasPer works correctly and no better alternative has been proposed for quite some time now, I am closing this issue.

rossburton commented 8 months ago

Absolutely the compiler has to be ran, that's the solution I'd like: no guessing, just run the compiler and see what the value is. There's no need to run target code, just run the compiler on a one-line file and see what the output is.