This is a simple CMake tutorial project which contains some different scenarios

Overview

learning-cmake

This is a simple CMake tutorial project which contains some different scenarios.

  • hello-world: Demo a simplest CMake project.
  • hello-world-clear: Separate the output files and src files.
  • hello-world-lib: Demo how to make a static/shared library.
  • hello-world-shared: Demo how to utilize external static/shared library.
  • curl: Demo how to use cmake with curl.
  • hello-module: Demo how to use cmake find module.
  • config-file: Demo how to work with config.h.
  • hunter-simple: Demo how to use hunter and gtest.
  • boost: Demo how to use boost library.

Build steps

  • cmake -H. -B_builds
  • cmake --build _builds

CMake based tools

  • hunter: CMake-driven cross-platform package manager for C++.
  • CLion: CMake based IDE.

Nice CMake Resources

Comments
  • 你没有写cmake  find rules

    你没有写cmake find rules

    CMake Warning at src/CMakeLists.txt:8 (find_package):
      By not providing "Findcurl.cmake" in CMAKE_MODULE_PATH this project has
      asked CMake to find a package configuration file provided by "curl", but
      CMake did not find one.
    
      Could not find a package configuration file provided by "curl" with any of
      the following names:
    
        curlConfig.cmake
        curl-config.cmake
    
      Add the installation prefix of "curl" to CMAKE_PREFIX_PATH or set
      "curl_DIR" to a directory containing one of the above files.  If "curl"
      provides a separate development package or SDK, be sure it has been
      installed.
    
    
    opened by itfanr 5
  • problem at find_library in hello-module

    problem at find_library in hello-module

    Hi, After hours of trying to build to hello-module project, found that according to the documentation for find_library you need to have PATHS rather than PATH to define additional paths for searching for the libraries.

    opened by meslahik 4
  • Question

    Question

    感觉对unset的行为有点困惑。

    An option that the user can select. Can accept condition to control when option is available for user.

    Usage:

    mxnet_option(<option_variable> "doc string" [IF ])

    function(mxnet_option variable description value) set(__value ${value}) set(__condition "") set(__varname "__value") foreach(arg ${ARGN}) if(arg STREQUAL "IF" OR arg STREQUAL "if") set(__varname "__condition") else() list(APPEND ${__varname} ${arg}) endif() endforeach() unset(__varname) ==========>这里为什么要unset() unset之后这个变量不是不起作用? if("${__condition}" STREQUAL "") set(__condition 2 GREATER 1) endif()

    if(${__condition}) if("${__value}" MATCHES ";") if(${__value}) option(${variable} "${description}" ON) else() option(${variable} "${description}" OFF) endif() elseif(DEFINED ${__value}) if(${__value}) option(${variable} "${description}" ON) else() option(${variable} "${description}" OFF) endif() else() option(${variable} "${description}" ${__value}) endif() else() unset(${variable} CACHE) endif() endfunction()

    opened by pzz2011 0
  • 关于对cmake编译同名静态库和动态库的解释的建议

    关于对cmake编译同名静态库和动态库的解释的建议

    你好!我在阅读cmake-practice的文档时,有关于编译出hello.so和hello.a的两个库的内容中,涉及到使用 SET_TARGET_PROPERTIES(hello PROPERTIES CLEAN_DIRECT_OUTPUT 1) SET_TARGET_PROPERTIES(hello_static PROPERTIES CLEAN_DIRECT_OUTPUT 1) 来防止库因同名而被删除的问题,但是个人(目前使用的cmake是3.10.2)经过一些尝试,在不使用以上语句的情况下也能成功编译出两个同名的库,有没有可能是版本更新后对此进行了优化导致的?或者请问我这样的尝试有什么不当之处吗?还请赐教

    
    ADD_LIBRARY(hello SHARED ${LIBHELLO_SRC})
    
    #[[
    SET_TARGET_PROPERTIES(
        hello 
        PROPERTIES 
                    CLEAN_DIRECT_OUTPUT 1            
    )
    ]]
    
    ADD_LIBRARY(hello_static STATIC ${LIBHELLO_SRC})
    
    SET_TARGET_PROPERTIES(
        hello_static
        PROPERTIES 
                    OUTPUT_NAME "hello"
    )
    

    图片

    opened by robin-bird-go 0
  • CMakeList.txt error in first practice in

    CMakeList.txt error in first practice in "CMake Practice.pdf"

    /backup/t1/CMakeLists.txt

    PROJECT (HELLO)
    SET(SRC_LIST main.c)
    MESSAGE(STATUS "This is BINARY dir " ${HELLO_BINARY_DIR})
    MESSAGE(STATUS "This is SOURCE dir "${HELLO_SOURCE_DIR})
    ADD_EXECUTABLE(hello SRC_LIST)
    

    line 1: space after PROJECT is unnessary. line 4: need no space before ${HELLO_SOURCE_DIR}, or there will be warning. line 5: ${SRC_LIST} not SRC_LIST, or there will be an error.

    opened by willson-chen 0
  • [DOC Error] ADD_EXECUTABLE expects the source files not the variable name

    [DOC Error] ADD_EXECUTABLE expects the source files not the variable name

    Hi there, When I try the first example in cmake-pratice, page 6, cmake complains cannot find source files.

    -- This is BINARY dir
    -- This is SOURCE dir
    -- Configuring done
    CMake Error at CMakeLists.txt:8 (add_executable):
      Cannot find source file:
    
        SRC_LIST
    
      Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
      .hxx .in .txx
    
    
    CMake Error: CMake can not determine linker language for target: hello
    CMake Error: Cannot determine link language for target "hello".
    

    After I modified add_executable(hello SRC_LIST) to add_executable(hello ${SRC_LIST}), this issue had been solved. So here must be using variable name. Can you check and update it?

    cmake version 3.5.1

    opened by leeexyz 0
