Skip to content

Instantly share code, notes, and snippets.

@cprieto
Last active March 28, 2017 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cprieto/79f3c5c7907dcc64dfca949e06b3c970 to your computer and use it in GitHub Desktop.
Save cprieto/79f3c5c7907dcc64dfca949e06b3c970 to your computer and use it in GitHub Desktop.
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