Skip to content

Swepz/Simple_CMake_Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple C project structure example using CMake

Note that this project does not require the user to smash commands in terminal. If the user have a IDE that supports CMake the executable will be found and added.

Required packages are CMake(version > 3.1)

Installation:

Ubuntu

sudo apt install cmake

Arch Linux

sudo pacman -S cmake

Other: Select a distro that floats your boat

How to: Define project name

  1. Locate CMakeLists.txt in root directory
CMakeLists.txt <----------------- Change here
include/
inc/
build/
run.sh
README.md
source/
  1. Change "exampleProjectName" to a suitable name

Example:

project(exampleProjectName LANGUAGES C)

exampleProjectName -> realProjectName

project(realProjectName LANGUAGES C)

How to: Build, compile & run

sh run main

Note that the run.sh file might not be executable

  • If not executable then

    chmod +x run

Edit shell script for custom target to be launched

The file binary file "main" comes from source/CMakeLists.txt

"add_executable(main main.c)"

Note: Math has been linked to target "main" by default

target_link_libraries(sharedLibrary INTERFACE ${MATH})