Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake: Add custom command to ExternalProject_Add()

Tags:

cmake

I am building an external project but want to change some files before calling configure on it. This is my current CMakeLists.txt:

ExternalProject_Add(
    foo
    URL ${PROJECT_SOURCE_DIR}/ext/foo.tar.gz
    BUILD_IN_SOURCE 1
    #Need copyFromOthers to run here, before configure but after untar
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ""
    INSTALL_COMMAND ""
)

ExternalProject_Add_Step(){
    foo copyFromOthers
    ExternalProject_Get_Property(foo INSTALL_DIR)
    file (COPY <src>/foo_v1.c DESTINATION ${INSTALL_DIR}/foo_v1.c)
    file (COPY <src>/foo_v2.c DESTINATION ${INSTALL_DIR}/foo_v2.c)
##....Continues till foo_v10.c
}

Is there a way to call a custom step after URL command in ExternalProject_Add()?

I tried to add copyFromOthers as a DEPENDEES for ExternalProject_Add() but it kept giving me error about ExternalProject_Get_Property(foo INSTALL_DIR)

like image 589
Kish Avatar asked Dec 11 '25 22:12

Kish


1 Answers

You may use STEP_TARGETS parameter like this

ExternalProject_Add(
    foo
    URL ${PROJECT_SOURCE_DIR}/ext/foo.tar.gz
    BUILD_IN_SOURCE 1
    #Need copyFromOthers to run here, before configure but after untar
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ""
    INSTALL_COMMAND ""
    STEP_TARGETS download
)

Then you may use target "foo-download" in other ExternalProject_Add commands with DEPENDS parameter:

ExternalProject_Add (<some_target_name>
        <...>
        DEPENDS foo-download
        )

For example you could build external project which depends from other external projects. It is impossible to use dependencies like "foo-download" to build targets, defined with commands like add_executable or add_library, but you could use "ordinal" targets defined by ExternalProject_Add (for example, "foo") in such commands:

add_dependencies (some_target foo)

Also you could use ExternalProject_Add_Step commands to add steps to targets defined with ExternalProject_Add. See ExternalProject for more details

like image 75
Boris Uskov Avatar answered Dec 14 '25 09:12

Boris Uskov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!