在 CMake 项目中使用 Taglib 库,同时保持跨平台

问题描述

我第一次尝试使用 CMake,方法是使用 Taglib 库 (https://github.com/taglib/taglib) 创建跨平台项目(Windows 和 Linux,但不是 macOS)。

我现在的问题是当我使用“make”软件构建应用程序时收到“没有这样的文件或目录”错误。这是因为 Taglib 头文件的路径不是由 -I 选项指定给编译器的。如何使用 Taglib 项目中的 CMake 文件中的信息与其标头(使用 -I 选项)进行编译。

另外,如果你们中的一些人能给我一些关于如何在 CMake 项目中添加 Taglib 库以使其跨平台的提示,我将不胜感激。

再次感谢,我很认真!

项目树结构

    ProjectName/
        |-- Preload.cmake
        |-- CMakeLists.txt
        |-- main.cpp
        |-- taglib/ (This folder is a submodule to my repository. This repository can be found here: 
                     https://github.com/taglib/taglib)

项目名称/Preload.cmake

    if(UNIX AND NOT APPLE)
        set (CMAKE_GENERATOR "Unix Makefiles" CACHE INTERNAL "" FORCE)
    endif()
    if(WIN32)
        set (CMAKE_GENERATOR "MinGW Makefiles" CACHE INTERNAL "" FORCE)
    endif()

项目名称/CMakeLists.txt

    cmake_minimum_required(VERSION 3.10)
    project(ProjectName)
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_required True)
    
    add_subdirectory(taglib)
        
    # Here I should include the directories of Taglib.
    
    # I am not sure aobut this but I am guessing that it is here that I should
    # set some CMake configuration variable or some C++ Pre-compiler deFinition.
    # Here is the installation note (https://github.com/taglib/taglib/blob/master/INSTALL.md).

    add_executable(${CMAKE_PROJECT_NAME} main.cpp)

    target_link_libraries(${CMAKE_PROJECT_NAME} tag)

项目名称/main.cpp

    // Some Taglib included headers
    #include <mpegfile.h>
    #include ...
    #include ...

    int main(int argc,char* argv[]) {
        // Some code using the taglib library
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)