2

在将每个目录 CMakeList.txt 转到分层组织时,我遇到了路径问题。

Platform: windows 7  
Cmake portable : cmake-3.10.2-win64-x64  
git-bash in Git : PortableGit-2.16.1.3-64-bit  
MinGW : the one shipped with codeblocks-17.12mingw-nosetup  
make --version: 3.81  
mingw32-make --version: 3.82.90

我从 git-bash 启动一切。

我只能使用安装在有空格的目录中的便携式应用程序(原文如此!)。

该项目是这样组织的:

/demos-cpp
     build/
     CMakeList.txt
     [...]
     modplayer/
          build/
          CMakeLists.txt
          [...]

当我使用此 CMakeLists.txt 文件cmake -G "Unix Makefiles" ..在子目录中运行时,它工作正常:app/build

cmake_minimum_required(VERSION 3.0)

set(CMAKE_RC_COMPILER windres)

project(pj-modplayer VERSION 1.0 LANGUAGES CXX)

set(SOURCES
    main.cc
    ModLoader.cc
    ../common/ByteReader.cc
    ../common/ChunkyMode.cc
    )   

set(HEADERS
    protracker.hh
    ModLoader.hh
    )

if(WIN32)
    set(RESOURCES resources.rc)
endif()

math( EXPR BITS "8*${CMAKE_SIZEOF_VOID_P}" )
set( EXECUTABLE_NAME ${PROJECT_NAME}-x${BITS} )

link_directories( $ENV{SDL2_PATH}/lib )

# The executable file will be generate in the bin/ directory
#set(EXECUTABLE_OUTPUT_PATH bin/)

add_executable( ${EXECUTABLE_NAME} ${SOURCES} ${HEADERS} ${RESOURCES} )

target_compile_features( ${EXECUTABLE_NAME} PRIVATE cxx_std_11 )

target_include_directories( ${EXECUTABLE_NAME}
    PUBLIC $ENV{SDL2_PATH}/include ../common
    )

target_compile_definitions( ${EXECUTABLE_NAME}
    PUBLIC WIN32
        )
if(CMAKE_COMPILER_IS_GNUCXX)
    target_compile_options( ${EXECUTABLE_NAME}
        PUBLIC -fexceptions
        PUBLIC -Wall
    )
endif()

if(WIN32)
    target_link_libraries(
        ${EXECUTABLE_NAME}
        mingw32         # remove to get back to non terminal app with a WinMain
        ws2_32
        SDL2main
        SDL2
    )
else()
    target_link_libraries(
        ${EXECUTABLE_NAME}
        SDL2main
        SDL2
    )
endif()

但是,当我尝试使构建系统分层并在父目录中创建一个非常简单的 CMakeLists.txt 时:

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)

set(CMAKE_RC_COMPILER windres)

project(myproject VERSION 0.1 LANGUAGES CXX)

add_subdirectory(modplayer)

编译资源文件失败:

[ 83%] Building RC object modplayer/CMakeFiles/pj-modplayer-x32.dir/resources.rc.obj
'D:\Users\XXXXXX\Documents\Mes' not recognized as an internal or external command operable program or batch file.
D:\Users\XXXXXX\Documents\Mes Outils Personnels\apps\MinGW\bin\windres.exe: preprocessing failed.
make[2]: *** [modplayer/CMakeFiles/pj-modplayer-x32.dir/resources.rc.obj] Error 1
make[1]: *** [modplayer/CMakeFiles/pj-modplayer-x32.dir/all] Error 2
make: *** [all] Error 2

当我查看如何使用 using 调用流程时,make --debug=j有效的流程和失败的流程之间存在很大差异。

失败的那个:

[ 16%] Building RC object modplayer/CMakeFiles/pj-modplayer-x32.dir/resources.rc.obj  
Reaping winning child 0x01d916b8 PID 30998520  
CreateProcess(NULL,D:/Users/XXXXX/Documents/Mes Outils Personnels/apps/PortableGit/usr/bin/sh.exe -c "cd D:/Users/XXXXX/Documents/DEV/demos-cpp/build/modplayer && windres -O coff -DWIN32 -ID:/Users/XXXXX/Documents/DEV/SDL2-2.0.7/i686-w64-mingw32/include -ID:/Users/XXXXX/Documents/DEV/demos-cpp/modplayer/../common D:/Users/XXXXX/Documents/DEV/demos-cpp/modplayer/resources.rc CMakeFiles/pj-modplayer-x32.dir/resources.rc.obj",...)  
Live child 0x01d916b8 (modplayer/CMakeFiles/pj-modplayer-x32.dir/resources.rc.obj) PID 30998520

一个有效的:

[ 16%] Building RC object CMakeFiles/pj-modplayer-x32.dir/resources.rc.obj Reaping winning child 0x00461770 PID 4586800
CreateProcess(D:\Users\XXXXX\Documents\Mes Outils Personnels\apps\MinG \bin\windres.exe,windres -O coff -DWIN32 -ID:/Users/XXXXX/Documents/DEV/SDL2-2.0.7/i686-w64-mingw32/include -ID:/Users/XXXXX/Documents/DEV/demos-cpp/modplayer/../common D:/Users/XXXXX/Documents/DEV/demos-cpp/modplayer/resources.rc CMakeFiles/pj-modplayer-x32.dir/resources.rc.obj,...)
Live child 0x00461770 (CMakeFiles/pj-modplayer-x32.dir/resources.rc.obj) PID 4586800
Reaping winning child 0x00461770 PID 4586800
Removing child 0x00461770 PID 4586800 from chain.

用于编译资源文件的CreateProcess调用windres是完全不同的。

我不明白为什么它失败只是因为windres它适用于g++.

如果有人可以帮助我提供在哪里看的线索,那就太好了。

谢谢阅读。

4

0 回答 0