Skip to content

Commit 7c954cf

Browse files
committed
cmake multi file recursive
1 parent c1ab1fe commit 7c954cf

File tree

11 files changed

+44
-4
lines changed

11 files changed

+44
-4
lines changed

cmake/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
Good examples: <https://github.com/ttroy50/cmake-examples>
44

55
1. [multi_executable](multi_executable/)
6+
1. [multi_file](multi_file/)
7+
1. [multi_file_recursive](multi_file_recursive/)
68
1. [shared_lib_external](shared_lib_external/)
79

810
Make alternative that aims to be portable.

cmake/multi_executable/CMakeLists.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
cmake_minimum_required(VERSION 3.0)
2-
file(GLOB APP_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "*.c")
3-
message("${APP_SOURCES}")
4-
foreach(testsourcefile ${APP_SOURCES})
2+
file(GLOB SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "*.c")
3+
foreach(testsourcefile ${SOURCES})
54
string(REPLACE ".c" "" testname ${testsourcefile})
65
add_executable(${testname} ${testsourcefile})
7-
endforeach(testsourcefile ${APP_SOURCES})
6+
endforeach(testsourcefile ${SOURCES})

cmake/multi_file/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cmake_minimum_required(VERSION 3.0)
2+
file(GLOB SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "*.c")
3+
add_executable(main ${SOURCES})

cmake/multi_file/a.c

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "a.h"
2+
3+
int a(void) { return 42; }

cmake/multi_file/a.h

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ifndef A_H
2+
#define A_H
3+
int a(void);
4+
#endif

cmake/multi_file/main.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
#include "a.h"
5+
6+
int main(void) {
7+
printf("%d\n", a());
8+
return EXIT_SUCCESS;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cmake_minimum_required(VERSION 3.0)
2+
file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "src/*.c")
3+
add_executable(main ${SOURCES})

cmake/multi_file_recursive/src/d/a.c

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "a.h"
2+
3+
int a(void) { return 42; }

cmake/multi_file_recursive/src/d/a.h

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ifndef A_H
2+
#define A_H
3+
int a(void);
4+
#endif

cmake/multi_file_recursive/src/main.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
#include "d/a.h"
5+
6+
int main(void) {
7+
printf("%d\n", a());
8+
return EXIT_SUCCESS;
9+
}

sdl/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
1. [Animation random walk](animation_random_walk.c)
1212
1. [Animation user control](animation_user_control.c)
1313
1. [Animation user control discrete](animation_user_control_discrete.c)
14+
1. [Animation user control inertia](animation_user_control_inertia.c)
1415
1. [Two player discrete](two_player_discrete.c)
1516
1. [Two player discrete sync](two_player_discrete_sync.c)
1617
1. Plots

0 commit comments

Comments
 (0)