顯示具有 CMake 標籤的文章。 顯示所有文章
顯示具有 CMake 標籤的文章。 顯示所有文章

2020年10月7日 星期三

[CMake] FAQ

  • Build Type
    • cmake -DCMAKE_BUILD_TYPE=Debug/Release ..
       
  • Dump all variables
      function(dump_cmake_variables)
        get_cmake_property(_variableNames VARIABLES)
        list (SORT _variableNames)
        foreach (_variableName ${_variableNames})
            if (ARGV0)
                unset(MATCHED)
                string(REGEX MATCH ${ARGV0} MATCHED ${_variableName})
                if (NOT MATCHED)
                    continue()
                endif()
            endif()
            message(STATUS "${_variableName}=${${_variableName}}")
        endforeach()
    endfunction()
      
  • Q: 加了 link_directories, link 時仍找不到 library
  • Q: How to enable C++11?
    • set(CMAKE_CXX_STANDARD 11)
      set(CMAKE_CXX_STANDARD_REQUIRED ON)
      
    • 或是
      ADD_DEFINITIONS(
          -std=c++11 # or -std=c++0x
      )
      

2018年7月7日 星期六

[Software Engineering] use CMake to add version


  • Problem: 如何在軟體中加入版號?
  • How:
    • 工具: CMake (跨平台的 configuration tool, 可建立各平台的 build solution/project file)
    • 流程:
      • 在 project setting 檔案 (CMakeLists.txt) 內加入版號
      • set (APP_VERSION_MAJOR 1)
        set (APP_VERSION_MINOR 0)
        
      • 在 source code 中新增特定的預設 config.h.in 檔 (config.h 會是 build config.h.in 後的產物)
      • // the configured options and settings for App 
        #define APP_VERSION_MAJOR @APP_VERSION_MAJOR@
        #define APP_VERSION_MINOR @APP_VERSION_MAJOR@
        
      • CMakeLists.txt 中指定此 config.h 檔及預設的 config.h.in參考檔
      • configure_file (
            "${PROJECT_SOURCE_DIR}/config.h.in"
            "${PROJECT_BINARY_DIR}/config.h"
        ))
      • 如此就可以在 source code 中, include config.h 並使用 APP_VERSION_MAJOR, APP_VERSION_MINOR
      • 另外, 若 build成 shared binary 的話, 也可以像 linux一樣設計成 app_3.1.2 這樣的 binary, 然後 app為 symbolic link to app_3.1.2
        • CMakeLists.txt 中加入 target property VERSION 與 SONAME
        • set(APP_VERSION_STRING ${APP_VERSION_MAJOR}.${APP_VERSION_MINOR}.${APP_VERSION_PATCH})
          
          set_target_properties(App PROPERTIES 
              VERSION ${APP_VERSION_STRING} 
              SOVERSION ${APP_VERSION_MAJOR}
          )
          
  • Reference: CMake tutorial

2013年8月10日 星期六

[CMake] Install command line fail


  • 問題
    • 在安裝 CMake command line tools可能會發生 "Failed create symlink installation may be incomplete" 的錯誤
  • 原因
    • 主要原因是之前安裝過其他版本的 CMake而造成的衝突
  • 解法
    • 自行 link吧!
    • 在 /usr/bin中找到以下相關 binary
      • ccmake
      • cmake
      • cmake-gui
      • cmakexbuild
      • cpack
      • ctest
    • 刪除其 link, 並建立新的link
      • e.g.  sudo ln -s /Applications/CMake\ 2.8-11.app/Contents/bin/cmake /usr/bin/cmake