I have been working on a fun project (a game engine) for awhile now and figured i could make it more portable and easy to compile across platforms if I use cmake. Right now i have it set up like so, with a main executable and then a bunch of shared libraries that the executable is linked to. I've found all the material needed to produce the libraries and the executable, and linking those to the executable, but what of linking a dependency like a static library or another shared library to one of the libraries i produce? Here is a visual
Sentiment (name of project) -Root (all the interfaces and components of the engine. main.cpp is here -Sentiment_OGL4Renderer (the files for the Renderer library) -Sentiment_SFMLGui (the files for the Gui library) -Sentiment_TestGame (the code for a game) now i want all of these, the executable and the shared libraries built and put into the bin folder in the top level directory. What i found suggested online for a setup like this was to make cmakelists.txt files in each folder, and then one in the root, for each project. What i have thus far is this.
#Sentiment cmake_minimum_required(VERSION 2.6) project(Sentiment) set(RENDERER Sentiment_OGL4Renderer) set(GUI Sentiment_SFMLGui) set(GAME Test_Game) add_definitions(-DBUILD_DLL) list( APPEND CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS} -g -ftest-coverage -fprofile-arcs") set(EXECUTABLE_OUTPUT_PATH "${Sentiment_SOURCE_DIR}/bin") set(LIBRARY_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}") link_directories("${LIBRARY_OUTPUT_PATH}") add_subdirectory("${RENDERER}") add_subdirectory("${GUI}") add_subdirectory("${GAME}") add_subdirectory(Root) in root
project(Sentiment_exe) link_directories("${Sentiment_SOURCE_DIR}/bin") AUX_SOURCE_DIRECTORY(. new_source_list) add_executable("${CMAKE_PROJECT_NAME}" ${new_source_list}) target_link_libraries("${CMAKE_PROJECT_NAME}" "${LIBRARY_OUTPUT_PATH}/${RENDERER}" "${LIBRARY_OUPUT_PATH}/${GUI}" "${LIBRARY_OUTPUT_PATH}/${GAME}" "${ADDITIONAL_DEPENDENCIES}") in Sentiment_OGL4Renderer
project(Sentiment_OGL4-3Renderer) include_directories(${Sentiment_SOURCE_DIR}) add_definitions(-DGLEW_STATIC) add_library(Sentiment_OGL4-3Renderer SHARED Sentiment_OGL4Renderer.cpp GL/glew.cpp) in Sentiment_SFMLGui
project(Sentiment_SFMLGui) include_directories(${Sentiment_SOURCE_DIR}) add_library(Sentiment_SFMLGui SHARED Sentiment_SFMLGui.cpp) in Sentiment_TestGame
project(Sentiment_Game) include_directories(${Sentiment_SOURCE_DIR}) add_library(Sentiment_Game SHARED Game.cpp) As you can tell there are a lot of third party libraries, and i tried various methods of linking, like with target_link_libraries, and i cannot for the life of me figure how to link an external library to the ones i've made. First off, the renderer uses GLEW but it needs no external dependency so ignore that. Then it needs OpenGL32.lib and Gdi32.lib from the windows sdk (only for windows). As for SFML, i've got the DLL's in the bin folder which need to be linked, (can easily get the .so's when working in linux and can distribute with the final product if I ever choose to do so). I need these all linked as dependencies to the libraries i create, but nothing seems to work. The project is all c++ and I am currently using mingw32 to compile it. I'm brand new to cmake so please be gentle if it is really simple.