[Fwd: [cython-users] Conditional compilation of Cython code / preprocessor / external conditions]
Hi, After a bit more research, I found two options that I initially overlooked: 1) (Apparently undocumented) provisions to provide external attributes in cython_compile_time_env 2) Generation of the PXI file from the external build system I don't like (2) very much, so I've got an idea to extend (1) with the ability to pass -D options to cython compiler, like: cython -DHAVE_LIBFOO=1 Will any such pull request be accepted? -- Sincerely yours, Yury V. Zaytsev -------- Forwarded Message -------- From: Yury V. Zaytsev <yury@shurup.com> Reply-to: cython-users@googlegroups.com To: cython-users@googlegroups.com Subject: [cython-users] Conditional compilation of Cython code / preprocessor / external conditions Date: Mon, 22 Jul 2013 16:17:58 +0200 Hi folks, Is it possible to conditionally compile Cython code depending on some externally defined value?
From reading the documentation, I've got an impression that presently Cython doesn't have any kind of preprocessor, and I hope that I'm just missing something here:
http://docs.cython.org/src/userguide/language_basics.html My use case is as follows: The application that I'm wrapping links against a number of libraries, and some might be unavailable at compile time, so the corresponding parts of the Cython code shouldn't be compiled either. During the build, a preprocessor constant is defined, such as HAVE_LIBFOO that I can get by including config.h or pass via the autotools build system to the external tools. However, I can't figure out how to use that from Cython... So far, I was able to come up with an idea of replicating the API of the missing libraries with dummies on the C++ level, such that the Cython code compiles either way. Or else, I can make a poor man's preprocessor based on sed and just strip parts marked for conditional compilation from the PYX files. Both solutions look really disgusting and unmaintainable. I would greatly appreciate better ideas! To me it sounds like a rather common problem, so somebody must have come up with a solution already... Thanks, -- Sincerely yours, Yury V. Zaytsev -- --- You received this message because you are subscribed to the Google Groups "cython-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
participants (1)
-
Yury V. Zaytsev