Re: [CMake] Beginner's Question: Organizing Projects

2010-10-28 Thread Dominik Gabi
On Wed, 2010-10-27 at 10:54 -0500, Ryan Pavlik wrote:
 On Wed, Oct 27, 2010 at 9:04 AM, Rolf Eike Beer e...@sf-mail.de wrote:
  Thanks. The way I understand this is that now instead of
 
  include_directories(${GTKMM_INCLUDE_DIRS})
 
  i would write something like
 
  include_directories(${GTKMM_INCLUDE_DIRS})
  # and at the end of the file
  set(INCLUDE_DIRECTORIES ${INCLUDE_DIRECTORIES} PARENT_SCOPE)
 
  ? I'd do the same with the LINK_DIRECTORIES, LINK_LIBRARIES property and
  for all other libraries?
 
  Don't set LINK_DIRECTORIES and LINK_LIBRARIES. When you are a beginner
  probably every usage of them is wrong.
 
  You simply do
 
  TARGET_LINK_LIBRARIES(mytarget ${GTK_LIBRARIES}) (or however that is called)
 
  The only thing you need to export upwards in this case would be the
  GTK_LIBRARIES variable.
 
  Eike
 
 This is good advice, however, in most cases, since you're using
 pkgconfig directly (which is not the recommended way), that will cause
 more failure.  Best thing to do is to create/find a cmake module for
 each of those packages, that might use pkgconfig for help finding the
 library, but that doesn't just use what it returns verbatim.
 
 Ryan
 

As it turns out, my problems are probably not cmake related. Thanks for
the help anyway.

Maybe it's my limited understanding of C++. So here's the problem. The
project structure is as before. I've got a ui directory that uses
classes from the geometry directory. I've set up a simple test class in
the geometry directory that I use in some file in ui.

// Test.h
class Test
{
public:
static void test();
};

// Test.cpp
#include Test.h
#include iostream
void Test::test()
{
std::cout  Hello World!  std::endl;
}

With these two files it works perfectly fine. Everything compiles, links
and runs without problems. Unfortunately, as soon as I add templates the
situation is different:

// Test.h
templateclass T
class Test
{
public:
static void test();
};

// Test.cpp
#include Test.h
#include iostream
templateclass T
void TestT::test()
{
std::cout  Hello World!  std::endl;
}

results in the following error (I've left out the name spaces above for
clarity):

domi...@dmac:Pixels$ make
Scanning dependencies of target Ui
[ 33%] Building CXX object ui/CMakeFiles/Ui.dir/MainWindow.cpp.o
Linking CXX static library libUi.a
[ 33%] Built target Ui
[ 66%] Built target Geometry
Linking CXX executable Pixels
ui/libUi.a(MainWindow.cpp.o): In function
`UI::MainWindow::start_application(int, char**)':
MainWindow.cpp:(.text+0x9e1): undefined reference to
`GE::Testdouble::test()'
collect2: ld returned 1 exit status
make[2]: *** [Pixels] Error 1
make[1]: *** [CMakeFiles/Pixels.dir/all] Error 2
make: *** [all] Error 2

I don't get it, can anyone explain this to me?

Dominik.


___
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


Re: [CMake] Beginner's Question: Organizing Projects

2010-10-28 Thread John Drescher
On Thu, Oct 28, 2010 at 8:23 AM, Dominik Gabi dkgis...@gmail.com wrote:
 On Wed, 2010-10-27 at 10:54 -0500, Ryan Pavlik wrote:
 On Wed, Oct 27, 2010 at 9:04 AM, Rolf Eike Beer e...@sf-mail.de wrote:
  Thanks. The way I understand this is that now instead of
 
  include_directories(${GTKMM_INCLUDE_DIRS})
 
  i would write something like
 
  include_directories(${GTKMM_INCLUDE_DIRS})
  # and at the end of the file
  set(INCLUDE_DIRECTORIES ${INCLUDE_DIRECTORIES} PARENT_SCOPE)
 
  ? I'd do the same with the LINK_DIRECTORIES, LINK_LIBRARIES property and
  for all other libraries?
 
  Don't set LINK_DIRECTORIES and LINK_LIBRARIES. When you are a beginner
  probably every usage of them is wrong.
 
  You simply do
 
  TARGET_LINK_LIBRARIES(mytarget ${GTK_LIBRARIES}) (or however that is 
  called)
 
  The only thing you need to export upwards in this case would be the
  GTK_LIBRARIES variable.
 
  Eike

 This is good advice, however, in most cases, since you're using
 pkgconfig directly (which is not the recommended way), that will cause
 more failure.  Best thing to do is to create/find a cmake module for
 each of those packages, that might use pkgconfig for help finding the
 library, but that doesn't just use what it returns verbatim.

 Ryan


 As it turns out, my problems are probably not cmake related. Thanks for
 the help anyway.

 Maybe it's my limited understanding of C++. So here's the problem. The
 project structure is as before. I've got a ui directory that uses
 classes from the geometry directory. I've set up a simple test class in
 the geometry directory that I use in some file in ui.

 // Test.h
 class Test
 {
        public:
                static void test();
 };

 // Test.cpp
 #include Test.h
 #include iostream
 void Test::test()
 {
        std::cout  Hello World!  std::endl;
 }

 With these two files it works perfectly fine. Everything compiles, links
 and runs without problems. Unfortunately, as soon as I add templates the
 situation is different:

 // Test.h
 templateclass T
 class Test
 {
 public:
 static void test();
 };

 // Test.cpp
 #include Test.h
 #include iostream
 templateclass T
 void TestT::test()
 {
 std::cout  Hello World!  std::endl;
 }

 results in the following error (I've left out the name spaces above for
 clarity):

 domi...@dmac:Pixels$ make
 Scanning dependencies of target Ui
 [ 33%] Building CXX object ui/CMakeFiles/Ui.dir/MainWindow.cpp.o
 Linking CXX static library libUi.a
 [ 33%] Built target Ui
 [ 66%] Built target Geometry
 Linking CXX executable Pixels
 ui/libUi.a(MainWindow.cpp.o): In function
 `UI::MainWindow::start_application(int, char**)':
 MainWindow.cpp:(.text+0x9e1): undefined reference to
 `GE::Testdouble::test()'
 collect2: ld returned 1 exit status
 make[2]: *** [Pixels] Error 1
 make[1]: *** [CMakeFiles/Pixels.dir/all] Error 2
 make: *** [all] Error 2

 I don't get it, can anyone explain this to me?


Start reading here:

http://stackoverflow.com/questions/115703/storing-c-template-function-definitions-in-a-cpp-file

John
___
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


Re: [CMake] Beginner's Question: Organizing Projects

2010-10-28 Thread John Drescher
On Thu, Oct 28, 2010 at 8:29 AM, John Drescher dresche...@gmail.com wrote:
 On Thu, Oct 28, 2010 at 8:23 AM, Dominik Gabi dkgis...@gmail.com wrote:
 On Wed, 2010-10-27 at 10:54 -0500, Ryan Pavlik wrote:
 On Wed, Oct 27, 2010 at 9:04 AM, Rolf Eike Beer e...@sf-mail.de wrote:
  Thanks. The way I understand this is that now instead of
 
  include_directories(${GTKMM_INCLUDE_DIRS})
 
  i would write something like
 
  include_directories(${GTKMM_INCLUDE_DIRS})
  # and at the end of the file
  set(INCLUDE_DIRECTORIES ${INCLUDE_DIRECTORIES} PARENT_SCOPE)
 
  ? I'd do the same with the LINK_DIRECTORIES, LINK_LIBRARIES property and
  for all other libraries?
 
  Don't set LINK_DIRECTORIES and LINK_LIBRARIES. When you are a beginner
  probably every usage of them is wrong.
 
  You simply do
 
  TARGET_LINK_LIBRARIES(mytarget ${GTK_LIBRARIES}) (or however that is 
  called)
 
  The only thing you need to export upwards in this case would be the
  GTK_LIBRARIES variable.
 
  Eike

 This is good advice, however, in most cases, since you're using
 pkgconfig directly (which is not the recommended way), that will cause
 more failure.  Best thing to do is to create/find a cmake module for
 each of those packages, that might use pkgconfig for help finding the
 library, but that doesn't just use what it returns verbatim.

 Ryan


 As it turns out, my problems are probably not cmake related. Thanks for
 the help anyway.

 Maybe it's my limited understanding of C++. So here's the problem. The
 project structure is as before. I've got a ui directory that uses
 classes from the geometry directory. I've set up a simple test class in
 the geometry directory that I use in some file in ui.

 // Test.h
 class Test
 {
        public:
                static void test();
 };

 // Test.cpp
 #include Test.h
 #include iostream
 void Test::test()
 {
        std::cout  Hello World!  std::endl;
 }

 With these two files it works perfectly fine. Everything compiles, links
 and runs without problems. Unfortunately, as soon as I add templates the
 situation is different:

 // Test.h
 templateclass T
 class Test
 {
 public:
 static void test();
 };

 // Test.cpp
 #include Test.h
 #include iostream
 templateclass T
 void TestT::test()
 {
 std::cout  Hello World!  std::endl;
 }

 results in the following error (I've left out the name spaces above for
 clarity):

 domi...@dmac:Pixels$ make
 Scanning dependencies of target Ui
 [ 33%] Building CXX object ui/CMakeFiles/Ui.dir/MainWindow.cpp.o
 Linking CXX static library libUi.a
 [ 33%] Built target Ui
 [ 66%] Built target Geometry
 Linking CXX executable Pixels
 ui/libUi.a(MainWindow.cpp.o): In function
 `UI::MainWindow::start_application(int, char**)':
 MainWindow.cpp:(.text+0x9e1): undefined reference to
 `GE::Testdouble::test()'
 collect2: ld returned 1 exit status
 make[2]: *** [Pixels] Error 1
 make[1]: *** [CMakeFiles/Pixels.dir/all] Error 2
 make: *** [all] Error 2

 I don't get it, can anyone explain this to me?


 Start reading here:

 http://stackoverflow.com/questions/115703/storing-c-template-function-definitions-in-a-cpp-file

 John


