Skip to content

Instantly share code, notes, and snippets.

@YooWaan
Last active May 1, 2021 02:37
Show Gist options
  • Save YooWaan/cca667f4a4b3a92137e88da208b5984c to your computer and use it in GitHub Desktop.
Save YooWaan/cca667f4a4b3a92137e88da208b5984c to your computer and use it in GitHub Desktop.
My CMake Note

CMake My Note

Env

prj-dir
|CMakeList.txt
|src/*.c,*cpp
|inc/*.h,*.hpp
`bin/<executable files>

Run Command

Generate

# linux
$ cmake -GNinja

# macOS
$ cmake -GNinja CMakeLists.txt -D CMAKE_CXX_COMPILER=/usr/bin/g++

build & execute

$ ninja

$ ./runcmd
cmake_minimum_required(VERSION 3.20)
project( my_app CXX )
# lib
add_library( other OBJECT src/other.cpp)
# add_library( other STATIC src/other.cpp )
target_include_directories( other PRIVATE ./inc)
target_compile_options( other PUBLIC -w -Wall )
target_compile_features( other PUBLIC cxx_std_17)
# if STATIC,SHARE set_target_properties( other PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ./lib)
# bin
add_executable(runcmd src/main.cpp)
target_compile_options( runcmd PUBLIC -w -Wall )
target_compile_features( runcmd PUBLIC cxx_std_17)
target_link_libraries(runcmd other )
target_include_directories(runcmd PRIVATE ./inc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment