Cmake build order with external projects

How do I enforce the build order, to say if your going to include SDL files
make sure that external projects are built first?

This is my current script

include(ExternalProject)
ExternalProject_Add(sdl
HG_REPOSITORY http://hg.libsdl.org/SDL
UPDATE_COMMAND hg pull -u http://hg.libsdl.org/SDL

PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/SDL2

CMAKE_ARGS -DSDL_STATIC:BOOL=FALSE
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}

)

ExternalProject_Add(sdl_image
DEPENDS sdl
PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/SDL_image

HG_REPOSITORY http://hg.libsdl.org/SDL_image
UPDATE_COMMAND hg pull -u http://hg.libsdl.org/SDL_image
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/SDL_image/src/sdl_image/./autogen.sh


CONFIGURE_COMMAND

${CMAKE_CURRENT_SOURCE_DIR}/SDL_image/src/sdl_image/./configure
–prefix=${CMAKE_BINARY_DIR}

)

I wrote this and it build everything correctly in my other projects I am
able to link against it like this:

//this call in the main project
SET(SDL_INCLUDE_DIR ${CMAKE_BINARY_DIR}/include/SDL2)
SET(SDL_LIB_DIR ${CMAKE_BINARY_DIR}/lib)

//this call in any projects that needs to
INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
SET(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/headers/res_utils.h)
SET(SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/res_utils.c)

IF(CMAKE_C_COMPILER_ID STREQUAL “GNU”)
SET(CMAKE_C_FLAGS “-fPIC ${CMAKE_C_FLAGS}”)
ENDIF()

ADD_LIBRARY(res_utils SHARED ${SRC_FILES} ${HEADER_FILES})
TARGET_LINK_LIBRARIES(res_utils ${TARGET_LIBS})
TARGET_INCLUDE_DIRECTORIES(res_utils PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/headers)

That was working fine until I removed my build tree. Then I realized that
the order that these things are built in, also cmake doesn’t know what I am
building when so it doesn’t really know how that there will be nothing
inside the SDL_LIB or SDL_INCLUDE dirs.

So, how do I make sure the project has the proper build order, to say if
your going to include SDL files make sure that external projects are built
first?

This seems like a really complicated issue, checking cmake mailing list,
stackoverflow and googling and ending up on tons of forums, it seems that
doing something as defining that these external projects should be built
after the internal projects or at least adding dependencies is a real mess
and requires hacking config or findpackages.

There’s no standard way of implementing this with cmake?On Wed, Dec 16, 2015 at 5:26 PM, Owen Hogarth II <@Owen_Alanzo_Hogarth> wrote:

How do I enforce the build order, to say if your going to include SDL
files make sure that external projects are built first?

This is my current script

include(ExternalProject)
ExternalProject_Add(sdl
HG_REPOSITORY http://hg.libsdl.org/SDL
UPDATE_COMMAND hg pull -u http://hg.libsdl.org/SDL

PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/SDL2

CMAKE_ARGS -DSDL_STATIC:BOOL=FALSE
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}

)

ExternalProject_Add(sdl_image
DEPENDS sdl
PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/SDL_image

HG_REPOSITORY http://hg.libsdl.org/SDL_image
UPDATE_COMMAND hg pull -u http://hg.libsdl.org/SDL_image
COMMAND

${CMAKE_CURRENT_SOURCE_DIR}/SDL_image/src/sdl_image/./autogen.sh

CONFIGURE_COMMAND

${CMAKE_CURRENT_SOURCE_DIR}/SDL_image/src/sdl_image/./configure
–prefix=${CMAKE_BINARY_DIR}

)

I wrote this and it build everything correctly in my other projects I am
able to link against it like this:

//this call in the main project
SET(SDL_INCLUDE_DIR ${CMAKE_BINARY_DIR}/include/SDL2)
SET(SDL_LIB_DIR ${CMAKE_BINARY_DIR}/lib)

//this call in any projects that needs to
INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
SET(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/headers/res_utils.h)
SET(SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/res_utils.c)

IF(CMAKE_C_COMPILER_ID STREQUAL “GNU”)
SET(CMAKE_C_FLAGS “-fPIC ${CMAKE_C_FLAGS}”)
ENDIF()

ADD_LIBRARY(res_utils SHARED ${SRC_FILES} ${HEADER_FILES})
TARGET_LINK_LIBRARIES(res_utils ${TARGET_LIBS})
TARGET_INCLUDE_DIRECTORIES(res_utils PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/headers)

That was working fine until I removed my build tree. Then I realized that
the order that these things are built in, also cmake doesn’t know what I am
building when so it doesn’t really know how that there will be nothing
inside the SDL_LIB or SDL_INCLUDE dirs.

So, how do I make sure the project has the proper build order, to say if
your going to include SDL files make sure that external projects are built
first?