Here is a second link:
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12


-- 
John M. Drescher
___
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


Re: [CMake] Beginner's Question: Organizing Projects

2010-10-28 Thread Aaron_Wright
I've seen this a few times in the past, and I've seen a few people try to 
get it to work. My advise is to not try. The problem comes from thinking 
that a template class is a class, but that is not true. Your template 
class is just a recipe for the compiler to use when it wants to make a 
class for you on the fly at compile time. The compiler needs the entire 
recipe to do this. Thus, splitting up the recipe (template) between a 
header and a cpp file confuses the compiler.

Do yourself a favor and just put template classes in headers.

---
Aaron Wright




From:
John Drescher dresche...@gmail.com
To:
Dominik Gabi dkgis...@gmail.com
Cc:
cmake@cmake.org
Date:
10/28/2010 05:31 AM
Subject:
Re: [CMake] Beginner's Question: Organizing Projects
Sent by:
cmake-boun...@cmake.org



On Thu, Oct 28, 2010 at 8:29 AM, John Drescher dresche...@gmail.com 
wrote:
 On Thu, Oct 28, 2010 at 8:23 AM, Dominik Gabi dkgis...@gmail.com 
wrote:
 On Wed, 2010-10-27 at 10:54 -0500, Ryan Pavlik wrote:
 On Wed, Oct 27, 2010 at 9:04 AM, Rolf Eike Beer e...@sf-mail.de 
wrote:
  Thanks. The way I understand this is that now instead of
 
  include_directories(${GTKMM_INCLUDE_DIRS})
 
  i would write something like
 
  include_directories(${GTKMM_INCLUDE_DIRS})
  # and at the end of the file
  set(INCLUDE_DIRECTORIES ${INCLUDE_DIRECTORIES} PARENT_SCOPE)
 
  ? I'd do the same with the LINK_DIRECTORIES, LINK_LIBRARIES 
property and
  for all other libraries?
 
  Don't set LINK_DIRECTORIES and LINK_LIBRARIES. When you are a 
beginner
  probably every usage of them is wrong.
 
  You simply do
 
  TARGET_LINK_LIBRARIES(mytarget ${GTK_LIBRARIES}) (or however that is 
called)
 
  The only thing you need to export upwards in this case would be 
the
  GTK_LIBRARIES variable.
 
  Eike

 This is good advice, however, in most cases, since you're using
 pkgconfig directly (which is not the recommended way), that will cause
 more failure.  Best thing to do is to create/find a cmake module for
 each of those packages, that might use pkgconfig for help finding the
 library, but that doesn't just use what it returns verbatim.

 Ryan


 As it turns out, my problems are probably not cmake related. Thanks for
 the help anyway.

 Maybe it's my limited understanding of C++. So here's the problem. The
 project structure is as before. I've got a ui directory that uses
 classes from the geometry directory. I've set up a simple test class in
 the geometry directory that I use in some file in ui.

 // Test.h
 class Test
 {
public:
static void test();
 };

 // Test.cpp
 #include Test.h
 #include iostream
 void Test::test()
 {
std::cout  Hello World!  std::endl;
 }

 With these two files it works perfectly fine. Everything compiles, 
