# 插件系统

## 配置规则

<figure><img src="https://1433329390-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGUKK6YnYBR07zaFrfU1O%2Fuploads%2FWoUtwdlvdzIAOwoFKcnF%2Fimage.png?alt=media&#x26;token=75066e86-731b-42d4-b5d3-2b297da87809" alt=""><figcaption><p>HEngine\Engine\Config\Plugins.json</p></figcaption></figure>

cmake会读这个json，然后link到对应为true的目标上。这个json没有的插件就不会被link，也不会被 add\_subdirectory。

<figure><img src="https://1433329390-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGUKK6YnYBR07zaFrfU1O%2Fuploads%2Fx0W2j4CzDPilYwrNUKTI%2Fimage.png?alt=media&#x26;token=5019ddc0-7c07-45a7-85eb-5cca6d64d005" alt=""><figcaption><p>HEngine\Engine\Source\Plugins\CMakeLists.txt</p></figcaption></figure>

\\

<figure><img src="https://1433329390-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGUKK6YnYBR07zaFrfU1O%2Fuploads%2FlwUV2NYtl2q8CoFMPVgH%2Fimage.png?alt=media&#x26;token=49a5b96b-bf23-4f5f-8c7e-dcdd750ae154" alt=""><figcaption><p>HEngine\Engine\Source\CMakeLists.txt</p></figcaption></figure>

## 自动检测文件夹名

<https://stackoverflow.com/questions/7787823/cmake-how-to-get-the-name-of-all-subdirectories-of-a-directory>

```cmake

MACRO(SUBDIRLIST result curdir)
    FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
    SET(dirlist "")
    FOREACH(child ${children})
        IF(IS_DIRECTORY ${curdir}/${child})
            LIST(APPEND dirlist ${child})
        ENDIF()
    ENDFOREACH()
    SET(${result} ${dirlist})
ENDMACRO()

SUBDIRLIST(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR})

FOREACH(subdir ${SUBDIRS})
    message(${subdir})
    # ADD_SUBDIRECTORY(${subdir})
ENDFOREACH()
```

\\
