How do I use the --prefix argument in cmake --install?

My command is cmake --install . --prefix somewhereelse. I’m trying to get cmake to install a project in a custom directory instead of my program files folder. No matter what, though, it always puts it in my program files folder. It seems to be entirely ignoring my prefix argument.

Output for the above command is:

-- Install configuration: "Release"
-- Up-to-date: C:/Program Files (x86)/zlib/lib/zlib.lib
-- Up-to-date: C:/Program Files (x86)/zlib/bin/zlib.dll
-- Up-to-date: C:/Program Files (x86)/zlib/lib/zlibstatic.lib
-- Up-to-date: C:/Program Files (x86)/zlib/include/zconf.h
-- Up-to-date: C:/Program Files (x86)/zlib/include/zlib.h
-- Up-to-date: C:/Program Files (x86)/zlib/share/man/man3/zlib.3
-- Up-to-date: C:/Program Files (x86)/zlib/share/pkgconfig/zlib.pc

What do the install() commands look like for these files in the original project?

It looks like I have to set a variable at cmake build time?

This:

set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
# …
    install(TARGETS zlib zlibstatic
        RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
        ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
        LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )

means that the prefix is baked in at configure time. Instead, the INSTALL_BIN_DIR should be relative and let the install script add ${CMAKE_INSTALL_PREFIX} as needed. Right now, the install path is seen as absolute and therefore not eligible for replacement at install time.

1 Like

Incidentally, it is also bad because those values are only the defaults. This process:

$ cmake -DCMAKE_INSTALL_PREFIX=oops ../src # initial configure
$ cmake -DCMAKE_INSTALL_PREFIX=what_i_meant ../src

leaves the install still looking at oops because the INSTALL_BIN_DIR was initialized with oops/bin and won’t be updated with the new prefix selection. There’s been a

There’s been a what? Are you ok? Did the zlib authors get to you before you could finish your statement? :cold_sweat:

1 Like

Ah, sorry. My wireless flaked out and it seemed like everything had been there, but I guess not.

Basically, I could fix my upstream PR that already tries to fix some of this, but given the lack of activity…that’s probably not a useful investment of time.