diff options
author | Seungha Son <seungha.son@samsung.com> | 2021-01-27 20:57:05 +0900 |
---|---|---|
committer | Seungha Son <seungha.son@samsung.com> | 2021-01-28 06:42:43 +0900 |
commit | cab111e0a975aff2b8a9119cbda7407e26f2ec28 (patch) | |
tree | 2f45fbb6d09ce2191695e8d58c57ce38ca2bc2aa | |
parent | c5a09eb4dee1775a64413c137bd5012c780614b2 (diff) | |
download | ttrace-cab111e0a975aff2b8a9119cbda7407e26f2ec28.tar.gz ttrace-cab111e0a975aff2b8a9119cbda7407e26f2ec28.tar.bz2 ttrace-cab111e0a975aff2b8a9119cbda7407e26f2ec28.zip |
Refactor cmake build structuresubmit/tizen/20210128.033347
This patch is for refactor cmake build structure.
To facilitate analysis and modification by separating it
'src','atrace','atrace-helper', and 'test', respectively.
Change-Id: I2f2349fd0e055e4f7a719da733c185896aaf7464
Signed-off-by: Seungha Son <seungha.son@samsung.com>
-rwxr-xr-x | CMakeLists.txt | 55 | ||||
-rw-r--r-- | atrace-helper/CMakeLists.txt | 16 | ||||
-rw-r--r-- | atrace/CMakeLists.txt | 27 | ||||
-rw-r--r-- | cmake/Modules/ApplyPkgConfig.cmake | 35 | ||||
-rw-r--r-- | packaging/ttrace.spec | 2 | ||||
-rw-r--r-- | src/CMakeLists.txt | 21 | ||||
-rw-r--r-- | test/CMakeLists.txt | 9 |
7 files changed, 91 insertions, 74 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d1796fb..4233798 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) PROJECT(ttrace C CXX) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) @@ -10,11 +10,13 @@ ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS}") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS}") - +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++11 -fPIE") +SET(CMAKE_EXE_LINKER_FLAGS "-ldl") SET(CMAKE_SKIP_BUILD_RPATH TRUE) # Generate ttrace.h SET(TTRACE_H_IN ttrace.h.in) + IF("${TTRACE_PROFILE}" STREQUAL "tv") SET(TTRACE_PROFILE_TV ON) ELSEIF("${TTRACE_PROFILE}" STREQUAL "wearable") @@ -29,50 +31,31 @@ ELSE() SET(TTRACE_TIZEN_VERSION_MAJOR "2") ENDIF() -configure_file(${TTRACE_H_IN} "include/ttrace.h") - - - -################################################################# -# Set common componenets for library -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRC) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) -# ------------------------------ -# Build ttrace Library (Shared) -# ------------------------------ -SET(TTRACE "ttrace") - -INCLUDE(FindPkgConfig) -pkg_check_modules(pkg_ttrace REQUIRED dlog capi-base-common) -FOREACH(flag ${pkg_ttrace_CFLAGS}) - SET(EXTRA_CFLAGS_common "${EXTRA_CFLAGS_common} ${flag}") -ENDFOREACH(flag) - IF("${COVERAGE}" STREQUAL "on") ADD_DEFINITIONS("-DTTRACE_COVERAGE") ENDIF() -ADD_LIBRARY(${TTRACE} SHARED ${SRC}) - -SET_TARGET_PROPERTIES(${TTRACE} PROPERTIES SOVERSION ${MAJORVER}) -SET_TARGET_PROPERTIES(${TTRACE} PROPERTIES VERSION ${FULLVER}) -SET_TARGET_PROPERTIES(${TTRACE} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_common}) -TARGET_LINK_LIBRARIES(${TTRACE} ${pkg_ttrace_LDFLAGS} "-ldl") +CONFIGURE_FILE(${TTRACE_H_IN} "include/ttrace.h") -CONFIGURE_FILE(${TTRACE}.pc.in ${TTRACE}.pc @ONLY) - -INSTALL(TARGETS ${TTRACE} DESTINATION ${LIBDIR} COMPONENT RuntimeLibraries) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TTRACE}.pc DESTINATION ${LIBDIR}/pkgconfig) +SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") +INCLUDE(FindPkgConfig) +INCLUDE(ApplyPkgConfig) -INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ - DESTINATION include - FILES_MATCHING - PATTERN "*.h") +PKG_CHECK_MODULES(DLOG_DEPS REQUIRED dlog) +PKG_CHECK_MODULES(CAPI_BASE_COMMON_DEPS REQUIRED capi-base-common) +PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock) +PKG_CHECK_MODULES(ZLIB_DEPS REQUIRED zlib) +PKG_CHECK_MODULES(SMACK_DEPS REQUIRED libsmack) ################################################################# +SET(TARGET_TTRACE "ttrace") +SET(TARGET_ATRACE "atrace") +SET(TARGET_ATRACE_HELPER "atrace-helper") +SET(TARGET_TTRACE_UNIT_TEST "ttrace-unit-test") +################################################################# # Build atrace / atrace-helper # ------------------------------ +ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(atrace) ADD_SUBDIRECTORY(atrace-helper) - ADD_SUBDIRECTORY(test) diff --git a/atrace-helper/CMakeLists.txt b/atrace-helper/CMakeLists.txt index 746d91a..13d52b3 100644 --- a/atrace-helper/CMakeLists.txt +++ b/atrace-helper/CMakeLists.txt @@ -1,18 +1,8 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(atrace-helper CXX) - -SET(PREFIX ${CMAKE_INSTALL_PREFIX}) -SET(EXEC_PREFIX "\${prefix}") - INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCES) -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++11") -SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") -SET(CMAKE_CXX_FLAGS_RELEASE "-O2") - -ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCES}) +ADD_EXECUTABLE(${TARGET_ATRACE_HELPER} ${SOURCES}) -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${ATRACE_HELPER_VERSION}) +SET_TARGET_PROPERTIES(${TARGET_ATRACE_HELPER} PROPERTIES VERSION ${ATRACE_HELPER_VERSION}) -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) +INSTALL(TARGETS ${TARGET_ATRACE_HELPER} DESTINATION bin) diff --git a/atrace/CMakeLists.txt b/atrace/CMakeLists.txt index c5c7e7f..5c44a60 100644 --- a/atrace/CMakeLists.txt +++ b/atrace/CMakeLists.txt @@ -1,24 +1,13 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(atrace C) - -SET(PREFIX ${CMAKE_INSTALL_PREFIX}) -SET(EXEC_PREFIX "\${prefix}") - -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++11 -fPIE") -SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") -SET(CMAKE_CXX_FLAGS_RELEASE "-O2") - AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCES) +ADD_EXECUTABLE(${TARGET_ATRACE} ${SOURCES}) -INCLUDE(FindPkgConfig) -pkg_check_modules(pkg_atrace REQUIRED zlib libsmack) -FOREACH(flag ${pkg_atrace_CXXFLAGS}) - SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}") -ENDFOREACH(flag) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../include) -ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCES}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkg_atrace_LDFLAGS} "-ldl") +SET_TARGET_PROPERTIES(${TARGET_ATRACE} PROPERTIES VERSION ${ATRACE_VERSION}) -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${ATRACE_VERSION}) +APPLY_PKG_CONFIG(${TARGET_ATRACE} PUBLIC + ZLIB_DEPS + SMACK_DEPS +) -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) +INSTALL(TARGETS ${TARGET_ATRACE} DESTINATION bin) diff --git a/cmake/Modules/ApplyPkgConfig.cmake b/cmake/Modules/ApplyPkgConfig.cmake new file mode 100644 index 0000000..9d107c3 --- /dev/null +++ b/cmake/Modules/ApplyPkgConfig.cmake @@ -0,0 +1,35 @@ +# Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# +# This function applies external (out of source tree) dependencies +# to given target. Arguments are: +# TARGET - valid cmake target +# PRIVACY - dependency can be inherited by dependent targets or not: +# PUBLIC - this should be used by default, cause compile/link flags passing +# PRIVATE - do not passes any settings to dependent targets, +# may be usefull for static libraries from the inside of the project +# Argument ARGV2 and following are supposed to be names of checked pkg config +# packages. This function will use variables created by check_pkg_modules(). +# - ${DEP_NAME}_LIBRARIES +# - ${DEP_NAME}_INCLUDE_DIRS +# - ${DEP_NAME}_CFLAGS +# +FUNCTION(APPLY_PKG_CONFIG TARGET PRIVACY) + MATH(EXPR DEST_INDEX "${ARGC}-1") + FOREACH(I RANGE 2 ${DEST_INDEX}) + IF(NOT ${ARGV${I}}_FOUND) + MESSAGE(FATAL_ERROR "Not found dependency - ${ARGV${I}}_FOUND") + ENDIF(NOT ${ARGV${I}}_FOUND) + TARGET_LINK_LIBRARIES(${TARGET} ${PRIVACY} "${${ARGV${I}}_LIBRARIES}") + TARGET_INCLUDE_DIRECTORIES(${TARGET} ${PRIVACY} SYSTEM "${${ARGV${I}}_INCLUDE_DIRS}") + STRING(REPLACE ";" " " CFLAGS_STR "${${ARGV${I}}_CFLAGS}") + SET(CFLAGS_LIST ${CFLAGS_STR}) + SEPARATE_ARGUMENTS(CFLAGS_LIST) + FOREACH(OPTION ${CFLAGS_LIST}) + TARGET_COMPILE_OPTIONS(${TARGET} ${PRIVACY} ${OPTION}) + ENDFOREACH(OPTION) + SET_TARGET_PROPERTIES(${TARGET} PROPERTIES SKIP_BUILD_RPATH true) + ENDFOREACH(I RANGE 2 ${DEST_INDEX}) +ENDFUNCTION(APPLY_PKG_CONFIG TARGET PRIVACY) diff --git a/packaging/ttrace.spec b/packaging/ttrace.spec index 81008e6..6900adc 100644 --- a/packaging/ttrace.spec +++ b/packaging/ttrace.spec @@ -95,7 +95,7 @@ find . -name '*.gcno' -exec cp '{}' gcov-obj ';' %endif %check -(cd test && LD_LIBRARY_PATH=../ ctest -V) +(cd test && LD_LIBRARY_PATH=../src ctest -V) %if 0%{?gcov:1} lcov -c --ignore-errors graph --no-external -q -d . -o ttrace.info genhtml ttrace.info -o ttrace.out diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..739dfc3 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,21 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SRC) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) + +ADD_LIBRARY(${TARGET_TTRACE} SHARED ${SRC}) + +APPLY_PKG_CONFIG(${TARGET_TTRACE} PUBLIC + DLOG_DEPS + CAPI_BASE_COMMON_DEPS +) + +SET_TARGET_PROPERTIES(${TARGET_TTRACE} PROPERTIES SOVERSION ${MAJORVER}) +SET_TARGET_PROPERTIES(${TARGET_TTRACE} PROPERTIES VERSION ${FULLVER}) + +CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/${TARGET_TTRACE}.pc.in ${CMAKE_SOURCE_DIR}/${TARGET_TTRACE}.pc @ONLY) + +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../${TARGET_TTRACE}.pc DESTINATION ${LIBDIR}/pkgconfig) +INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ + DESTINATION include + FILES_MATCHING + PATTERN "*.h") +INSTALL(TARGETS ${TARGET_TTRACE} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 405c263..a3dd22a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,4 @@ ENABLE_TESTING() -SET(TARGET_TTRACE_UNIT_TEST "ttrace-unit-test") AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src UNIT_TESTS_SRCS) @@ -9,11 +8,11 @@ TARGET_INCLUDE_DIRECTORIES(${TARGET_TTRACE_UNIT_TEST} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../include" ) -INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(gtest_pkgs REQUIRED gmock) - -TARGET_LINK_LIBRARIES(${TARGET_TTRACE_UNIT_TEST} PUBLIC ${gtest_pkgs_LDFLAGS} ${PROJECT_NAME}) +APPLY_PKG_CONFIG(${TARGET_TTRACE_UNIT_TEST} PUBLIC + GMOCK_DEPS +) +TARGET_LINK_LIBRARIES(${TARGET_TTRACE_UNIT_TEST} PUBLIC ${TARGET_TTRACE}) SET_TARGET_PROPERTIES(${TARGET_TTRACE_UNIT_TEST} PROPERTIES COMPILE_FLAGS "-fPIE -fvisibility=default") SET_TARGET_PROPERTIES(${TARGET_TTRACE_UNIT_TEST} PROPERTIES LINK_FLAGS "-pie") |