[CMake] find_package

David Cole DLRdave at aol.com
Fri Apr 24 11:33:09 EDT 2015


You should keep replies on the mailing list so others can see it, and
pitch in and help.

If you are actually building boost using execute_process during a
CMake run, then it should be able to find it with your find_package
call. Perhaps you need to give the find_package in step 4 a hint to
find it where you're building/installing it...?


HTH,
David C.


On Fri, Apr 24, 2015 at 11:16 AM, matzeNOTAVAILABLE .
<matze999 at gmail.com> wrote:
> The script to trigger the boost build from within cmake is bascially from:
> http://stackoverflow.com/questions/18354398/what-is-the-best-way-to-build-boost-with-cmake
>
> ...
> function(install_boost)
>
>   set(APT_BOOST_SRC "../external/boost_1_57_0")
>   set(APT_BOOST_COMPONENTS "log" "thread" "filesystem" "system")
>   set(BOOTSTRAP_CMD "./bootstrap.sh")
>   set(BOOTSTRAP_ARGS "--prefix=${APT_BOOST_BIN}")
>   message("Executing command: ${BOOTSTRAP_CMD} ${BOOTSTRAP_ARGS}")
>   execute_process(COMMAND "${BOOTSTRAP_CMD}" ${BOOTSTRAP_ARGS}
> WORKING_DIRECTORY ${APT_BOOST_SRC}
>     RESULT_VARIABLE BS_RESULT OUTPUT_VARIABLE BS_OUTPUT ERROR_VARIABLE
> BS_ERROR)
>   if(NOT BS_RESULT EQUAL 0)
>     message(FATAL_ERROR "Failed running ${BOOTSTRAP_CMD} ${BOOTSTRAP_ARGS}
> in ${APT_BOOST_SRC}:\n${BS_OUTPUT}\n${BS_ERROR}\n")
>   endif()
>
>   #
>   # run b2
>   #
>   set(B2_ARGS "link=static" "threading=multi" "runtime-link=static"
> "variant=release")
>   foreach(COMP IN LISTS APT_BOOST_COMPONENTS)
>     set(B2_ARGS "--with-${COMP}" ${B2_ARGS})
>   endforeach(COMP IN LISTS APT_BOOST_COMPONENTS)
>
>   set(B2_ARGS ${B2_ARGS} install)
>   set(B2_CMD "./b2")
>   message("Executing command: ${B2_CMD} ${B2_ARGS}")
>   execute_process(COMMAND ${B2_CMD} ${B2_ARGS} WORKING_DIRECTORY
> ${APT_BOOST_SRC}
>     RESULT_VARIABLE B2_RESULT OUTPUT_VARIABLE B2_OUTPUT ERROR_VARIABLE
> B2_ERROR)
>   if(NOT B2_RESULT EQUAL 0)
>     message(FATAL_ERROR "Failed running ${B2_CMD} in
> ${APT_BOOST_SRC}:\n${B2_OUTPUT}\n${B2_ERROR}\n")
>   endif()
>
> endfunction()
>
>
> set(APT_BOOST_BIN "${CMAKE_CURRENT_SOURCE_DIR}/boost_requirements")
> SET(BOOST_ROOT "${APT_BOOST_BIN}")
> FIND_PACKAGE( Boost 1.57 REQUIRED COMPONENTS log thread filesystem system)
>
> if(NOT Boost_FOUND)
>   MESSAGE (STATUS "Installing boost")
>   install_boost()
> else(NOT Boost_FOUND)
>   MESSAGE (STATUS "Boost install already exists")
> endif(NOT Boost_FOUND)
>
> MESSAGE (STATUS "Find package again")
> FIND_PACKAGE( Boost 1.57 REQUIRED COMPONENTS log thread filesystem system )
>
>
> My output is:
>
> Executing command: ./b2
> --with-system;--with-filesystem;--with-thread;--with-log;link=static;threading=multi;runtime-link=static;variant=release;install
> -- Find package again
> CMake Error at /usr/share/cmake-2.8/Modules/FindBoost.cmake:1131 (message):
>   Unable to find the requested Boost libraries.
>
>   Boost version: 1.54.0
>
>   Boost include path: /usr/include
>
>   Detected version of Boost is too old.  Requested version was 1.57 (or
>   newer).
> Call Stack (most recent call first):
>   CMakeLists.txt:123 (FIND_PACKAGE)
>
>
> -- Configuring incomplete, errors occurred!
>
>
> After the script completes the boost install exists.
> Interestingly, after running the script for the first time, deleting the
> generated CMakeCache.txt and rerunning the script, it does find the boost
> install.
>
> Thanks,
> Matt
>
> On Fri, Apr 24, 2015 at 4:09 PM, David Cole <DLRdave at aol.com> wrote:
>>
>> How do you do step 3) -- build boost?
>>
>> Unless the build is done and installed and ready to find before the
>> end of step 3, there is still nothing (yet) there for the find_package
>> in step 4 to find...
>>
>>
>> David C.
>>
>>
>> On Fri, Apr 24, 2015 at 9:36 AM, matzeNOTAVAILABLE . <matze999 at gmail.com>
>> wrote:
>> > Hi,
>> > i am struggling somewhat with find_package. I looked at the
>> > documentation
>> > and googled quite a bit, but i am still stuck. I alos tried
>> > stackoverflow to
>> > no avail.
>> >
>> > What i am trying to accomplish is the following:
>> > 1) See if my custom boost installation exists (using find_package)
>> > (version
>> > 1.57)
>> > 2) If it does not -> build it
>> > 3) Use find_package again to find the newly built boost libs.
>> >
>> > This works up until but not including step 3.
>> >
>> > Something that it might be complicating matters (i am not sure) is that
>> > i
>> > have a system boost installation (1.54).
>> >
>> > 1) (... set boost_root ...)
>> > 2) FIND_PACKAGE(Boost 1.57 COMPONENTS log thread filesystem system)
>> > 3) (... build boost if it Boost_FOUND is 0)
>> > 4) FIND_PACKAGE(Boost 1.57 REQUIRED COMPONENTS log thread filesystem
>> > system)
>> >
>> > The second call to find_package does not find the boost installation and
>> > thus does not set include dirs etc... properly.
>> >
>> > I wonder why not?
>> >
>> > Any hints are greatly appreciated,
>> > Matt
>> >
>> >
>> > --
>> >
>> > Powered by www.kitware.com
>> >
>> > Please keep messages on-topic and check the CMake FAQ at:
>> > http://www.cmake.org/Wiki/CMake_FAQ
>> >
>> > Kitware offers various services to support the CMake community. For more
>> > information on each offering, please visit:
>> >
>> > CMake Support: http://cmake.org/cmake/help/support.html
>> > CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> > CMake Training Courses: http://cmake.org/cmake/help/training.html
>> >
>> > Visit other Kitware open-source projects at
>> > http://www.kitware.com/opensource/opensource.html
>> >
>> > Follow this link to subscribe/unsubscribe:
>> > http://public.kitware.com/mailman/listinfo/cmake
>
>


More information about the CMake mailing list