Michael Profile Picture
Michael Malura
Entwickler - Fotograf - Technologie-Enthusiast

Ein C++ Programm mit CMake erstellen

22.04.2019 [ cpp, development, cmake, osx ]

Code

#include <iostream>
int main(int argc, char** args) {
  std::cout << "Hello, cmake!\n";
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.13)
project(basic)
add_executable(basic main.cpp)

Kompilieren

$ cmake .
-- The C compiler identification is AppleClang 10.0.1.10010046
-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/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: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/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: /Users/michael/development/projects/cmake-examples/basic
$ make
Scanning dependencies of target basic
[ 50%] Building CXX object CMakeFiles/basic.dir/main.cpp.o
[100%] Linking CXX executable basic
[100%] Built target basic
$ ./basic
Hello, cmake!