Skip to content

Commit 7a95f14

Browse files
Initial Project (#1)
* init first * init project * test failed * fixed build error
1 parent 4e730dd commit 7a95f14

File tree

7 files changed

+57
-52
lines changed

7 files changed

+57
-52
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Build
2+
on: [ push, pull_request ]
3+
jobs:
4+
build:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@master
8+
- run: cmake -B ./build -S .
9+
- run: cmake --build build

.gitignore

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,3 @@
1-
# Prerequisites
2-
*.d
3-
4-
# Object files
5-
*.o
6-
*.ko
7-
*.obj
8-
*.elf
9-
10-
# Linker output
11-
*.ilk
12-
*.map
13-
*.exp
14-
15-
# Precompiled Headers
16-
*.gch
17-
*.pch
18-
19-
# Libraries
20-
*.lib
21-
*.a
22-
*.la
23-
*.lo
24-
25-
# Shared objects (inc. Windows DLLs)
26-
*.dll
27-
*.so
28-
*.so.*
29-
*.dylib
30-
31-
# Executables
32-
*.exe
33-
*.out
34-
*.app
35-
*.i*86
36-
*.x86_64
37-
*.hex
38-
39-
# Debug files
40-
*.dSYM/
41-
*.su
42-
*.idb
43-
*.pdb
44-
45-
# Kernel Module Compile Results
46-
*.mod*
47-
*.cmd
48-
.tmp_versions/
49-
modules.order
50-
Module.symvers
51-
Mkfile.old
52-
dkms.conf
1+
.idea
2+
cmake-build-debug
3+
build

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.15.4)
2+
project(Examples C)
3+
4+
set(CMAKE_C_STANDARD 99)
5+
6+
add_subdirectory(maths)
7+
8+
add_executable(C main.c)

main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
printf("Hello, World!\n");
5+
return 0;
6+
}

maths/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# If necessary, use the RELATIVE flag, otherwise each source file may be listed
2+
# with full pathname. RELATIVE may makes it easier to extract an executable name
3+
# automatically.
4+
file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.c )
5+
# file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c )
6+
# AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES)
7+
foreach( testsourcefile ${APP_SOURCES} )
8+
# I used a simple string replace, to cut off .cpp.
9+
string( REPLACE ".c" "" testname ${testsourcefile} )
10+
add_executable( ${testname} ${testsourcefile} )
11+
install(TARGETS ${testname} DESTINATION "bin/maths")
12+
13+
endforeach( testsourcefile ${APP_SOURCES} )

maths/absolute.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <assert.h>
2+
int absolute(int number) {
3+
return number < 0 ? -number : number;
4+
}
5+
6+
int main() {
7+
assert(absolute(-2) == 2);
8+
}

maths/add.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <stdio.h>
2+
#include <assert.h>
3+
int add(int a, int b){
4+
return a + b;
5+
}
6+
7+
int main(){
8+
assert(add(3, 2) == 5);
9+
}
10+

0 commit comments

Comments
 (0)