conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
7.96k stars 952 forks source link

[question] Unexpected behavior with `cli_args` passed to `CMake.configure()`. #16463

Closed PauloCarvalhoRJ closed 3 weeks ago

PauloCarvalhoRJ commented 3 weeks ago

Hello,

So, I have recipe code like this:

            cmake.configure(build_script_folder=os.path.join(self.build_folder, self._source_subfolder, 'contrib', 'minizip'),
                            cli_args="-B"+os.path.join(self.build_folder, self._source_subfolder, 'contrib', 'minizip'))

because I need to build a given library in a sub-folder of the main build directory. The -B CMake option allows me to do just that (https://stackoverflow.com/questions/18826789/cmake-how-to-set-the-build-directory-to-be-different-than-source-directory). However, Conan seems to issue an ill-formed command:

zlib/1.2.11: RUN: cmake -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/conan_packages/b/zlibdb695f28a7113/p" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" "C:/conan_packages/b/zlibdb695f28a7113/b/source_subfolder/contrib/minizip" - B " C : \ c o n a n _ p a c k a g e s \ b \ z l i b d b 6 9 5 f 2 8 a 7 1 1 3 \ b \ s o u r c e _ s u b f o l d e r \ c o n t r i b \ m i n i z i p "

Notice the undue whitespaces between each character which obviously results in a CMake error. I'm using Conan 2.3.2.

Thanks,

PC

Have you read the CONTRIBUTING guide?

AbrilRBS commented 3 weeks ago

Hi @PauloCarvalhoRJ thanks gor the report

This is because the method expects a list of strings to be passed, not the one string itself . Could you try adding the [] list, see if it works?

So something like cli_args=["-B"+os.path.join(self.build_folder)]

Thanks!

PauloCarvalhoRJ commented 3 weeks ago

Hello, @RubenRBS

Right on! I got new errors, but the CMake command is now well-formed.

I suspected of something like that, but I had no clue as to what. Now that you mentioned it, it's indeed there in the docs, the little "list" word that I mistakenly didn't interpret as refering to the data structure. Anyway, as a side note, that's a fine example as to why implicit conversions are best avoided: https://stackoverflow.com/questions/2346083/why-implicit-conversion-is-harmful-in-c .

Compiling errors are always better than bugs because they are immediately visible for you to correct.

I mean, if the Python interpreter had at least warned me, I could have identified my mistake in earliest.

Thank you very much for the heads up,

PC