This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Add this to prevent in-source builds | |
| if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) | |
| message(FATAL_ERROR "In-source builds not allowed!") | |
| endif() | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Modern way (CMake 3.0+) | |
| target_link_libraries(app PRIVATE mylib) | |
| # Old way (avoid this) | |
| link_libraries(mylib) | |
| add_executable(app main.c) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | target_include_directories(mylib | |
| PUBLIC include # Users of the library need this | |
| PRIVATE src # Only for building the library | |
| ) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Good - affects only this target | |
| target_compile_options(myapp PRIVATE -Wall) | |
| # Bad - affects everything globally | |
| add_compile_options(-Wall) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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> | |
| ) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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 | |
| ) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #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)); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #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); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #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) { | 
NewerOlder