Owner
Bob Liu
The quieter, the more!
Bob Liu
Example project which demonstrates various CMake features.

CMake example Example project which demonstrates various CMake features. CDash testing dashboard (probably empty but you can submit your test result t

Radovan Bast 141 Feb 28, 2022
CMake modules for some scientific libraries

A collection of CMake modules, which can mostly be used independently. The utilities for writing robust Find* modules might be useful until CMake take

Jed Brown 80 Jul 12, 2022
📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.

Setup-free CMake dependency management CPM.cmake is a CMake script that adds dependency management capabilities to CMake. It's built as a thin wrapper

CPM.cmake 1.3k Sep 21, 2022
CMake checks cache helper modules – for fast CI CMake builds!

cmake-checks-cache Cross platform CMake projects do platform introspection by the means of "Check" macros. Have a look at CMake's How To Write Platfor

Cristian Adam 60 Aug 17, 2022
CMake scripts for painless usage of SuiteSparse+METIS from Visual Studio and the rest of Windows/Linux/OSX IDEs supported by CMake

CMake scripts for painless usage of Tim Davis' SuiteSparse (CHOLMOD,UMFPACK,AMD,LDL,SPQR,...) and METIS from Visual Studio and the rest of Windows/Lin

Jose Luis Blanco-Claraco 388 Sep 16, 2022
cmake-font-lock - Advanced, type aware, highlight support for CMake

cmake-font-lock - Advanced, type aware, highlight support for CMake

Anders Lindgren 37 Dec 30, 2021
cmake-avr - a cmake toolchain for AVR projects

cmake-avr - a cmake toolchain for AVR projects Testing the example provided The toolchain was created and tested within the following environment: Lin

Matthias Kleemann 160 Sep 5, 2022
Make CMake less painful when trying to write Modern Flexible CMake

Izzy's eXtension Modules IXM is a CMake library for writing Modern flexible CMake. This means: Reducing the amount of CMake written Selecting reasonab

IXM 107 Sep 1, 2022
CMake module to enable code coverage easily and generate coverage reports with CMake targets.

CMake-codecov CMake module to enable code coverage easily and generate coverage reports with CMake targets. Include into your project To use Findcodec

HPC 79 Sep 12, 2022
unmaintained - CMake module to activate certain C++ standard, feature checks and appropriate automated workarounds - basically an improved version of cmake-compile-features

Compatibility This library provides an advanced target_compile_features() and write_compiler_detection_header(). The problem with those is that they a

Jonathan Müller 72 Apr 14, 2022
[CMake] [BSD-2] CMake module to find ICU

FindICU.cmake A CMake module to find International Components for Unicode (ICU) Library Note that CMake, since its version 3.7.0, includes a FindICU m

julp 28 Sep 1, 2022
CMake project for BL602 RISC-V processor

bl602_cmake_base CMake project for BL602 RISC-V processor How to build NOTE : This project uses a pre-compiled version of the Buffalo SDK (bl_iot_sdk)

null 9 Jan 6, 2022
Project to enable using CMake from a Maven build.

CMake-Maven-Project Introduction A Maven project for the CMake build system. It can be used by including it as a plugin within your Maven project's po

null 58 Jul 13, 2022
Enhanced CMake Project Manager plugin for Qt Creator

CMakeProjectManager2 Alternative CMake support for Qt Creator. Main differents from original CMakeProject plugin: Project file list readed from file s

Alexander Drozdov 71 May 24, 2022
A program that automatically generates CMake and Meson configuration files for your Vala project

Autovala is a program and a library designed to help in the creation of projects with Vala and CMake. It also has support for Genie.

Sergio Costas 107 Apr 7, 2021
Installation example for a C++ project (Windows) with Cmake.

CMakeInstallExample Installation example for a C++ project (Windows) with Cmake. Contents This project demonstrates how to use cmake with cpack to gen

Paul T 28 Jul 13, 2022
Template for reliable, cross-platform C++ project setup using cmake.

The C++ CMake Project Template cmake-init is a sophisticated copy & paste template for modern C and C++ projects. The main goals include support of al

CG Internals 798 Sep 17, 2022
CMake module for downloading an external project's source at configure time

DownloadProject Platform Build status Linux Mac OSX Windows (VS2015) This repository contains a generalized implementation for downloading an external

Crascit Pty Ltd 430 Sep 19, 2022
Simple library for embedding static resources into C++ binaries using CMake

libromfs libromfs is an easy way to bundle resources directly into any C++ application and access them through a simple interface. The main advantage

WerWolv 27 Aug 11, 2022