[CMake] Include_directories looks for Boost twice / Problem with if statement

Jakub Zakrzewski jzakrzewski at e2e.ch
Fri Dec 7 03:46:11 EST 2012


Hi
Did you think about something like this:

ADD_DEFINITIONS (-DBOOST_ALL_NO_LIB)
SET (BOOST_ROOT $ENV{BOOST_ROOT})
SET (Boost_NO_SYSTEM_PATHS ON)
SET (Boost_USE_MULTITHREADED ON)
SET (Boost_USE_STATIC_RUNTIME OFF)
IF (TARGET parent)
FIND_PACKAGE (Boost 1.42.0 REQUIRED COMPONENTS system)
  IF (Boost_FOUND)  
    LINK_DIRECTORIES (${Boost_LIBRARY_DIRS})
    INCLUDE_DIRECTORIES (${Boost_INCLUDE_DIRS})
    TARGET_LINK_LIBRARIES (parent ${Boost_LIBRARIES})
  ENDIF ()
ENDIF (TARGET parent)


-----Original Message-----
From: cmake-bounces at cmake.org [mailto:cmake-bounces at cmake.org] On Behalf Of Raymond Wan
Sent: Donnerstag, 6. Dezember 2012 18:45
To: cmake at cmake.org
Subject: [CMake] Include_directories looks for Boost twice / Problem with if statement

Hi all,

I have two CMakeFile.txt's for a C++ project where one includes the other.  In both cases, I'm searching for Boost.

So, to make this easier, suppose I call one project "parent" and the other "child" such that "parent"'s CMakefile.txt has:

INCLUDE_DIRECTORIES (child)

where child is a subdirectory.  Both have:

ADD_DEFINITIONS (-DBOOST_ALL_NO_LIB)
SET (BOOST_ROOT $ENV{BOOST_ROOT})
SET (Boost_NO_SYSTEM_PATHS ON)
SET (Boost_USE_MULTITHREADED ON)
SET (Boost_USE_STATIC_RUNTIME OFF)
FIND_PACKAGE (Boost 1.42.0 REQUIRED COMPONENTS system) IF (Boost_FOUND)
  IF (TARGET parent)
    LINK_DIRECTORIES (${Boost_LIBRARY_DIRS})
    INCLUDE_DIRECTORIES (${Boost_INCLUDE_DIRS})
    TARGET_LINK_LIBRARIES (parent ${Boost_LIBRARIES})
  ENDIF (TARGET parent)
ENDIF ()

(In the subdirectory "child", I check for the target "child" instead.)

The reason I have to repeat it twice is because both parent and child has a main ().  parent has the one for the entire project; if I want to do unit testing on child, then I compile in child's build directory using its main.

I hope everything so far is ok.  The problem is that when I run the CMakeFile.txt of parent, it ends up checking for Boost twice.

There's no harm to it and I had left it alone for a while.  Then, I thought I could use an if statement inside child to prevent it from checking again.  Inside, child, none of these seem to work:

IF (NOT DEFINED Boost_FOUND)
IF (NOT Boost_FOUND)

So, while my question is about Boost, I guess it is irrelevant to boost...seems to be a problem with my understanding of variables and if statements.

Any suggestion on what I'm doing wrong?  Or am I going at it wrong and I need to rethink what I'm doing?

Thank you!

Ray
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list