Skip to content

Commit

Permalink
add template of program with static library
Browse files Browse the repository at this point in the history
  • Loading branch information
UsovaMA committed Sep 14, 2020
1 parent 7996ee3 commit a611bd2
Show file tree
Hide file tree
Showing 13 changed files with 29,753 additions and 0 deletions.
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.6 FATAL_ERROR)

project(samples)

include(cmake/function.cmake)

add_subdirectory(function_lib)
add_subdirectory(main)

option(BTEST "build test?" OFF)

if(BTEST)
add_subdirectory(gtest)
add_subdirectory(test)
endif()
27 changes: 27 additions & 0 deletions cmake/function.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function(create_project_lib TARGET )
file(GLOB TARGET_SRC "*.c*")
file(GLOB TARGET_HD "*.h*")
add_library(${TARGET} STATIC ${TARGET_SRC} ${TARGET_HD})

get_property ( INCLUDE_DIRS GLOBAL PROPERTY INC_DIR)
list(APPEND INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
set_property ( GLOBAL PROPERTY INC_DIR ${INCLUDE_DIRS})

get_property ( LIB_LIST GLOBAL PROPERTY LIBS_P)
list(APPEND LIB_LIST ${TARGET})
set_property ( GLOBAL PROPERTY LIBS_P ${LIB_LIST})

endfunction()

function(create_executable_project TARGET)
file(GLOB TARGET_SRC "*.c*")
file(GLOB TARGET_HD "*.h*")
add_executable(${TARGET} ${TARGET_SRC} ${TARGET_HD})

get_property ( INCLUDE_DIRS GLOBAL PROPERTY INC_DIR)
target_include_directories(${TARGET} PUBLIC ${INCLUDE_DIRS})

get_property ( LIB_LIST GLOBAL PROPERTY LIBS_P)
target_link_libraries(${TARGET} ${LIB_LIST})

endfunction()
1 change: 1 addition & 0 deletions function_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create_project_lib(mylibrary)
3 changes: 3 additions & 0 deletions function_lib/add.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int add(int a, int b) {
return a + b;
}
6 changes: 6 additions & 0 deletions function_lib/add.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef INCLUDE_ADD_H_
#define INCLUDE_ADD_H_

int add(int a, int b);

#endif // INCLUDE_ADD_H_
18 changes: 18 additions & 0 deletions gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(target "gtest")
create_project_lib(${target})

#if((${CMAKE_CXX_COMPILER_ID} MATCHES "GNU" OR
# ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") AND
# (${CMAKE_SYSTEM_NAME} MATCHES "Linux"))
# set(pthread "-pthread")
#endif()
#target_link_libraries(${target} ${pthread})

find_package(Threads)
if(THREADS_HAVE_PTHREAD_ARG)
target_compile_options(${target} PUBLIC "-pthread")
endif()
if(CMAKE_THREAD_LIBS_INIT)
target_link_libraries(${target} "${CMAKE_THREAD_LIBS_INIT}")
endif()

Loading

0 comments on commit a611bd2

Please sign in to comment.