[CMake] setting up a library with cmake

Owen Alanzo Hogarth gurenchan at gmail.com
Thu Aug 13 12:57:35 EDT 2015


I initially setup a project like this:

PROJECT/
.../build/
.../cmake_modules/
.../resources/
.../source/                         <-- subfolders under sources are shared
libs
.../source/components/
.../source/core_math/
.../source/ren_opengl/
.../source/utils/
.../source/main.c     <-- main() and imported all the shared libs

this setup worked great now I wanted to add another layer to this project

I want to add a top level folder that would contain the project
PROJECT/
.../build/
.../cmake_modules/
*.../project/              <-- want to move main here*
.../project/game.c
.../project/game.h
.../resources/
.../source/                         <-- subfolders under sources are shared
libs
.../source/components/
.../source/core_math/
.../source/ren_opengl/
.../source/utils/
.../source/main.c     <-- main() and imported all the shared libs

I want to move the main application starter from under the sources folder
to it's own folder under the project sub folder and be able to just import
say main_libs.h

which would in turn bring all the functions that I described in the
sources/ part of the tree.

How can I accomplish this with cmake?

This is what the main.c cmakelists file looks like atm. This is the
cmakelists.txt that starts the whole build down through all the dynamic
libs. Each dynamic lib folder just has a .h .c and maybe some simple header
includes.

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(main)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)

FIND_PACKAGE(SDL2 REQUIRED)
INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIR})


INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/source/core_math")
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/source/utils/time_utils")
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/source/utils/resource_utils")
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/source/ren_opengl")
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/source/components/renderable2d")

INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/source/glm/vec3.hpp")

FIND_PACKAGE(SDL2 REQUIRED)
INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIR})

REQUIRED_VARS SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR)
FIND_PACKAGE(SDL2_IMAGE)
INCLUDE_DIRECTORIES(${SDL2_IMAGE_INCLUDE_DIR})

ADD_SUBDIRECTORY(source)
ADD_SUBDIRECTORY(project) //my attempt to add the new directory

SET(SRC_FILES main.c)
SET(EXTERNAL_TARGET_LIBS ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARY})
SET(COMPONENTS renderable2d)
SET(INTERNAL_TARGET_LIBS core_math time_utils resource_utils ren_opengl)

SET(TARGET_LIBS ${INTERNAL_TARGET_LIBS} ${EXTERNAL_TARGET_LIBS}
${COMPONENTS})

ADD_EXECUTABLE(blulauncher ${SRC_FILES})
TARGET_LINK_LIBRARIES(blulauncher ${TARGET_LIBS})


FILE(COPY ${CMAKE_CURRENT_SOURCE_DIR}/resources/ DESTINATION
${CMAKE_CURRENT_BINARY_DIR}/bin/resources/)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150814/55d69330/attachment.html>


More information about the CMake mailing list