From af08b58d293c5c092fa78471129ef2ff8cf1875e Mon Sep 17 00:00:00 2001 From: mtdxc Date: Thu, 17 Feb 2022 10:33:42 +0800 Subject: [PATCH] =?UTF-8?q?cmake=E9=A1=B9=E7=9B=AE=E5=88=86=E7=BB=84=20(#1?= =?UTF-8?q?431)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 重要项目(toolkit和mediakit)增加目录显示 --- CMakeLists.txt | 36 ++++++++++++++++++++++++++++++++++++ api/tests/CMakeLists.txt | 3 +++ tests/CMakeLists.txt | 4 ++++ 3 files changed, 43 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4cc97e7..edd7eccf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,37 @@ option(ENABLE_WEBRTC "Enable WebRTC" true) option(ENABLE_PLAYER "Enable Player" true) option(ENABLE_MSVC_MT "Enable MSVC Mt/Mtd lib" true) option(ENABLE_API_STATIC_LIB "Enable mk_api static lib" false) +option(USE_SOLUTION_FOLDERS "Enable solution dir supported" ON) +# ---------------------------------------------------------------------------- +# Solution folders: +# ---------------------------------------------------------------------------- +if(USE_SOLUTION_FOLDERS) + set_property(GLOBAL PROPERTY USE_FOLDERS ON) + set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets") +endif() + +function(set_file_group prefix) + message(STATUS "set_file_group " ${prefix} " " ${ARGC}) + foreach(FILE IN LISTS ARGN 1) + # Get the directory of the source file + get_filename_component(PARENT_DIR "${FILE}" DIRECTORY) + + # Remove common directory prefix to make the group + string(REPLACE "${prefix}" "" GROUP "${PARENT_DIR}") + + # Make sure we are using windows slashes + string(REPLACE "/" "\\" GROUP "${GROUP}") + + # Group into "Source Files" and "Header Files" + #if ("${FILE}" MATCHES ".*\\.cpp") + # set(GROUP "Source Files${GROUP}") + #elseif("${FILE}" MATCHES ".*\\.h") + # set(GROUP "Header Files${GROUP}") + #endif() + #message(STATUS ${GROUP} " : " ${FILE}) + source_group("${GROUP}" FILES "${FILE}") + endforeach() +endfunction() if (MSVC AND ENABLE_MSVC_MT) set(CompilerFlags @@ -264,6 +295,11 @@ else () add_definitions(-DWIN32_LEAN_AND_MEAN -DMP4V2_NO_STDINT_DEFS -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS) endif () +if (USE_SOLUTION_FOLDERS AND (NOT GROUP_BY_EXPLORER)) # 在 IDE 中对文件进行分组,源文件和头文件分开 + set_file_group(${ToolKit_Root} ${ToolKit_src_list}) + set_file_group("${CMAKE_CURRENT_SOURCE_DIR}/src" ${MediaKit_src_list}) +endif() + #添加库 add_library(zltoolkit STATIC ${ToolKit_src_list}) add_library(zlmediakit STATIC ${MediaKit_src_list}) diff --git a/api/tests/CMakeLists.txt b/api/tests/CMakeLists.txt index b60eb130..eeec6129 100644 --- a/api/tests/CMakeLists.txt +++ b/api/tests/CMakeLists.txt @@ -4,6 +4,9 @@ foreach(TEST_SRC ${TEST_SRC_LIST}) message(STATUS "add c api tester:${TEST_EXE_NAME}") set(exe_name api_tester_${TEST_EXE_NAME}) add_executable(${exe_name} ${TEST_SRC}) + if(USE_SOLUTION_FOLDERS) + SET_PROPERTY(TARGET ${exe_name} PROPERTY FOLDER "api_test") + endif() if(MSVC) set_target_properties(${exe_name} PROPERTIES COMPILE_FLAGS ${VS_FALGS} ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c8cd3bfb..0fe2d458 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,6 +14,10 @@ foreach (TEST_SRC ${TEST_SRC_LIST}) message(STATUS "add test:${TEST_EXE_NAME}") add_executable(${TEST_EXE_NAME} ${TEST_SRC}) + if(USE_SOLUTION_FOLDERS) + SET_PROPERTY(TARGET ${TEST_EXE_NAME} PROPERTY FOLDER "test") + endif () + if (MSVC) set_target_properties(${TEST_EXE_NAME} PROPERTIES COMPILE_FLAGS ${VS_FALGS}) endif ()