2

I'm encountering a path problem when going to a per directory CMakeList.txt to a hierarchical organization.

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

I launch everything from git-bash.

I can only use portable apps installed in a directory that has spaces (sic!).

The project is organized like this:

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

It works fine when I run cmake -G "Unix Makefiles" .. in the app/build sub-dir using this CMakeLists.txt file:

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()

But, when I try to make my build system hierarchical and create a very simple CMakeLists.txt in the parent directory:

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)

set(CMAKE_RC_COMPILER windres)

project(myproject VERSION 0.1 LANGUAGES CXX)

add_subdirectory(modplayer)

It fails compiling the resource file:

[ 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

When I look at how processes are called using make --debug=j, there're big differences between the one that works and the one that fail.

The one that fails:

[ 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

The one that works:

[ 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.

The CreateProcess called to compile the resource file using windres are totally different.

I don't understand why it fails just for windres whereas it works for g++.

If one could help to give me clues where to look at, it would be nice.

Thanks for reading.

  • 1
    Welcome to Stack Overflow! Here we expect code to be **in the question post** itself, not linked. Also, main language of Stack Overflow is English, so we want to see error messages on this language. (You may post build logs in your native language, but add translation of error messages into English). Please, [edit] your question post and fix these issues. – Tsyvarev Mar 11 '18 at 13:00
  • Try putting all your `${CMAKE_SOURCE_DIR}`, `${CMAKE_BINARY_DIR}` and `${CMAKE_COMMAND}` between quotes. The problem seems to be the spaces in "Mes Outils Personnels". – oLen Mar 11 '18 at 18:58
  • @Tsyvarev: post edited as required – Pierre-Jean Turpeau Mar 11 '18 at 21:48
  • Looks like CMake bug or limitation for me. @oLen: I guess neither `debug` not `release` targets are not called, so quotes in *COMMAND*s for that targets are unrelated. (But it would be a good idea to remove whole unrelated code from the question post). – Tsyvarev Mar 11 '18 at 22:45
  • @Tsyvarev: you're right, targets removed – Pierre-Jean Turpeau Mar 12 '18 at 12:13

0 Answers0