Skip to content

Instantly share code, notes, and snippets.

@jmoyers
Last active June 23, 2023 17:00
Show Gist options
  • Save jmoyers/de19d4a6050dcfe67d110782346496ce to your computer and use it in GitHub Desktop.
Save jmoyers/de19d4a6050dcfe67d110782346496ce to your computer and use it in GitHub Desktop.
Get up and running with a terminal, vim, and c++
" be iMproved, required
set nocompatible
" you want emojis and crap like that, right?
set encoding=utf-8
" linux yank to clipboard, paste from clipboard
" its different per platform :-(
set clipboard=unnamedplus
" Allows you to :e file automplete in subdirectories
set path+=**
set wildmenu
" Stops ctrlp from going into git and node_moduls folders
let g:ctrlp_custom_ignore = '\.git\|node_modules'
" Allows directory/project specific vimrc
set exrc
set secure
call plug#begin()
Plug 'ctrlpvim/ctrlp.vim'
Plug 'rhysd/vim-clang-format'
Plug 'tpope/vim-dispatch'
Plug 'dracula/vim', {'as': 'dracula'}
call plug#end()
colorscheme dracula
" clang
" set makeprg=clang++\ \-Wall\ -Werror\ -Wpedantic\ \-fstandalone-debug\ -std=c++17\ -D_GLIBCXX_DEBUG\ -g\ -o\ build/%<\ %
" CMake
" let &makeprg = "cd build/debug && make -j 16"
" note 16 is hardware concurrency for build
" make does an "out of tree build," thats why we cd into a diff directory
" this assumes you've run cmake ../.. inside build/debug ahead of time to generate the makefile
" gcc
set makeprg=g++\ \-Wall\ -Werror\ -Wpedantic\ -std=c++17\ -g\ -o\ build/%<\ %
set disassembly-flavor intel
set print pretty on
tui enable
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
set -g mouse on
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# magic vodoo for true color vim inside tmux
set -g default-terminal 'xterm-256color'
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'dracula/tmux'
# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin '[email protected]:user/plugin'
# set -g @plugin '[email protected]:user/plugin'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
# here be an example medium sized CMakeLists.txt (the backbone of a CMake project)
# this is for a node addon/electron project I was working on, so there are some bits specific to that
# specify minimum version of cmake required
cmake_minimum_required(VERSION 3.5)
# name the project, semver version
project(combat VERSION 0.0.1)
# any -D flags you pass to your compiler for #define #ifdef type code
# this particular line not required for something that isn't a node c++ addon
add_definitions(-DNAPI_VERSION=3)
# link to libc++
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
# we want c++17, libc++, to use clang memory sanitizer and to track the origin of the memory issues
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -stdlib=libc++ -fsanitize=memory -fsanitize-memory-track-origins")
# header include directories, linking against custom build of libc++ and node-addon-api
include_directories(
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/node_modules/node-addon-api
/usr/include/nodejs/src
/home/jmoyers/dev/llvm-project/build/include
)
# library search directory
link_directories(
/home/jmoyers/dev/llvm-project/build/lib
)
# link against pthread for c++ standard library thread classes on linux and c++abi for libc++
link_libraries(pthread c++abi)
# create a shared library target from the source list, cmakejs is a tool for using cmake with
# node addons, safe to ignore. it adds a source list that lets you skip using gyp tool
add_library(combat_addon SHARED src/main.cpp ${CMAKE_JS_SRC})
# add a static library with these source files
add_library(combat_lib
include/logs.hpp
include/pool.hpp
)
# set target specific build properties. these things generally
# change compiler flags, sometimes do other target specific things
# CXX_STANDARD is the modern CMake way to set -std=c++17 etc
# PREFIX/SUFFIX stuff is node specific, they want their addon libraries to
# end in .node
set_target_properties(combat_addon PROPERTIES
PREFIX ""
SUFFIX ".node"
CXX_STANDARD 17
LINKER_LANGUAGE CXX
)
set_target_properties(combat_lib PROPERTIES
CXX_STANDARD 17
LINKER_LANGUAGE CXX
)
# add subdirectories, which INCLUDE child CMakeLists.txt
add_subdirectory(test)
add_subdirectory(benchmarks)
# these are literally cloned versions of google test and google benchmark. we link
# against them inside the tests/ and benchmarks/ subprojects
add_subdirectory(vendor/googletest)
add_subdirectory(vendor/benchmark)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment