How to use CMAKE_INSTALL_PREFIX

后端 未结 3 1636
情话喂你
情话喂你 2020-11-29 19:26

I want to generate Makefile with install target, making installation to /usr instead of default /usr/local. Assuming that build directory is done in the source subdirectory,

相关标签:
3条回答
  • 2020-11-29 20:09

    That should be (see the docs):

    cmake -DCMAKE_INSTALL_PREFIX=/usr ..
    
    0 讨论(0)
  • 2020-11-29 20:14

    There are two ways to use this variable:

    • passing it as a command line argument just like Job mentioned:

      cmake -DCMAKE_INSTALL_PREFIX=< install_path > ..

    • assigning value to it in CMakeLists.txt:

      SET(CMAKE_INSTALL_PREFIX < install_path >)

      But do remember to place it BEFORE PROJECT(< project_name>) command, otherwise it will not work!

    0 讨论(0)
  • 2020-11-29 20:22

    But do remember to place it BEFORE PROJECT(< project_name>) command, otherwise it will not work!

    My first week of using cmake - after some years of GNU autotools - so I am still learning (better then writing m4 macros), but I think modifying CMAKE_INSTALL_PREFIX after setting project is the better place.

    CMakeLists.txt

    cmake_minimum_required (VERSION 2.8)
    
    set (CMAKE_INSTALL_PREFIX /foo/bar/bubba)
    message("CIP = ${CMAKE_INSTALL_PREFIX} (should be /foo/bar/bubba")
    project (BarkBark)
    message("CIP = ${CMAKE_INSTALL_PREFIX} (should be /foo/bar/bubba")
    set (CMAKE_INSTALL_PREFIX /foo/bar/bubba)
    message("CIP = ${CMAKE_INSTALL_PREFIX} (should be /foo/bar/bubba")
    

    First run (no cache)

    CIP = /foo/bar/bubba (should be /foo/bar/bubba
    -- The C compiler identification is GNU 4.4.7
    -- etc, etc,...
    CIP = /usr/local (should be /foo/bar/bubba
    CIP = /foo/bar/bubba (should be /foo/bar/bubba
    -- Configuring done
    -- Generating done
    

    Second run

    CIP = /foo/bar/bubba (should be /foo/bar/bubba
    CIP = /foo/bar/bubba (should be /foo/bar/bubba
    CIP = /foo/bar/bubba (should be /foo/bar/bubba
    -- Configuring done
    -- Generating done
    

    Let me know if I am mistaken, I have a lot of learning to do. It's fun.

    0 讨论(0)
提交回复
热议问题