Set WORKING_DIRECTORY for ExternalProject_Add CONFIGURE_COMMAND
Asked Answered
C

1

8

I'm trying to add an Automake project as an external project. The Automake configure script (usually run with ./configure) contains a relative path to a resource file. The file is found when I run configure manually, because my working directory is in the source directory. However, when I run configure with the ExternalProject_Add, it can't find the resource file because the working directory is CMAKE_CURRENT_BINARY_DIR.

ExternalProject_Add(zlib
        SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
        CONFIGURE_COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/configure
        BUILD_COMMAND make)

How can I set the working directory for the configuration step so that the config script finds the required files?

Chifforobe answered 16/4, 2018 at 17:24 Comment(0)
N
13

In ExternalProject_Add configuration step is performed with build directory (BINARY_DIR option) being current, so you may set this option:

ExternalProject_Add(...
    BINARY_DIR <dir>
    ...
)

For in-source builds (when build directory is the same as source directory), BUILD_IN_SOURCE option could be used as alternative to set BINARY_DIR option:

ExternalProject_Add(...
    BUILD_IN_SOURCE 1
    ...
)

More info see at ExternalProject documentation page.

Nonunionism answered 16/4, 2018 at 17:59 Comment(1)
Thanks for the answer, @Tsyvarev. I ended up using the BUILD_IN_SOURCE option. I was expecting the files to be copied into the build directory, instead of a subdirectory.Chifforobe

© 2022 - 2024 — McMap. All rights reserved.