我在访问分层组织的每个目录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发布了所有内容。
我只能使用安装在有空格的目录中的便携式应用程序(sic!)。
项目的组织方式如下:
/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
当我查看使用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++
。
如果有人可以帮我提供线索,那就太好了。
感谢阅读。