Q:

CMAKE / Code Organization

I'm going to be making a cmake script to help me cross platform build my game.
The way my game code folders are organized is I have the Game directory, then in there are folders for various things that include both the .hpp and .cpp files.
Example:
./Game/Engine/GraphicsContext.hpp
./Game/Resource/Sprite.hpp
etc...
Now here is where things get tricky. Everything right now is in a Visual Studio solution.
The solution has 2 projects; Game and Server.
All code for both projects sit in ./Game.
However, they share classes. They both use for example:
/Game/Net/NetEventDecoder.hpp
etc...
My goal is to do this such that, if I add more classes, I do not have to update my CMakeLists.
Does anyone have any advice on how I could achieve this, or minimize the amount of adding files I need to do;
For example, instead of:
INCLUDE "Game/UI/Button.hpp" ... etc
It would be nice to just: ADD_SUBDIRECTORY "Game/UI".
The problem is, for example, if I add the entire Game/Net subdirectory to the server project, it will include classes not used by the server.
Does anyone have a clever solution for this sort of problem or is the usual solution to update CMakeLists when I add a new class?
Thanks 

A:

Just share common sources using some library, like:
# Game/CMakeLists.txt
add_library(game_common "${GAME_COMMON_SOURCES}")
add_executable(game "${GAME_SOURCES}")
target_link_libraries(game game_common)

# Server/CMakeLists.txt
add_executable(server "${SERVER_SOURCES}")
target_link_libraries(server game_common)