links
 and runs without problems. Unfortunately, as soon as I add templates 
the
 situation is different:

 // Test.h
 templateclass T
 class Test
 {
 public:
 static void test();
 };

 // Test.cpp
 #include Test.h
 #include iostream
 templateclass T
 void TestT::test()
 {
 std::cout  Hello World!  std::endl;
 }

 results in the following error (I've left out the name spaces above for
 clarity):

 domi...@dmac:Pixels$ make
 Scanning dependencies of target Ui
 [ 33%] Building CXX object ui/CMakeFiles/Ui.dir/MainWindow.cpp.o
 Linking CXX static library libUi.a
 [ 33%] Built target Ui
 [ 66%] Built target Geometry
 Linking CXX executable Pixels
 ui/libUi.a(MainWindow.cpp.o): In function
 `UI::MainWindow::start_application(int, char**)':
 MainWindow.cpp:(.text+0x9e1): undefined reference to
 `GE::Testdouble::test()'
 collect2: ld returned 1 exit status
 make[2]: *** [Pixels] Error 1
 make[1]: *** [CMakeFiles/Pixels.dir/all] Error 2
 make: *** [all] Error 2

 I don't get it, can anyone explain this to me?


 Start reading here:

 
http://stackoverflow.com/questions/115703/storing-c-template-function-definitions-in-a-cpp-file


 John


Here is a second link:
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12


-- 
John M. Drescher
___
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


___
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


[CMake] Beginner's Question: Organizing Projects

2010-10-27 Thread Dominik Gabi
Hi,

after reading the tutorial I've decided to make my own project using
cmake but I'm having some troubles here. I'd like to organize my project
as follows:

Pixels/
  CMakeLists.txt (0)
  Pixels.cpp
  geometry/
CMakeLists.txt (1)
Vector.h Vector.cpp ...
  ui/
CMakeLists.txt (2)
MainWindow.h MainWindow.cpp ...

The dependencies are the following: the geometry package should be self
sufficient. The ui package needs the geometry library, gtkmm etc. and
Pixels.cpp for now just calls a static method in MainWindow therefore
depends only on ui.

