CMake2019年8月16日 | |
はじめにMake の代替ツール CMake のメモ。 環境Ubuntu 16.04 LTS インストールUbuntu なら apt-get でインストールできる。 $ sudo apt-get install cmake 最小のコンパイルソースファイルを aaa.cxx とする。CMakeLists.txt ファイルを作る。 CMakeLists.txt add_executable(aaa aaa.cxx) コンパイル。 $ mkdir build $ cd build $ cmake .. -- The C compiler identification is GNU 5.4.0 -- The CXX compiler identification is GNU 5.4.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done -- Build files have been written to: /home/xxx/work/aaa/build $ make Scanning dependencies of target aaa [ 50%] Building CXX object CMakeFiles/aaa.dir/aaa.cxx.o [100%] Linking CXX executable aaa [100%] Built target aaa 実行ファイル "aaa" ができる。 クリーンbuild ディレクトリの中身を消せばよい。 CMake のバージョン指定cmake_minimum_required(VERSION 2.8) ファイルをワイルドカードで指定
file(GLOB CXX_FILES *.cxx)
add_executable(aaa ${CXX_FILES})
インクルードパスinclude_directories(/usr/loca/include) ライブラリパスlink_directories(/usr/local/lib) ライブラリのリンクtarget_link_libraries(aaa lib1 lib2) パッケージの要求find_package(VTK REQUIRED) 要求されるパッケージを指定できる。対応しているパッケージは "cmake --help-module-list" で調べることができる。この中の "Find????" というものが対応している。 C++11 対応set(CMAKE_CXX_STANDARD 11) CMakeLists.txt の例Qt5 を利用したプログラムの例
cmake_minimum_required(VERSION 2.8)
find_package(Qt5Widgets REQUIRED)
file(GLOB CXX_FILES *.cxx)
add_executable(window ${CXX_FILES})
target_link_libraries(window ${Qt5Widgets_LIBRARIES})
| |
| PENGUINITIS | |