CMakeLists.txt :
# Set the minimum version of CMake that can be used # To find the cmake version run # $ cmake --version cmake_minimum_required(VERSION 3.5) # Set the project name project (hello_headers) # Create a sources variable with a link to all cpp files to compile set(SOURCES src/Hello.cpp src/main.cpp ) # Add an executable with the above sources add_executable(hello_headers ${SOURCES}) # Set the directories that should be included in the build command for this target # when running g++ these will be included as -I/directory/path/ target_include_directories(hello_headers PRIVATE ${PROJECT_SOURCE_DIR}/include ) |
Hello.h :
#ifndef __HELLO_H__ #define __HELLO_H__ class Hello { public: void print(); }; #endif |
Hello.cpp :
#include <iostream> #include "Hello.h" void Hello::print() { std::cout << "Hello Headers!" << std::endl; } |
main.cpp :
#include "Hello.h" int main(int argc, char *argv[]) { Hello hi; hi.print(); return 0; } |
mkdir build :
cd build
cmake ..
make
./hello_headers
[References]
[1] https://github.com/jacking75/examples_CMake
[2] https://github.com/ttroy50/cmake-examples
'Languages > C++' 카테고리의 다른 글
CMakeLists.txt for third-party-library (0) | 2022.05.24 |
---|