I've spent the past few hours trying to get everything to compile but I
always end up with some cmake or linker error :(

Here's what I've come up with so far:

### CMakeLists.txt (1)
add_library(Geometry Vector.h Vector.cpp ...)

### CMakeLists.txt (2)
add_library(Ui MainWindow.h MainWindow.cpp ...)

# Geometry
include_directories(${PIXELS_SRC_DIR}/geometry)
link_directories(${PIXELS_BIN_DIR}/geometry)
target_link_libraries(Ui Geometry)

find_package(PkgConfig)
# GTKMM
pkg_check_modules(GTKMM gtkmm-2.4)
include_directories(${GTKMM_INCLUDE_DIRS})
link_directories(${GTKMM_LIBRARY_DIRS})
target_link_libraries(Ui ${GTKMM_LIBRARIES})

# GTKGLEXTMM
pkg_check_modules(GLEXT gtkglextmm-1.2)
include_directories(${GLEXT_INCLUDE_DIRS})
link_directories(${GLEXT_LIBRARY_DIRS})
target_link_libraries(Ui ${GLEXT_LIBRARIES})

### CMakeLists.txt (0)
cmake_minimum_required(VERSION 2.8)
project(Pixels)

set(PIXELS_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(PIXELS_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR})

add_executable(Pixels Pixels.cpp)

include_directories(${PIXELS_SRC_DIR}/ui)
add_subdirectory(${PIXELS_SRC_DIR}/ui)
target_link_libraries(Pixels Ui)
### end

Unfortunately, this results in a ton of errors such as 

make[2]: *** [CMakeFiles/Pixels.dir/Pixels.cpp.o] Error 1
make[1]: *** [CMakeFiles/Pixels.dir/all] Error 2
make: *** [all] Error 2

Gtk has not been declared, Vector.h: no such file or directory.
Obviously I'm not doing it right ;)

The question then is: What am I doing wrong?

Thanks,
  Dominik.
 


___
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


Re: [CMake] Beginner's Question: Organizing Projects

2010-10-27 Thread Marcel Loose
On Wed, 2010-10-27 at 14:02 +0200, Dominik Gabi wrote:
 Hi,
 
 after reading the tutorial I've decided to make my own project using
 cmake but I'm having some troubles here. I'd like to organize my
project
 as follows:
 
 Pixels/
   CMakeLists.txt (0)
   Pixels.cpp
   geometry/
 CMakeLists.txt (1)
 Vector.h Vector.cpp ...
   ui/
 CMakeLists.txt (2)
 MainWindow.h MainWindow.cpp ...
 
 The dependencies are the following: the geometry package should be
self
 sufficient. The ui package needs the geometry library, gtkmm etc. and
 Pixels.cpp for now just calls a static method in MainWindow therefore
 depends only on ui.
 
 I've spent the past few hours trying to get everything to compile but
I
 always end up with some cmake or linker error :(
 
 Here's what I've come up with so far:
 
 ### CMakeLists.txt (1)
 add_library(Geometry Vector.h Vector.cpp ...)
 
 ### CMakeLists.txt (2)
 add_library(Ui MainWindow.h MainWindow.cpp ...)
 
 # Geometry
 include_directories(${PIXELS_SRC_DIR}/geometry)
 link_directories(${PIXELS_BIN_DIR}/geometry)
 target_link_libraries(Ui Geometry)
 
 find_package(PkgConfig)
 # GTKMM
 pkg_check_modules(GTKMM gtkmm-2.4)
 include_directories(${GTKMM_INCLUDE_DIRS})
 link_directories(${GTKMM_LIBRARY_DIRS})
 target_link_libraries(Ui ${GTKMM_LIBRARIES})
 
 # GTKGLEXTMM
 pkg_check_modules(GLEXT gtkglextmm-1.2)
 include_directories(${GLEXT_INCLUDE_DIRS})
 link_directories(${GLEXT_LIBRARY_DIRS})
 target_link_libraries(Ui ${GLEXT_LIBRARIES})
 
 ### CMakeLists.txt (0)
 cmake_minimum_required(VERSION 2.8)
 project(Pixels)
 
 set(PIXELS_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 set(PIXELS_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR})
 
 add_executable(Pixels Pixels.cpp)
 
 include_directories(${PIXELS_SRC_DIR}/ui)
 add_subdirectory(${PIXELS_SRC_DIR}/ui)
 target_link_libraries(Pixels Ui)
 ### end
 
 Unfortunately, this results in a ton of errors such as 
 
 make[2]: *** [CMakeFiles/Pixels.dir/Pixels.cpp.o] Error 1
 make[1]: *** [CMakeFiles/Pixels.dir/all] Error 2
 make: *** [all] Error 2
 
 Gtk has not been declared, Vector.h: no such file or directory.
 Obviously I'm not doing it right ;)
 
 The question then is: What am I doing wrong?
 
 Thanks,
   Dominik.
  

Hi Dominik,

You should realize that variables have scope, as have properties you set
on directories (which happens when you use, e.g.,
include_directories()). The GTK stuff is only put on the include path in
the UI directory. 

There are, IMO, two ways you can solve this.

1) Search for GTK in you top-level CMakeLists.txt file and use
include_directories() there. This will ensure that the
INCLUDE_DIRECTORIES property is set on all the subdirectories.

2) Export the GTK include directory up-level. The IMO fragile way of
doing this is using PARENT_SCOPE, because you have to use that at all
intermediate levels. The safer way is to use a global property.

The first option is definitely the easiest to implement but, for larger
projects, will cause your top-level CMakeLists.txt file to grow
extensively. And, worse, that file will share implementation details
of some lower-level directory, requiring package XYZ. So, for larger
projects, I would choose the seconds option.

Hope this helps.

Best regards,
Marcel Loose.



___
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


Re: [CMake] Beginner's Question: Organizing Projects

2010-10-27 Thread Dominik Gabi
Thanks. The way I understand this is that now instead of 

include_directories(${GTKMM_INCLUDE_DIRS})

i would write something like 

include_directories(${GTKMM_INCLUDE_DIRS})
# and at the end of the file
set(INCLUDE_DIRECTORIES ${INCLUDE_DIRECTORIES} PARENT_SCOPE)

? I'd do the same with the LINK_DIRECTORIES, LINK_LIBRARIES property and
for all other libraries? 

Is this more or less what you mean by exporting? Sorry for the stupid
questions but I'm currently a bit overwhelmed by the cmake
documentation...

Thanks, 
  Dominik.

On Wed, 2010-10-27 at 14:32 +0200, Marcel Loose wrote:
 On Wed, 2010-10-27 at 14:02 +0200, Dominik Gabi wrote:
  Hi,
  
  after reading the tutorial I've decided to make my own project using
  cmake but I'm having some troubles here. I'd like to organize my
 project
  as follows:
  
  Pixels/
