How do I use CMake?

后端 未结 6 550
生来不讨喜
生来不讨喜 2020-11-28 20:15

I am trying to use CMake in order to compile opencv.

I am reading the tutorial but can\'t understand what is CMakeLists files and how is it connected to the gui of C

相关标签:
6条回答
  • 2020-11-28 20:30

    Regarding CMake 3.13.3, platform Windows, and IDE Visual Studio 2017, I suggest this guide. In brief I suggest:
    1. Download cmake > unzip it > execute it.
    2. As example download GLFW > unzip it > create inside folder Build.
    3. In cmake Browse "Source" > Browse "Build" > Configure and Generate.
    4. In Visual Studio 2017 Build your Solution.
    5. Get the binaries.
    Regards.

    0 讨论(0)
  • 2020-11-28 20:34

    CMake (Cross platform make) is a build system generator. It doesn't build your source, instead, generates what a build system needs: the build scripts. Doing so you don't need to write or maintain platform specific build files. CMake uses relatively high level CMake language which usually written in CMakeLists.txt files. Your general workflow when consuming third party libraries usually boils down the following commands:

    cmake -S thelibrary -B build
    cmake --build build
    cmake --install build
    

    The first line known as configuration step, this generates the build files on your system. -S(ource) is the library source, and -B(uild) folder. CMake falls back to generate build according to your system. it will be MSBuild on Windows, GNU Makefiles on Linux. You can specify the build using -G(enerator) paramater, like:

    cmake -G Ninja -S libSource -B build
    

    end of the this step, generates build scripts, like Makefile, *.sln files etc. on build directory.

    The second line invokes the actual build command, it's like invoking make on the build folder.

    The third line install the library. If you're on Windows, you can quickly open generated project by, cmake --open build.

    Now you can use the installed library on your project with configured by CMake, writing your own CMakeLists.txt file. To do so, you'll need to create a your target and find the package you installed using find_package command, which will export the library target names, and link them against your own target.

    0 讨论(0)
  • 2020-11-28 20:35

    Cmake from Windows terminal:

    mkdir build
    cd build/
    cmake ..
    cmake --build . --config Release
    ./Release/main.exe
    
    0 讨论(0)
  • 2020-11-28 20:48

    I don't know about Windows (never used it), but on a Linux system you just have to create a build directory (in the top source directory)

    mkdir build-dir
    

    go inside it

    cd build-dir
    

    then run cmake and point to the parent directory

    cmake ..
    

    and finally run make

    make
    

    Notice that make and cmake are different programs. cmake is a Makefile generator, and the make utility is governed by a Makefile textual file. See cmake & make wikipedia pages.

    NB: On Windows, cmake might operate so could need to be used differently. You'll need to read the documentation (like I did for Linux)

    0 讨论(0)
  • 2020-11-28 20:51

    CMake takes a CMakeList file, and outputs it to a platform-specific build format, e.g. a Makefile, Visual Studio, etc.

    You run CMake on the CMakeList first. If you're on Visual Studio, you can then load the output project/solution.

    0 讨论(0)
  • 2020-11-28 20:53

    Yes, cmake and make are different programs. cmake is (on Linux) a Makefile generator (and Makefile-s are the files driving the make utility). There are other Makefile generators (in particular configure and autoconf etc...). And you can find other build automation programs (e.g. ninja).

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