[CMake] INSTALL CODE using EXEC_PROGRAM with spaces in path

Urbach, Marcel [Rohmann GmbH] urbach at rohmann.de
Tue Mar 15 05:11:59 EDT 2011


Hi David

Your solution works fine, but i still got the problem with execute_process.
Right now I use it this way:

#cmakelists.txt
ADD_LIBRARY(${project_name} SHARED ${sources} ${headers} ${idls} ${generated} ${resources}  )
SET(project_out "${INSTALL_LIB_DIR}/${project_name}_d.dll")
STRING(REGEX REPLACE "/" "\\\\\\\\" project_out ${project_out} )
register_shared_libraries(${project_name} "${project_out}" )

#global.cmake
FUNCTION(register_shared_libraries)
    IF (WIN32)
        SET(param1 ${ARGV0})
        SET(param2 ${ARGV1})
        CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/post_install.cmake.in
            ${CMAKE_CURRENT_BINARY_DIR}/post_install.cmake @ONLY
            )
        INSTALL(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/post_install.cmake")
    ENDIF()
ENDFUNCTION()

#post_install.cmake.in
SET(file_name "@param2@")
MESSAGE(STATUS "file_name: ${file_name}")
EXEC_PROGRAM( regsvr32 
              ARGS \"/s\" 
              ARGS \"${file_name}\" 
              OUTPUT_VARIABLE ov RETURN_VALUE rv )

MESSAGE("out ${ov}")
MESSAGE("res ${rv}")

SET(project_name "@param1@")
MESSAGE(STATUS "project_name: ${project_name}")
EXECUTE_PROCESS(COMMAND regsvr32 #$<TARGET_FILE:${project_name}> 
    INPUT_FILE $<TARGET_FILE_NAME:${project_name}>
    WORKING_DIRECTORY $<TARGET_FILE_DIR:${project_name}>
    OUTPUT_VARIABLE ov RESULT_VARIABLE rv
)
MESSAGE("out ${ov}")
MESSAGE("res ${rv}")


The first version using EXEC_PROGRAM works fine, but there is a problem resolving the target name. XXX.dll for release or XXX_d.for debug.
The second (EXECUTE_PROCESS) never returns from regsvr32 when using regsvr32 #$<TARGET_FILE:${project_name}> or it says wrong syntax for file name or dir name when using regsvr32 INPUT_FILE $<TARGET_FILE_NAME:${project_name}> WORKING_DIRECTORY $<TARGET_FILE_DIR:${project_name}>





-----Ursprüngliche Nachricht-----
Von: David Cole [mailto:david.cole at kitware.com] 
Gesendet: Montag, 14. März 2011 17:17
An: Urbach, Marcel [Rohmann GmbH]
Cc: cmake at cmake.org
Betreff: Re: [CMake] INSTALL CODE using EXEC_PROGRAM with spaces in path

On Mon, Mar 14, 2011 at 11:17 AM, Urbach, Marcel [Rohmann GmbH]
<urbach at rohmann.de> wrote:
> I have already tried to use the SCRIPT. But there is a problem to submit the name of the dll or the project name to the extern script. I need something like a  parameter and I guess that doesn't exsist. Do you have any ideas to solve this?
> INSTALL(SCRIPT "PostInst.cmake" PARAMETeR...)
>

How about something like this?

  # File "script.cmake.in"
  set(p1 "@param1@")
  execute_process(COMMAND xyz ${p1} OUTPUT_VARIABLE ov RESULT_VARIABLE rv)
  if(NOT rv STREQUAL "0")
    message(FATAL_ERROR "xyz failed: rv='${rv}'")
  endif()

And then:

  # in CMakeLists.txt
  set(param1 "value-of-p1")
  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/script.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/script.cmake @ONLY)
  install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/script.cmake")


I have written code in the past which calls regsvr32 successfully.
What are the arguments you are passing that are causing problems? Can
you call the same regsvr32 from the Windows command prompt
successfully? Are you using the same regsvr32 in both scenarios?


> I also tried to use execute_process, but it didn't work with regsvr32.
> It ended in an endless loop. Only a timeout could break it. Can you confirm that?
>
> -----Ursprüngliche Nachricht-----
> Von: David Cole [mailto:david.cole at kitware.com]
> Gesendet: Freitag, 11. März 2011 16:50
> An: Tyler
> Cc: Urbach, Marcel [Rohmann GmbH]; cmake at cmake.org
> Betreff: Re: [CMake] INSTALL CODE using EXEC_PROGRAM with spaces in path
>
> Tyler's right. Use install(SCRIPT instead.
>
> And use execute_process instead of exec_program. It's better.
>
> From the help at
> http://cmake.org/cmake/help/cmake-2-8-docs.html#command:execute_process
> :
> "The execute_process command is a newer more powerful version of
> exec_program, but the old command has been kept for compatibility."
>
>
> On Fri, Mar 11, 2011 at 10:34 AM, Tyler <tyler at cryptio.net> wrote:
>> I believe the canonical answer is to write the command line you wish
>> to execute into a file and use install(SCRIPT ...) instead of
>> install(CODE ...).
>>
>> tyler
>>
>> On Fri, Mar 11, 2011 at 7:14 AM, Urbach, Marcel [Rohmann GmbH]
>> <urbach at rohmann.de> wrote:
>>> Hi,
>>>
>>> I am using Windows 7 and I have tried to register my builded dll files with
>>> regsvr32 after installing them. It works for paths without spaces.
>>>
>>>
>>>
>>> INSTALL( CODE
>>>
>>>     "EXEC_PROGRAM( regsvr32 ARGS \"/s\" ARGS \"C:\\lib\\test.dll\"
>>> OUTPUT_VARIABLE POST_INST_OUT RETURN_VALUE POST_INST_RES )"
>>>
>>> )
>>>
>>>
>>>
>>> But when there a spaces inside a path regsvr32 returns with an error:
>>>
>>> "Error loading module "C:\Program".
>>>
>>>
>>>
>>> INSTALL( CODE
>>>
>>>     "EXEC_PROGRAM( regsvr32 ARGS \"/s\" ARGS \"C:\\Program
>>> Files\\test\\lib\\test.dll\" OUTPUT_VARIABLE POST_INST_OUT RETURN_VALUE
>>> POST_INST_RES )"
>>>
>>> )
>>>
>>>
>>>
>>> I have spended the whole day  escaping the path in the right way but I don't
>>> get it.
>>>
>>>
>>>
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the CMake FAQ at:
>>> http://www.cmake.org/Wiki/CMake_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.cmake.org/mailman/listinfo/cmake
>>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>


More information about the CMake mailing list