commit 1771977c98a8ec5adf4ba26feb39bf4c5c838b08 Author: Václav Valíček Date: Sun May 17 23:16:40 2020 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b4ab6da --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ + +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps +cmake-* diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..8bf4d45 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,6 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..2d85490 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +test_static_library \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..79b3c94 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..eb1acf3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/test-static-library.iml b/.idea/test-static-library.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/test-static-library.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5a12ce4 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,52 @@ +cmake_minimum_required(VERSION 3.9) +# project definition +project(test_static_library LANGUAGES C VERSION 1.0.0 DESCRIPTION "Static C Library for testing of various cmake configurations") +set(CMAKE_C_STANDARD 99) +include(GNUInstallDirs) +enable_testing() + + +# define library +add_library(${PROJECT_NAME} STATIC src/test_static_library.c include/test_static_library.h) + +# library properties and meta vars +set_target_properties(test_static_library PROPERTIES + VERSION ${PROJECT_VERSION} + PUBLIC_HEADER include/test_static_library.h) + +#target_include_directories(test_shared_library PRIVATE .) +target_include_directories(${PROJECT_NAME} PUBLIC + $ + $ + PRIVATE src) + + +# pkg-config props +configure_file(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) + +# export native cmake package +install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Config + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +# export pkg-config package +install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig) + +# install exported packages +install(EXPORT ${PROJECT_NAME}Config DESTINATION share/${PROJECT_NAME}/cmake) +export(TARGETS ${PROJECT_NAME} FILE ${PROJECT_NAME}Config.cmake) + + + +message(STATUS "${CMAKE_C_FLAGS}") + +# test executable +add_executable(test_library test.c) +target_link_libraries(test_library ${PROJECT_NAME}) + +# testing support with make test +add_test(test_shared_lib_dynamic test_library) + + + diff --git a/include/test_static_library.h b/include/test_static_library.h new file mode 100644 index 0000000..add104a --- /dev/null +++ b/include/test_static_library.h @@ -0,0 +1,6 @@ +#ifndef TEST_STATIC_LIBRARY_H +#define TEST_STATIC_LIBRARY_H + +int hello(int input); + +#endif //TEST_STATIC_LIBRARY_H diff --git a/src/test_static_library.c b/src/test_static_library.c new file mode 100644 index 0000000..cef6704 --- /dev/null +++ b/src/test_static_library.c @@ -0,0 +1,8 @@ +#include +#include + +int hello(int input) { + input -= 2; + printf("Hello, World %d!\n", input); + return input; +} diff --git a/test.c b/test.c new file mode 100644 index 0000000..1283d02 --- /dev/null +++ b/test.c @@ -0,0 +1,8 @@ +#include +#include + +int main(void) { + printf("Program should print \"Hello World \" by calling static library function.\n"); + hello(12); + return 0; +} \ No newline at end of file diff --git a/test_static_library.pc.in b/test_static_library.pc.in new file mode 100644 index 0000000..f5aac29 --- /dev/null +++ b/test_static_library.pc.in @@ -0,0 +1,10 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +includedir=${prefix}/include +libdir=${exec_prefix}/lib + +Name: @PROJECT_NAME@ +Description: @PROJECT_DESCRIPTION@ +Version: @PROJECT_VERSION@ +Cflags: -I${includedir} +Libs: -L${libdir} \ No newline at end of file