Skip to content

Instantly share code, notes, and snippets.

View 0xskaper's full-sized avatar
🔥
On my learning arc.

Rajat Yadav 0xskaper

🔥
On my learning arc.
View GitHub Profile
# Add this to prevent in-source builds
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds not allowed!")
endif()
# Modern way (CMake 3.0+)
target_link_libraries(app PRIVATE mylib)
# Old way (avoid this)
link_libraries(mylib)
add_executable(app main.c)
target_include_directories(mylib
PUBLIC include # Users of the library need this
PRIVATE src # Only for building the library
)
# Good - affects only this target
target_compile_options(myapp PRIVATE -Wall)
# Bad - affects everything globally
add_compile_options(-Wall)
cmake_minimum_required(VERSION 3.10)
project(Calc VERSION 1.0 LANGUAGES C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(COMMON_WARNING
$<$<C_COMPILER_ID:MSVC>:/W4 /WX>
$<$<NOT:$<C_COMPILER_ID:MSVC>>:-Wall -Wextra -Werror>
)
cmake_minimum_required(VERSION 3.10)
project(Calc VERSION 1.0 LANGUAGES C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
add_library(calclib STATIC
src/math_utils.c
src/utils.c
)
cmake_minimum_required(VERSION 3.10)
project(Calc VERSION 1.0 LANGUAGES C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
include_directories(include)
set(SOURCES
src/main.c
#include "math_utils.h"
#include "utils.h"
#include <stdio.h>
int main(void) {
double a = read_input("Enter A: ");
double b = read_input("Enter B: ");
print_result("Addition -> ", add(a, b));
print_result("Multiply -> ", multiply(a, b));
#include "utils.h"
#include <stdio.h>
void print_result(const char *operation, double result) {
printf("%s Result -> %.2f\n", operation, result);
}
double read_input(const char *prompt) {
double num;
printf("%s", prompt);
#include "math_utils.h"
#include <stdio.h>
double add(double a, double b) { return a + b; }
double multiply(double a, double b) { return a * b; }
double subtract(double a, double b) { return a - b; }
double division(double a, double b) {