Project

General

Profile

Task #20

Rewrite cmake scripts to enforce dependency-policies

Added by Lukasz Gromanowski over 6 years ago. Updated over 1 year ago.

Status:
New
Priority:
Low
Assignee:
-
Category:
Code Maintenance
Target version:
Start date:
08/06/2011
% Done:

0%

Severity:
Normal

Description

Trying to depend on a package you should not depend on, should result in a compile error.

May require some changes in the way headers are included. And while we are at it, the cmake files could use a general cleanup.

History

#1 Updated by Marc Zinnschlag almost 6 years ago

  • Target version changed from openmw-0.12 to openmw-future

#2 Updated by scrawl . over 2 years ago

Is this even possible?

Let's say we adjust the way include paths are setup so that e.g.

#include <mwworld/world.hpp>

would be legal within apps/openmw, but illegal within components/. But then what is to prevent someone from just include-ing
#include "../apps/openmw/mwworld/world.hpp

instead? How can you forbid relative include paths? I don't think that's possible.

#3 Updated by Roman Proskuryakov over 1 year ago

Jannik Heller wrote:

Is this even possible?

Let's say we adjust the way include paths are setup so that e.g.
[...]
would be legal within apps/openmw, but illegal within components/. But then what is to prevent someone from just include-ing
[...]
instead? How can you forbid relative include paths? I don't think that's possible.

Well, it seems like one should never include a header from a package by relative path.

https://cmake.org/cmake/help/v3.0/command/target_include_directories.html
Lets say we've got 2 binaries and 2 libs:

add_library(A ...)
add_library(B ...)

add_executable(needs_a a.cpp)
add_executable(needs_a_and_b a_b.cpp)

# the most important part start
target_include_directories(A PUBLIC some_a_dir_prefix/)
target_include_directories(B PUBLIC some_b_dir_prefix/)

target_link_libraries(needs_a A) # adds -I some_a_dir_prefix/
target_link_libraries(needs_a_and_b A B) # adds -I some_a_dir_prefix/ -I some_b_dir_prefix/
# end

// a.cpp:
#include <a.h>
...

// a_b.cpp:
#include <a.h>
#include <b.h>
...

What will happen if one includes b.h inside a.cpp? It will result in a compile error until you add target_link_libraries(needs_a B). It is not possible to implement such behaviour if a.h and b.h are placed in the same directory.

Also available in: Atom PDF