[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • You may highlight syntax and preserve whitespace by using [code] tags.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


Janitor applications are now closed. Thanks to all who applied!


[Advertise on 4chan]


File: IMG_1716.png (214 KB, 960x539)
214 KB PNG
>Neo/Vim bros using C/C++
How do you deal with Makefiles and cmake in your projects? Do you always write them from scratch, even in 2026?
>>
i wrote a makefile template that i use for most personal projects i write in C, and write scripts for anything that it doesn't cover
you only have to modify a few lines
here, have it

# Configuration
PROGRAM = <name of your program>
# Directories
SRC_DIRS += src
INC_DIRS += inc
LIB_DIRS +=
BIN_DIR = bin
# Compiler
CC = gcc
CFLAGS += -O3
DEFINES +=
LIBRARIES +=

# Script (Read Only)
# Lists
SRC_FILES = $(wildcard $(patsubst %,%/*.c,$(SRC_DIRS)))
SRC_TO_OBJ = $(addprefix ./$(BIN_DIR)/,$(addsuffix .o,$(notdir $(basename $1))))
OBJ_FILES = $(call SRC_TO_OBJ,$(SRC_FILES))
SRC_TO_DEP = $(addprefix ./$(BIN_DIR)/,$(addsuffix .d,$(notdir $(basename $1))))
DEP_FILES = $(call SRC_TO_DEP,$(SRC_FILES))

# Options
CFLAGS += $(foreach def,$(DEFINES),-D$(def))
CFLAGS += $(foreach dir,$(INC_DIRS),-I$(dir))
LDFLAGS += $(foreach dir,$(LIB_DIRS),-L$(dir)) -L$(BIN_DIR)
LDFLAGS += $(foreach lib,$(LIBRARIES),-l$(lib))

# Compiler
OUTPUT_COMMAND = $(CC) -o $(PROGRAM) $(OBJ_FILES) $(LDFLAGS)

# Targeter
define TARGETER
$(call SRC_TO_OBJ,$1) : $1 | $(BIN_DIR)
$(CC) -MD -MP -MT "$(call SRC_TO_DEP,$1) $$@" -c $(CFLAGS) -o $$@ $$<
endef

# Targets (Read Only)
.PHONY: all clean clean-d clean-o clean-x

all: $(PROGRAM)

clean: clean-d clean-o clean-x

clean-d:
rm -rf $(DEP_FILES)

clean-o:
rm -rf $(OBJ_FILES)

clean-x:
rm -rf $(PROGRAM)

$(PROGRAM): $(SRC_FILES) $(OBJ_FILES)
$(OUTPUT_COMMAND)

$(foreach src,$(SRC_FILES),$(eval $(call TARGETER,$(src))))

-include $(DEP_FILES)
>>
>>109027504
I'm using visual studio and I write cmakelists by hand.

The builtin microsoft build system is dogshit, and everyone recommends using cmake instead. It's the same story on clion, though I don't use it anymore.

I just have a template cmake for every project
CMAKE_MINIMUM_REQUIRED(VERSION 3.22)
PROJECT(project_name LANGUAGES CXX)

SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)
SET(CMAKE_CXX_FLAGS "-Wall -Wextra -Wconversion -pedantic -std=c++98 -ggdb")

FILE(GLOB_RECURSE SOURCES
"src/*.cpp")

ADD_EXECUTABLE(${CMAKE_PROJECT_NAME} ${SOURCES})

It works with clang, and should work with g++ too.
This one is good for 99% of projects. I do have some snippet to use mold instead of ld on linux.

Makefiles are nice too, cmake can integrate with make, but the other way around isn't really true. So for C++ I just stick to cmake.
>>
>>109027504
I just use makefiles and yes I write them by hand
I don't know what cmake does and don't really care either
>>
>>109027504
>How do you deal with Makefiles and cmake in your projects?
Just open the online manual and read it while going line by line.
>Do you always write them from scratch, even in 2026?
Haven't made anything in 2026 but if I did I'd probably just have a LLM make me a batch script to compile and skip the whole cmake fiasco.
>>
>>109027543
cmake is a cross-platform build system that generates native build system files
it is extremely homosexual
>>
yeah usually a makefile on the root of my project and I use \r to compile
>>
>>109027504
>le C
Rust, actually.
>>
>>109027531
>>109027529
Thanks anons
>>
>>109027504
cmake is cancer
>>
>>109027531
Setting the CMAKE_CXX_FLAGS variable directly is bad practice because it overrides and overwrites the defaults set by cmake for the platform you're on, which can be annoying.

Prefer

target_compile_options(YourTargetName 
PRIVATE
--List
-Of
--Compile
--options
)
>>
>>109027504
I just copy an old meson.build file and change it to fit my new project. Probs should script it instead.
>>
I write CMake files from scratch, who in turn generate the Makefiles.
>>
>>109027504
No, I use meson because I'm not retarded. Syntax and documentation is 10x better, managing dependencies is much better and it just werks.
If you use cmake then at the very least make it generate ninja instead of makefiles. Makefiles are slow.
Cmake is terrible, if you must use it then prefer to do things the dumb way and NEVER use shitty features like modules, they're a massive waste of time.
>>
>>109028021
while this is factually correct, you can't really do C++ without CMake, so you may as well stop being a whiny bitch, and learn to do it right. it's not too bad when done by the books.
>>
>>109027504
I use neovim and meson. idk if there's any LSP for meson, but it's so EZ it has been a breeze to write by hand anyway.
>>
>>109027529
>
LDFLAGS += $(foreach lib,$(LIBRARIES),-l$(lib))

Might miss some flags, consider using pkg-config
>>
>>109027504
I use rust instead.
>>
Neo/Vim sisters are you still falling for memes in 2026 or the vim was the last one for you?
What was the last meme 4chan tech you fallen for?
>>
>>109029372
https://mesonbuild.com/

>>109029431
Shut the fuck up, I've been using (neo)vim for almost a decade now and I'm never going back. Works perfect for every single task. I never change my config except every 2 years or so.
>>
>>109029452
What is a config? Is editing text too hard for you, or is it too easy?
>>
I have been using the same CMake template since 2024
>>
>>109029466
LLM bot post



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.