CMakeLists.txt (0)
Pixels.cpp
geometry/
  CMakeLists.txt (1)
  Vector.h Vector.cpp ...
ui/
  CMakeLists.txt (2)
  MainWindow.h MainWindow.cpp ...
  
  The dependencies are the following: the geometry package should be
 self
  sufficient. The ui package needs the geometry library, gtkmm etc. and
  Pixels.cpp for now just calls a static method in MainWindow therefore
  depends only on ui.
  
  I've spent the past few hours trying to get everything to compile but
 I
  always end up with some cmake or linker error :(
  
  Here's what I've come up with so far:
  
  ### CMakeLists.txt (1)
  add_library(Geometry Vector.h Vector.cpp ...)
  
  ### CMakeLists.txt (2)
  add_library(Ui MainWindow.h MainWindow.cpp ...)
  
  # Geometry
  include_directories(${PIXELS_SRC_DIR}/geometry)
  link_directories(${PIXELS_BIN_DIR}/geometry)
  target_link_libraries(Ui Geometry)
  
  find_package(PkgConfig)
  # GTKMM
  pkg_check_modules(GTKMM gtkmm-2.4)
  include_directories(${GTKMM_INCLUDE_DIRS})
  link_directories(${GTKMM_LIBRARY_DIRS})
  target_link_libraries(Ui ${GTKMM_LIBRARIES})
  
  # GTKGLEXTMM
  pkg_check_modules(GLEXT gtkglextmm-1.2)
  include_directories(${GLEXT_INCLUDE_DIRS})
  link_directories(${GLEXT_LIBRARY_DIRS})
  target_link_libraries(Ui ${GLEXT_LIBRARIES})
  
  ### CMakeLists.txt (0)
  cmake_minimum_required(VERSION 2.8)
  project(Pixels)
  
  set(PIXELS_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
  set(PIXELS_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR})
  
  add_executable(Pixels Pixels.cpp)
  
  include_directories(${PIXELS_SRC_DIR}/ui)
  add_subdirectory(${PIXELS_SRC_DIR}/ui)
  target_link_libraries(Pixels Ui)
  ### end
  
  Unfortunately, this results in a ton of errors such as 
  
  make[2]: *** [CMakeFiles/Pixels.dir/Pixels.cpp.o] Error 1
  make[1]: *** [CMakeFiles/Pixels.dir/all] Error 2
  make: *** [all] Error 2
  
  Gtk has not been declared, Vector.h: no such file or directory.
  Obviously I'm not doing it right ;)
  
  The question then is: What am I doing wrong?
  
  Thanks,
Dominik.
   
 
 Hi Dominik,
 
 You should realize that variables have scope, as have properties you set
 on directories (which happens when you use, e.g.,
 include_directories()). The GTK stuff is only put on the include path in
 the UI directory. 
 
 There are, IMO, two ways you can solve this.
 
 1) Search for GTK in you top-level CMakeLists.txt file and use
 include_directories() there. This will ensure that the
 INCLUDE_DIRECTORIES property is set on all the subdirectories.
 
 2) Export the GTK include directory up-level. The IMO fragile way of
 doing this is using PARENT_SCOPE, because you have to use that at all
 intermediate levels. The safer way is to use a global property.
 
 The first option is definitely the easiest to implement but, for larger
 projects, will cause your top-level CMakeLists.txt file to grow
 extensively. And, worse, that file will share implementation details
 of some lower-level directory, requiring package XYZ. So, for larger
 projects, I would choose the seconds option.
 
 Hope this helps.
 
 Best regards,
 Marcel Loose.
 
 
 


___
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


Re: [CMake] Beginner's Question: Organizing Projects

2010-10-27 Thread Rolf Eike Beer
 Thanks. The way I understand this is that now instead of

 include_directories(${GTKMM_INCLUDE_DIRS})

 i would write something like

 include_directories(${GTKMM_INCLUDE_DIRS})
 # and at the end of the file
 set(INCLUDE_DIRECTORIES ${INCLUDE_DIRECTORIES} PARENT_SCOPE)

 ? I'd do the same with the LINK_DIRECTORIES, LINK_LIBRARIES property and
 for all other libraries?

Don't set LINK_DIRECTORIES and LINK_LIBRARIES. When you are a beginner
probably every usage of them is wrong.

You simply do

TARGET_LINK_LIBRARIES(mytarget ${GTK_LIBRARIES}) (or however that is called)

The only thing you need to export upwards in this case would be the
GTK_LIBRARIES variable.

Eike
___
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