CMake command mode help (cmake -E env) (Edit: fixed error on concatenation)

Hello, everyone!

I’m trying to set up an external project. In the CONFIGURE_COMMAND phase I’m trying to use a modified environment as folows:

find_program(nasm NAMES nasm REQUIRED)
find_program(perl NAMES perl REQUIRED)

get_filename_component(nasm_dir ${nasm} DIRECTORY)
set(DIR_LIST $ENV{PATH})
list(APPEND DIR_LIST ${nasm_dir})
list(JOIN DIR_LIST "\;" ALL_PATH)
message(${ALL_PATH})

include(ExternalProject)

ExternalProject_Add(
    openssl_external
    GIT_REPOSITORY https://github.com/openssl/openssl.git
    GIT_TAG openssl-3.0.3

    CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env PATH="${ALL_PATH}" ${perl} ${CMAKE_BINARY_DIR}/openssl_external-prefix/src/openssl_external/Configure
    BUILD_COMMAND ""
    INSTALL_COMMAND ""
)

Configure step runs smoothly, but at build time CMake returns an error:

Microsoft (R) Build Engine version 17.2.1+52cd2da31 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

  Performing update step for 'openssl_external'
  No patch step for 'openssl_external'
  Performing configure step for 'openssl_external'
  Access is denied
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(245,5): error MSB8066: Custom build for 'E:\Projetos\openssl_cmake\build\CMakeFiles\5
a0dbcb60aa1c22791074824c5fb1c3f\openssl_external-update.rule;E:\Projetos\openssl_cmake\build\CMakeFiles\5a0dbcb60aa1c22791074824c5fb1c3f\openssl_external-patch.rule;E:\Projetos\openssl_cmake\buil 
d\CMakeFiles\5a0dbcb60aa1c22791074824c5fb1c3f\openssl_external-configure.rule;E:\Projetos\openssl_cmake\build\CMakeFiles\5a0dbcb60aa1c22791074824c5fb1c3f\openssl_external-build.rule;E:\Projetos\o 
penssl_cmake\build\CMakeFiles\5a0dbcb60aa1c22791074824c5fb1c3f\openssl_external-install.rule;E:\Projetos\openssl_cmake\build\CMakeFiles\8d46eee9464cb01489224e25d28f93e1\openssl_external-complete. 
rule;E:\Projetos\openssl_cmake\build\CMakeFiles\45483d5c0e89724af3f38f97f3dbb2ab\openssl_external.rule' exited with code 1. [E:\Projetos\openssl_cmake\build\openssl_external.vcxproj]

When I use only one path it works. How can I add paths to the system PATH variable without overwriting everything?

I think you want "PATH=${ALL_PATH}" rather than PATH="${ALL_PATH}". CMake doesn’t handle quotes within a string the same way as unix shells. In CMake, you must surround the whole thing with quotes for it to do what you intended here.

Regarding the list separators, don’t try to escape them. If you do the quoting as suggested above, CMake should take care of that for you. Note also that the PATH environment variable uses ; as a separator on Windows, but : on other platforms. You may want to use cmake_path(CONVERT ... TO_NATIVE_PATH_LIST) to get the path value in the right form for the platform.

Hello, @craig.scott

Sorry for the late reply. I’ll try your suggestions and bring feedback soon. Thanks!

So I managed to get it working after your suggestions! Many thanks!