[Tools] CMakeメモ

存在は知ってて、某ツール使う時に適当に

$> cmake

とかやってたのですが、[Tools] GoogleTestをインストール にて、
便利ということを実感しました。


CMake


私が勘違いしていたことは「GNU make」のようにビルドしてくれるわけではなく、
様々な環境用にファイルを用意してくれるということだった。

[Tools] GoogleTestをインストール で使ったやつを例にすると、

  • CMakeLists.txt
  • set(GTEST_ROOT /home/kocha/tools/gtest/gtest-1.7.0)
    include_directories(${GTEST_ROOT}/include)
    
    include_directories(${GTEST_ROOT}/include)
    add_executable(gtest_example gtest_example.cpp)
    target_link_libraries(gtest_example
      pthread
      ${GTEST_ROOT}/build/libgtest.a
      ${GTEST_ROOT}/build/libgtest_main.a
    )

を用意し、「$> cmake .」実行後に生成される Makefileはこんな感じ

  • Makefile
  • # CMAKE generated file: DO NOT EDIT!
    # Generated by "Unix Makefiles" Generator, CMake Version 2.8
    
    # Default target executed when no arguments are given to make.
    default_target: all
    .PHONY : default_target
    
    #=============================================================================
    # Special targets provided by cmake.
    
    # Disable implicit rules so canonical targets will work.
    .SUFFIXES:
    
    # Remove some rules from gmake that .SUFFIXES does not remove.
    SUFFIXES =
    
    .SUFFIXES: .hpux_make_needs_suffix_list
    
    # Suppress display of executed commands.
    $(VERBOSE).SILENT:
    
    # A target that is always out of date.
    cmake_force:
    .PHONY : cmake_force
    
    #=============================================================================
    # Set environment variables for the build.
    
    # The shell in which to execute make rules.
    SHELL = /bin/sh
    
    # The CMake executable.
    CMAKE_COMMAND = /usr/bin/cmake
    
    # The command to remove a file.
    RM = /usr/bin/cmake -E remove -f
    
    # The top-level source directory on which CMake was run.
    CMAKE_SOURCE_DIR = /home/kocha/work/tools/gtest/example
    
    # The top-level build directory on which CMake was run.
    CMAKE_BINARY_DIR = /home/kocha/work/tools/gtest/example
    
    #=============================================================================
    # Targets provided globally by CMake.
    
    # Special rule for the target edit_cache
    edit_cache:
        @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running interactive CMake command-line interface..."
        /usr/bin/cmake -i .
    .PHONY : edit_cache
    
    # Special rule for the target edit_cache
    edit_cache/fast: edit_cache
    .PHONY : edit_cache/fast
    
    # Special rule for the target rebuild_cache
    rebuild_cache:
        @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
        /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
    .PHONY : rebuild_cache
    
    # Special rule for the target rebuild_cache
    rebuild_cache/fast: rebuild_cache
    .PHONY : rebuild_cache/fast
    
    # The main all target
    all: cmake_check_build_system
        $(CMAKE_COMMAND) -E cmake_progress_start /home/kocha/work/tools/gtest/example/CMakeFiles /home/kocha/work/tools/gtest/example/CMakeFiles/progress.marks
        $(MAKE) -f CMakeFiles/Makefile2 all
        $(CMAKE_COMMAND) -E cmake_progress_start /home/kocha/work/tools/gtest/example/CMakeFiles 0
    .PHONY : all
    
    # The main clean target
    clean:
        $(MAKE) -f CMakeFiles/Makefile2 clean
    .PHONY : clean
    
    # The main clean target
    clean/fast: clean
    .PHONY : clean/fast
    
    # Prepare targets for installation.
    preinstall: all
        $(MAKE) -f CMakeFiles/Makefile2 preinstall
    .PHONY : preinstall
    
    # Prepare targets for installation.
    preinstall/fast:
        $(MAKE) -f CMakeFiles/Makefile2 preinstall
    .PHONY : preinstall/fast
    
    # clear depends
    depend:
        $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
    .PHONY : depend
    
    #=============================================================================
    # Target rules for targets named gtest_example
    
    # Build rule for target.
    gtest_example: cmake_check_build_system
        $(MAKE) -f CMakeFiles/Makefile2 gtest_example
    .PHONY : gtest_example
    
    # fast build rule for target.
    gtest_example/fast:
        $(MAKE) -f CMakeFiles/gtest_example.dir/build.make CMakeFiles/gtest_example.dir/build
    .PHONY : gtest_example/fast
    
    # target to build an object file
    gtest_example.o:
        $(MAKE) -f CMakeFiles/gtest_example.dir/build.make CMakeFiles/gtest_example.dir/gtest_example.o
    .PHONY : gtest_example.o
    
    # target to preprocess a source file
    gtest_example.i:
        $(MAKE) -f CMakeFiles/gtest_example.dir/build.make CMakeFiles/gtest_example.dir/gtest_example.i
    .PHONY : gtest_example.i
    
    # target to generate assembly for a file
    gtest_example.s:
        $(MAKE) -f CMakeFiles/gtest_example.dir/build.make CMakeFiles/gtest_example.dir/gtest_example.s
    .PHONY : gtest_example.s
    
    # Help Target
    help:
        @echo "The following are some of the valid targets for this Makefile:"
        @echo "... all (the default if no target is provided)"
        @echo "... clean"
        @echo "... depend"
        @echo "... edit_cache"
        @echo "... gtest_example"
        @echo "... rebuild_cache"
        @echo "... gtest_example.o"
        @echo "... gtest_example.i"
        @echo "... gtest_example.s"
    .PHONY : help
    
    
    
    #=============================================================================
    # Special targets to cleanup operation of make.
    
    # Special rule to run CMake to check the build system integrity.
    # No rule that depends on this can have commands that come from listfiles
    # because they might be regenerated.
    cmake_check_build_system:
        $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
    .PHONY : cmake_check_build_system
    

これだけでもかなり便利だな〜っと実感
積極的に使っていこうかなと思う。


参考

関連記事

コメントの投稿

非公開コメント

プロフィール

Kocha

Author:Kocha
なんでもチャレンジ!(^o^)/
E-mail
github:Kocha
イベントカレンダー

カレンダー
10 | 2017/11 | 12
- - - 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 - -
カテゴリ
OVP (4)
最新記事
最新コメント
アーカイブ
リンク
Twitter
アクセス人数