Reputation: 2240
I'm currently having this issue with the Google Protobuf Library, but it is a recurring problem and will likely occur with many if not all 3rd-party packages that I want to build and install from source.
I'm developing for Windows, and we need to be able to generate both 32-bit and 64-bit versions of our DLLs. It was relatively straightforward to get CMake to install our own modules to architecture-specific subdirectories, e.g. D:\libraries\bin\i686
and d:\libraries\lib\i686
(and sim. for bin
). But I'm having trouble achieving the same thing with 3rd-party libraries such as Protobuf.
I could, of course, use distinct CMAKE_INSTALL_PREFIX
and CMAKE_PREFIX_PATH
combinations (e.g. D:\libraries-i686
and D:\libraries-x86_64
, and will probably end up doing just that, but it bothers me that there doesn't seem to be a better alternative. The docs for find_package()
clearly show that the search procedure does attempt architecture-specific search paths, so why do the CMake files of popular libraries not generally seem to support installing to architecture-specific subdirectories?
Or could it be that it is just a matter of setting the right CMAKE_XXX
variable?
Upvotes: 1
Views: 792
Reputation: 2240
Thanks to @arrowd for pointing me in the right direction, I now have my answer, though it is not exactly what I had hoped for.
CMAKE_LIBRARY_OUTPUT_DIRECTORY
and CMAKE_RUNTIME_OUTPUT_DIRECTORY
, however, specify the build output directories, not the install directories. As it turns out though, there are variables for the install directories too, called CMAKE_INSTALL_BINDIR
and CMAKE_INSTALL_LIBDIR
- they are actually plainly visible (along with plenty more) in the cmake-gui interface when "Advanced" is checked.
I tried setting those two manually (to bin\i686
and lib\i686
), and it works: the Protobuf INSTALL
target copies the files where I wanted to have them, i.e. where the CMake script of my consumer project will find them in an architecture-safe manner.
I'm not sure how I feel about this - I would have preferred something like a CMAKE_INSTALL_ARCHITECTURE
or CMAKE_ARCHITECTURE_SUBDIR
variable that CMake would automatically append to relevant install paths. The solution above requires overriding defaults that I would prefer to leave untouched.
Under the circumstances, my fallback approach might still be the better option. That approach however requires that the choice of architecture be made very early on, typically when running the script that initializes the CMake-specific environment variables that will be passed to cmake
when configuring build directories. And it's worse when using cmake-gui
, which requires the user to set all directories manually.
In the end, I'm still undecided.
Upvotes: 2