[CMake] does cmake scripts execute sequentially?

Craig Scott craig.scott at crascit.com
Sat Oct 28 20:19:57 EDT 2017


On Sun, Oct 29, 2017 at 10:36 AM, Carlton Banks <noflaco at gmail.com> wrote:

> I seem to have some problems executing one of my submodules cmakelist.
>
> MESSAGE(“In record CMAKELIST”)
>
> # Include externalproject {portaudio} if lib/portaudio don't exist.
> MESSAGE(“Download external project”)
>
> INCLUDE(ExternalProject)
> ExternalProject_Add(project_portaudio
>     GIT_REPOSITORY      https://git.assembla.com/portaudio.git
>     PREFIX              lib/portaudio
>     CONFIGURE_COMMAND   <SOURCE_DIR>/configure
>     BUILD_IN_SOURCE     1
>     BUILD_COMMAND       make
>     INSTALL_COMMAND     sudo make install
> )
> ExternalProject_Get_Property(project_portaudio BINARY_DIR)
> ExternalProject_Get_Property(project_portaudio SOURCE_DIR)
>
> SET(portaudio_lib_dir "${BINARY_DIR}/lib/.libs")
> SET(portaudio_inc_dir "${SOURCE_DIR}/include")
>
> add_library(record STATIC record.cpp record.h)
> add_library(libaudio libportaudio.a PATHS ${portaudio_lib_dir})
>

What is this second add_library() command intended to do? I'm guessing you
probably instead want to be doing something like this (untested, but
hopefully in the ballpark):

add_library(portaudio STATIC IMPORTED)
set_target_properties(portaudio PROPERTIES
    IMPORTED_LOCATION ${BINARY_DIR}/lib/.libs/libportaudio.a
)
target_include_directories(portaudio INTERFACE
    ${SOURCE_DIR}/include
)

add_dependencies(portaudio project_portaudio)     # Not sure if this is
allowed for imported targets though


I don't recall off the top of my head whether STATIC IMPORTED or INTERFACE
IMPORTED would be the right way to call add_library() in the above, so try
the latter if the former doesn't work for you.



>
>
> #
> # this makes sure we have compiler flags that allow class::class() =
> default (>= C++11)
> target_compile_features(record PUBLIC cxx_defaulted_functions)
>
>
>
>
> target_include_directories(record PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
> ${project_portaudio})
>

You won't need this if you define the portaudio imported library as per my
example above.



>
>
> It cannot find libportaudio.a as externalproject_add() is not being
> executed, the command it executes add_library, which fails as the project
> has not been downloaded…
>
>
> what is wrong here?
>

The reason for this specific problem is that there's no dependency
relationship between the project_portaudio target defined by the
ExternalProject_Add() call and the record target. Such a relationship is
only created through a suitable call to target_link_libraries() or
add_dependencies(), or through arguments like DEPENDS for commands that
offer such features (e.g. add_custom_target() and add_custom_command()).


-- 
Craig Scott
Melbourne, Australia
https://crascit.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20171029/9a66184d/attachment.html>


More information about the CMake mailing list