Initial commit

This commit is contained in:
Václav Valíček 2020-05-17 23:16:40 +02:00
commit 1771977c98
11 changed files with 118 additions and 0 deletions

13
.gitignore vendored Normal file
View File

@ -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-*

6
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

1
.idea/.name Normal file
View File

@ -0,0 +1 @@
test_static_library

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/test-static-library.iml" filepath="$PROJECT_DIR$/.idea/test-static-library.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

52
CMakeLists.txt Normal file
View File

@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
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)

View File

@ -0,0 +1,6 @@
#ifndef TEST_STATIC_LIBRARY_H
#define TEST_STATIC_LIBRARY_H
int hello(int input);
#endif //TEST_STATIC_LIBRARY_H

View File

@ -0,0 +1,8 @@
#include <test_static_library.h>
#include <stdio.h>
int hello(int input) {
input -= 2;
printf("Hello, World %d!\n", input);
return input;
}

8
test.c Normal file
View File

@ -0,0 +1,8 @@
#include <test_static_library.h>
#include <stdio.h>
int main(void) {
printf("Program should print \"Hello World <param-2>\" by calling static library function.\n");
hello(12);
return 0;
}

10
test_static_library.pc.in Normal file
View File

@ -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}