[CMake] Include_directories looks for Boost twice / Problem with if statement
Raymond Wan
rwan.work at gmail.com
Thu Dec 6 12:45:23 EST 2012
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
More information about the CMake
mailing list