Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
CMake and Libraries - Part 1
cmake_minimum_required (VERSION 3.6)
project (hello VERSION 1.0)
set (LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/output)
add_subdirectory (greeter)
add_subdirectory (hello_app)
cmake_minimum_required (VERSION 3.6)
project (greeter VERSION 1.0)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/includes)
set (GREETER_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set (GREETER_SOURCE ${GREETER_SOURCE_DIR}/greeter.c)
add_library (greeter SHARED ${GREETER_SOURCE})
add_library (greeter_static STATIC ${GREETER_SOURCE})
target_include_directories (greeter PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/includes)
#ifndef GREETER_H
#define GREETER_H
void say_hello_to(char *nane);
#endif
#include <stdio.h>
#include "greeter.h"
void say_hello_to (char *name) {
printf("Hello %s\n", name);
}
cmake_minimum_required (VERSION 3.6)
project (app VERSION 1.0)
set (APP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set (APP_SOURCE ${APP_SOURCE_DIR}/main.c)
add_executable (app ${APP_SOURCE})
target_link_libraries (app greeter)
#include "greeter.h"
int main(){
say_hello_to ("cristian");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment