Last active
March 28, 2017 00:17
-
-
Save cprieto/79f3c5c7907dcc64dfca949e06b3c970 to your computer and use it in GitHub Desktop.
CMake and Libraries - Part 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef GREETER_H | |
#define GREETER_H | |
void say_hello_to(char *nane); | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "greeter.h" | |
void say_hello_to (char *name) { | |
printf("Hello %s\n", name); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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