[CMake] [SPAM] Re: [SPAM] Re: resource installation

Robert Maynard robert.maynard at kitware.com
Fri Feb 15 15:45:52 EST 2019


I believe the problem is related to execute_process CODE not being
quoted. So the following works for me:

install(CODE
"
execute_process(COMMAND
${CMAKE_CURRENT_SOURCE_DIR}/ResourceInstall.bat ${WIN_PLATFORM}
${CMAKE_BUILD_TYPE}
                RESULT_VARIABLE RI_RESULT
                OUTPUT_VARIABLE RI_OUTPUT
                ERROR_VARIABLE RI_ERROR
                OUTPUT_FILE ResInst.out
                ERROR_FILE ResInst.err
                )
"
)

The other option you have is using CMake's 3.X new bracket strings (
https://cmake.org/cmake/help/v3.4/manual/cmake-language.7.html#bracket-argument
) which stop
any CMake configure expansion. This makes it significantly easier to
pass down code strings, but you do have to remember to have a preamble
that sends down any
variables expanded that you need. So your example would look like this:


#First send down the variables you need expanded at CMake configure time
install(CODE
"
set(CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(WIN_PLATFORM ${WIN_PLATFORM})
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE})
"
)

#now send down the unexpanded commands to run
install(CODE [==[message("running
${CMAKE_CURRENT_SOURCE_DIR}/ResourceInstall.bat ${WIN_PLATFORM}
${CMAKE_BUILD_TYPE}")]==])
install(CODE
[==[
execute_process(COMMAND
${CMAKE_CURRENT_SOURCE_DIR}/ResourceInstall.bat ${WIN_PLATFORM}
${CMAKE_BUILD_TYPE}
                RESULT_VARIABLE RI_RESULT
                OUTPUT_VARIABLE RI_OUTPUT
                ERROR_VARIABLE RI_ERROR
                OUTPUT_FILE ResInst.out
                ERROR_FILE ResInst.err
                )
]==]
)

On Tue, Feb 12, 2019 at 2:12 PM Rob Boehne <robb at datalogics.com> wrote:
>
> The same behavior is also present in version 3.14.0-rc1.
>
> On 2/12/19, 11:54 AM, "CMake on behalf of Rob Boehne" <cmake-bounces at cmake.org on behalf of robb at datalogics.com> wrote:
>
>     Hmmm, I think I've found a bug.  Here is what I have in my top-level CMakeLists.txt file:
>
>
>     if(WIN32)
>         #
>         # run the script to install the resources
>         #
>         set(RI_RESULT " ")
>         set(RI_OUTPUT " ")
>         set(RI_ERROR " ")
>
>         install(CODE "message(\"running ${CMAKE_CURRENT_SOURCE_DIR}/ResourceInstall.bat ${WIN_PLATFORM} ${CMAKE_BUILD_TYPE}\")")
>
>         install(CODE execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/ResourceInstall.bat ${WIN_PLATFORM} ${CMAKE_BUILD_TYPE}
>                                      RESULT_VARIABLE RI_RESULT
>                                      OUTPUT_VARIABLE RI_OUTPUT
>                                      ERROR_VARIABLE RI_ERROR
>                                      OUTPUT_FILE ResInst.out
>                                      ERROR_FILE ResInst.err )
>                )
>
>         install(CODE "message(\"ResourceInstall results \\\"${RI_RESULT}\\\" output: \\\"${RI_OUTPUT}\\\"  error: \\\"${RI_ERROR}\\\" \")")
>
>     endif()
>
>
>     (As you can see I haven't figured out quoting yet)
>     This is what comes out of the above code:
>
>
>     if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xUnspecifiedx" OR NOT CMAKE_INSTALL_COMPONENT)
>       message("running C:/Users/robb/Development/apdfl-sandbox/pdfl15_all/ResourceInstall.bat x64 Release")
>     endif()
>
>     if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xUnspecifiedx" OR NOT CMAKE_INSTALL_COMPONENT)
>       execute_process(COMMAND "C:/Users/robb/Development/apdfl-sandbox/pdfl15_all/ResourceInstall.bat x64 Release"
>             WORKING_DIRECTORY C:/Users/robb/Development/apdfl-sandbox/pdfl15_all
>             RESULT_VARIABLE RI_RESULT
>             OUTPUT_VARIABLE RI_OUTPUT
>             ERROR_VARIABLE RI_ERROR
>             OUTPUT_FILE ResInst.out
>             ERROR_FILE ResInst.err ")
>     endif()
>
>     if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xUnspecifiedx" OR NOT CMAKE_INSTALL_COMPONENT)
>       message("ResourceInstall results  output:   error:  ")
>     endif()
>
>
>     From cmake 3.12.2 on Win64.  The issue is the closing quote inside "execute_process"  which appears to have been magically added by cmake.
>     When I run the cmake_install.cmake as is it fails on that line:
>
>
>     CMake Error at cmake_install.cmake:87:
>       Parse error.  Function missing ending ")".  Instead found unterminated
>       string with text ")
>
>       ".
>
>     If I remove that stray double quote, it runs, doing all the subdir install tasks, but still doesn't run the ResourceInstall.bat file.
>     And it generates the error:
>
>     1>  -- Installing: C:/Users/robb/Development/apdfl-sandbox/pdfl15_all/cmake_vs2013/../dist/x64/release/Resources/Sample_Input/XPStoPDF.xps
>     1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: The command "setlocal
>     1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: "C:\Program Files\CMake\bin\cmake.exe" -DBUILD_TYPE=RelWithDebInfo -P cmake_install.cmake
>     1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd
>     1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: :cmEnd
>     1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
>     1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: :cmErrorLevel
>     1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: exit /b %1
>     1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: :cmDone
>     1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd
>     1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: :VCEnd" exited with code -1.
>     1>Done executing task "Exec" -- FAILED.
>     1>Done building target "PostBuildEvent" in project "INSTALL.vcxproj" -- FAILED.
>     1>
>     1>Build FAILED.
>     1>
>     1>Time Elapsed 00:00:29.40
>     ========== Build: 0 succeeded, 1 failed, 31 up-to-date, 0 skipped ==========
>
>
>     I know the batch file does not get run because I have statements at the top that create a file before anything else, and it also sends output to stdout.
>
>     Any advice on how I can move forward here?
>
>     Thanks,
>
>     Rob Boehne
>
>
>
>     On 2/5/19, 4:09 PM, "Robert Maynard" <robert.maynard at kitware.com> wrote:
>
>         If you add 'OUTPUT_VARIABLE' and 'ERROR_VARIABLE' information to the
>         execute_process call you should be able to dump the information using
>         'message' and see if the execute_process is running.
>
>
>         On Tue, Jan 29, 2019 at 3:04 PM Rob Boehne <robb at datalogics.com> wrote:
>         >
>         > I’m still not getting this script executed.  I can copy the “message” output and run it – and it does what I want, and I see it in cmake_install.cmake – the message() and execute_process() calls are inside of identical conditionals, but there’s no indication that it is executing, or that there was any sort of problem.
>         >
>         > How do I get it to actually execute?
>         >
>         >
>         >
>         > In cmake_install.cmake:
>         >
>         >
>         >
>         > if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xUnspecifiedx" OR NOT CMAKE_INSTALL_COMPONENT)
>         >
>         >   message("running C:/Users/robb/Development/apdfl-sandbox/pdfl15_all/ResourceInstall.bat x64 Release")
>         >
>         > endif()
>         >
>         >
>         >
>         > if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xUnspecifiedx" OR NOT CMAKE_INSTALL_COMPONENT)
>         >
>         >   execute_process(COMMAND "C:/Users/robb/Development/apdfl-sandbox/pdfl15_all/ResourceInstall.bat x64 Release")
>         >
>         > endif()
>         >
>         >
>         >
>         >
>         >
>         > From: CMake <cmake-bounces at cmake.org> on behalf of Rob Boehne <robb at datalogics.com>
>         > Date: Thursday, January 24, 2019 at 9:49 AM
>         > To: "cmake at cmake.org" <cmake at cmake.org>
>         > Subject: [SPAM] Re: [CMake] resource installation
>         >
>         >
>         >
>         > Maybe because I misspelled it?  Yes.  Because I misspelled the script name.
>         >
>         >
>         >
>         > From: CMake <cmake-bounces at cmake.org> on behalf of Rob Boehne <robb at datalogics.com>
>         > Date: Thursday, January 24, 2019 at 9:40 AM
>         > To: "cmake at cmake.org" <cmake at cmake.org>
>         > Subject: [SPAM] [CMake] resource installation
>         >
>         >
>         >
>         > All,
>         >
>         >
>         >
>         > I’m attempting to install resource files (Fonts, etc.) into my product.  To that end, I have added this chunk of code to run a batch file that will copy resources into the tree:
>         >
>         >
>         >
>         > if(WIN32)
>         >
>         >     #
>         >
>         >     # run the script to install the resources
>         >
>         >     #
>         >
>         >     install(CODE "message(\"running ${CMAKE_CURRENT_SOURCE_DIR}/ResourceInstall.bat ${WIN_PLATFORM} ${CMAKE_BUILD_TYPE}\")")
>         >
>         >     install(CODE "execute_process(COMMAND \"${CMAKE_CURRENT_SOURCE_DIR}/ResourceInstall.bat ${WIN_PLATFORM} ${CMAKE_BUILD_TYPE}\")")
>         >
>         > endif()
>         >
>         >
>         >
>         > I see the output of the first line when I run the INSTALL target in VS 2013, but it seems as though the script isn’t run.
>         >
>         > 1>  -- Install configuration: "RelWithDebInfo"
>         >
>         > 1>  running C:/Users/robb/Development/apdfl-sandbox/pdfl15_all/ResourceInstall.bat x64 Release
>         >
>         > 1>  -- Installing: C:/Users/robb/Development/apdfl-sandbox/pdfl15_all/cmake_build/../dist/x64/release/CPlusPlus/Binaries/DL150BIBUtils.lib
>         >
>         >
>         >
>         > So the message is there, but the script isn’t run.
>         >
>         >
>         >
>         > I’m I missing a dependency, or formatting the string incorrectly?  How do I debug this?
>         >
>         >
>         >
>         > Thanks,
>         >
>         >
>         >
>         > Rob
>         >
>         >
>         >
>         >
>         >
>         > Rob Boehne
>         >
>         > Senior Software Architect | Datalogics, Inc.
>         >
>         > +1.312.853.8351 | robb at datalogics.com
>         >
>         > datalogics.com | blogs.datalogics.com
>         >
>         > Connect with us: Facebook | Twitter | LinkedIn | YouTube
>         >
>         >
>         >
>         >
>         >
>         > --
>         >
>         > Powered by www.kitware.com
>         >
>         > Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>         >
>         > Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>         >
>         > CMake Support: http://cmake.org/cmake/help/support.html
>         > CMake Consulting: http://cmake.org/cmake/help/consulting.html
>         > CMake Training Courses: http://cmake.org/cmake/help/training.html
>         >
>         > Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>         >
>         > Follow this link to subscribe/unsubscribe:
>         > https://cmake.org/mailman/listinfo/cmake
>
>
>     --
>
>     Powered by www.kitware.com
>
>     Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
>     Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
>     CMake Support: http://cmake.org/cmake/help/support.html
>     CMake Consulting: http://cmake.org/cmake/help/consulting.html
>     CMake Training Courses: http://cmake.org/cmake/help/training.html
>
>     Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
>     Follow this link to subscribe/unsubscribe:
>     https://cmake.org/mailman/listinfo/cmake
>
>


More information about the CMake mailing list