CMake static library example added.
This commit is contained in:
parent
b6d6d84dcd
commit
7fa1a0a6d6
5
c/cmake_static_lib/CMakeLists.txt
Normal file
5
c/cmake_static_lib/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
cmake_minimum_required (VERSION 2.6)
|
||||
project (HELLO)
|
||||
|
||||
add_subdirectory (libmean)
|
||||
add_subdirectory (test)
|
1
c/cmake_static_lib/libmean/CMakeLists.txt
Normal file
1
c/cmake_static_lib/libmean/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
add_library (libmean mean.c)
|
5
c/cmake_static_lib/libmean/mean.c
Normal file
5
c/cmake_static_lib/libmean/mean.c
Normal file
@ -0,0 +1,5 @@
|
||||
//#include <stdio.h>
|
||||
|
||||
double mean(double a, double b) {
|
||||
return (a+b) / 2;
|
||||
}
|
1
c/cmake_static_lib/libmean/mean.h
Normal file
1
c/cmake_static_lib/libmean/mean.h
Normal file
@ -0,0 +1 @@
|
||||
double mean(double, double);
|
7
c/cmake_static_lib/test/CMakeLists.txt
Normal file
7
c/cmake_static_lib/test/CMakeLists.txt
Normal file
@ -0,0 +1,7 @@
|
||||
include_directories (${HELLO_SOURCE_DIR}/libmean)
|
||||
|
||||
link_directories (${HELLO_BINARY_DIR}/libmean)
|
||||
|
||||
add_executable (helloDemo main)
|
||||
|
||||
target_link_libraries (helloDemo libmean)
|
15
c/cmake_static_lib/test/main.c
Normal file
15
c/cmake_static_lib/test/main.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
#include "mean.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
double v1, v2, m;
|
||||
v1 = 5.2;
|
||||
v2 = 7.9;
|
||||
|
||||
m = mean(v1, v2);
|
||||
|
||||
printf("The mean of %3.2f and %3.2f is %3.2f\n", v1, v2, m);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user