Le 27/07/2017 à 13:08, Eric Noulard a écrit :


2017-07-27 12:28 GMT+02:00 David Demelier <demelier.da...@gmail.com <mailto:demelier.da...@gmail.com>>:

    Hello,

    I'm still trying to find a correct solution to handle user specified
    installation paths.

    Let's consider two kind of paths:

       - WITH_BINDIR (default: bin/) where to install executables,
       - WITH_DATADIR (default: share/project_name/) where to install
    extra data.

    I want to let the user configuring those paths because not all
    distributions use the same paths (e.g. bin vs usr/bin).

    Then, I also like to build the whole CMake project by creating the
    hierarchy as it would be installed like:

    <binarydir>/WITH_BINDIR/myapp
    <binarydir>/WITH_DATADIR/somestuff.txt


Do you mean here that you setup CMAKE_<XXXX>_OUTPUT_DIRECTORY (variable or target property) to your favorite value
or

Both, I set the output directory for executable to WITH_BINDIR value and also install it as destination.

My opinion is that you should never use absolute path (besides some very specific case on unix where you want to put something in /etc/...)
You should ask your user for

    DATADIR
    BINDIR
    etc...


This is what I have done in my CMakeLists.txt, the cmake invocation fails if BINDIR and/or DATADIR are absolute. But again, then with some package managers you get in troubles because they specify absolute path.

See the RPM default macro:

  /usr/bin/cmake \
        -DCMAKE_C_FLAGS_RELEASE:STRING="-DNDEBUG" \
        -DCMAKE_CXX_FLAGS_RELEASE:STRING="-DNDEBUG" \
        -DCMAKE_Fortran_FLAGS_RELEASE:STRING="-DNDEBUG" \
        -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
        -DCMAKE_INSTALL_PREFIX:PATH=/usr \
        -DINCLUDE_INSTALL_DIR:PATH=/usr/include \
        -DLIB_INSTALL_DIR:PATH=/usr/lib64 \
        -DSYSCONF_INSTALL_DIR:PATH=/etc \
        -DSHARE_INSTALL_PREFIX:PATH=/usr/share \

And if you add any new variable, you should prefix by %{prefix} which is also absolute...

I wouldn't try to mimic install tree during the build (if it is what you are doing),

The nice thing is that you can easily run/debug the application especially if that application needs to find some plugins/data while running by evaluating paths to them.

I'll probably go for something like a pre-install target like you said instead of mimic'ing the build tree. And disable that target if any of the paths are absolute.

Thanks for the answers!
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to