CMake output/build directory

前端 未结 5 512
北恋
北恋 2020-11-28 03:05

I\'m pretty new to CMake, and read a few tutorials on how to use it, and wrote some complicated 50 lines of CMake script in order to make a program for 3 different compilers

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 03:41

    There's little need to set all the variables you're setting. CMake sets them to reasonable defaults. You should definitely not modify CMAKE_BINARY_DIR or CMAKE_CACHEFILE_DIR. Treat these as read-only.

    First remove the existing problematic cache file from the src directory:

    cd src
    rm CMakeCache.txt
    cd ..
    

    Then remove all the set() commands and do:

    cd Compile
    rm -rf *
    cmake ../src
    

    As long as you're outside of the source directory when running CMake, it will not modify the source directory unless your CMakeList explicitly tells it to.

    Once you have this working, you can look at where CMake puts things by default, and only if you're not satisfied with the default locations (such as the default value of EXECUTABLE_OUTPUT_PATH), modify only those you need. And try to express them relative to CMAKE_BINARY_DIR, CMAKE_CURRENT_BINARY_DIR, PROJECT_BINARY_DIR etc.

    If you look at CMake documentation, you'll see variables partitioned into semantic sections. Except for very special circumstances, you should treat all those listed under "Variables that Provide Information" as read-only inside CMakeLists.

提交回复
热议问题