cmake multi executable example

This commit is contained in:
Ciro Santilli 2017-10-14 07:49:50 +01:00
parent b7e2282b31
commit d76e3de59d
7 changed files with 27 additions and 2 deletions

View File

@ -119,5 +119,5 @@
1. [C++ templates](template_cpp.c)
1. [String to int](string_to_int.c)
1. [User input](interactive/user_input.c.off)
1. [Virtual memory](virtual_memory.c)
1. [Memory layout](memory_layout.c)
1. [Profiling](interactive/profiling.c)

View File

@ -30,7 +30,7 @@ int main(int argc, char **argv) {
printf(" &heap = %0*" PRIxPTR "\n", PRIxPTR_WIDTH, (uintptr_t)heap);
printf(" &bss = %0*" PRIxPTR "\n", PRIxPTR_WIDTH, (uintptr_t)&bss);
printf(" &data = %0*" PRIxPTR "\n", PRIxPTR_WIDTH, (uintptr_t)&data);
printf(" &str main = %0*" PRIxPTR "\n", PRIxPTR_WIDTH, (uintptr_t)&main);
printf(" &main = %0*" PRIxPTR "\n", PRIxPTR_WIDTH, (uintptr_t)&main);
printf(" &str char* = %0*" PRIxPTR "\n", PRIxPTR_WIDTH, (uintptr_t)&str);
free(heap);

View File

@ -1,5 +1,8 @@
# CMake
Good examples: <https://github.com/ttroy50/cmake-examples>
1. [multi_executable](multi_executable/)
1. [shared_lib_external](shared_lib_external/)
Make alternative that aims to be portable.

View File

@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.0)
file(GLOB APP_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "*.c")
message("${APP_SOURCES}")
foreach(testsourcefile ${APP_SOURCES})
string(REPLACE ".c" "" testname ${testsourcefile})
add_executable(${testname} ${testsourcefile})
endforeach(testsourcefile ${APP_SOURCES})

View File

@ -0,0 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
int main(void) {
puts(__FILE__);
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
int main(void) {
puts(__FILE__);
return EXIT_SUCCESS;
}

View File

@ -1,3 +1,4 @@
# sudo apt-get install libgsl-dev
cmake_minimum_required(VERSION 2.8)
add_executable(main main.c)
target_link_libraries(main gsl gslcblas)