[CMake] does cmake scripts execute sequentially?

Craig Scott craig.scott at crascit.com
Sat Oct 28 21:15:15 EDT 2017


On Sun, Oct 29, 2017 at 12:06 PM, J Decker <d3ck0r at gmail.com> wrote:

> I recently added externaproject_add() to download a library, but since it
> doesn't do the download until build, I had to put a conditional around the
> second part of the cmake that used the libraries it produced so it would do
> a cmake configure/generate, cmake build, cmake configure/generate and a
> final build and all was good...
>
> https://github.com/d3x0r/sack.vfs/blob/master/CMakeLists.gui.txt#L61
>
> but I coudln't reference any directories that didn't exist yet in
> include_directories, or link_directories...until the project had been at
> least partially built.
>

For the "directory must exist" problem, using file(MAKE_DIRECTORY) to force
it to exist first is sometimes a viable workaround.




>
> On Sat, Oct 28, 2017 at 6:00 PM, Craig Scott <craig.scott at crascit.com>
> wrote:
>
>> Ah, sorry. This particular problem has been fixed
>> <https://gitlab.kitware.com/cmake/cmake/merge_requests/1264> on CMake
>> master, but it won't be in the 3.10 release (in release candidate stage),
>> so that isn't going to help you right now. Possibly you might be able to
>> modify the relevant target property directly rather than using
>> target_include_directories() - again this is untested, but worth a try:
>>
>> set_property(TARGET portaudio APPEND PROPERTY
>>     INTERFACE_INCLUDE_DIRECTORIES ${SOURCE_DIR}/include
>> )
>>
>>
>> If that doesn't work, then I guess modifying your original method to use
>> the correct path may be an alternative workaround:
>>
>> target_include_directories(record PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${
>> SOURCE_DIR}/include)
>>
>>
>>
>>
>>
>> On Sun, Oct 29, 2017 at 11:47 AM, Carlton Banks <noflaco at gmail.com>
>> wrote:
>>
>>>
>>> Den 29. okt. 2017 kl. 02.29 skrev Craig Scott <craig.scott at crascit.com>:
>>>
>>>
>>>
>>> On Sun, Oct 29, 2017 at 11:26 AM, Carlton Banks <noflaco at gmail.com>
>>> wrote:
>>>
>>>> CMake Error at src/include/record/CMakeLists.txt:28
>>>> (target_include_directories):
>>>>   Cannot specify include directories for imported target "portaudio".
>>>>
>>>>
>>>> is the problem that externalProject_add only is executed when make is
>>>> executed and not when cmake is executed’?
>>>> what is `portaudio` here referring to?
>>>>
>>>
>>> The name "portaudio" is the target defined by the add_library() call in
>>> my example (the imported target that represents what the
>>> ExternalProject_Add() is going to create at build time).
>>>
>>> ok.
>>>
>>> Did you also try the INTERFACE IMPORTED alternative?
>>>
>>> Still the same..
>>>
>>> It would be more useful if you showed the full CMakeLists.txt rather
>>> than just the error message.
>>>
>>>
>>> The submodule cmakelist:
>>>
>>> https://pastebin.com/x2WNhK56
>>>
>>> tree structure
>>>
>>> https://pastebin.com/xhPNCkN2
>>>
>>> The outer cmakelist includes the inner directories.
>>>
>>>
>>>
>>>
>>>> Den 29. okt. 2017 kl. 02.19 skrev Craig Scott <craig.scott at crascit.com
>>>> >:
>>>>
>>>>
>>>>
>>>> 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/f4eed2ff/attachment.html>


More information about the CMake mailing list