Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does ExternalProject_Add build?

I want to build openssl and link my project against it. In my project, I have a library called net which is the part that uses openssl. So in my net\CMakeList, I added

include_directories(
    ../
  + ../../../ext/openssl/inc32/
)
add_library(net STATIC ${sources})
+ ADD_DEPENDENCIES(net openssl)

In my ext folder that is used for organizing all external library, I have a fresh unzipped openssl source code in a folder named openssl. Then I edited ext\CmakeList

message(STATUS "Configuring OpenSSL")
set(openssl_dir openssl)
if (CMAKE_CL_64)
include(ExternalProject)

set(OPENSSL_CONFIGURE perl\ Configure\ VC-WIN64A)
set(OPENSSL_MAKE  ms\\do_win64a\ &&\ nmake\ -f\ ms\\ntdll.mak)

ExternalProject_Add(openssl
    PREFIX openssl
    #-- Download Step ----------
    SOURCE_DIR ${CMAKE_SOURCE_DIR}/ext/openssl
    #--Configure step ----------
        CONFIGURE_COMMAND ${OPENSSL_CONFIGURE}
    #--Build Step ----------
    BUILD_COMMAND ${OPENSSL_MAKE}
    BUILD_IN_SOURCE 1
    #--install Step ----------
    INSTALL_COMMAND ""} 
)

endif()

When I built, the compiler complained the it can't find include files, and the openssl source code was not built at all, since there is no out32dll and inc32.

My question is: When does ExternalProject_Add actually build the project? If I make my net library depending on openssl, does it mean when I build net it would need to check and build openssl first?

like image 201
Jerry Avatar asked Jul 01 '14 11:07

Jerry


1 Answers

ExternalProject use add_custom_target internally to create project and according to its document

By default nothing depends on the custom target. Use ADD_DEPENDENCIES to add dependencies to or from other targets.

So if no project depend on it, it will not build by default.

  1. When this ExternalProject_Add actually builds the project?

    At build time(not at cmake time).

  2. If I make my net library depends on openssl, does it mean when I build net it would need to check and build openssl first?

    No. Since you make the dependency, cmake will handle it and openssl will be build before your library.

PS: There's still a lot of work to do. Because cmake doesn't know where the openssl result is, your project may run into link error. Here is a good example from the answer of "What is the best way to build boost with cmake".It use add_library with IMPORTED GLOBAL and set_target_properties with IMPORTED_LOCATION_* to solve the problem

like image 114
user3790229 Avatar answered Oct 04 '22 08:10

user3790229