Skip to content

EdenEast/scaffold

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scaffold

Shaded CMake macros and functions

Scaffold is a cmake library that helps you setup and maintain your cmake scripts. Scaffold is ment to be used as a submodule in your project.

Quick start

  1. Add this repository as a submodule of your project:

    git submodule add https://github.com/cruizemissile/scaffold.git external/scaffold
  2. Include this repository in your project's CMakeLists:

    cmake_minimum_required(VERSION 3.7)
    project(foo) # Note: make sure that you declare the project before you include scaffold
    
    list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/external/scaffold")
    include(scaffold)

Example usage of Scaffold in your cmake project

Setting up a project

# Root CMakeLists.txt.

# Not sure the min version of cmake that is required.
# This needs to be tested. (currently developing with 3.9)
cmake_minimum_required(VERSION 3.7)

# Make sure that you define the project before you include 
# Scaffold into your file
project(foo)

# Include scaffold into the project from where you added 
# it as a submodule
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/external/scaffold")
include(scaffold)

# Here we are checking to see if the project is the master project.
# We can create options based on if the project is the master or not.
# Only build samples and tests if we are the master project.
# If we are a submodule then we dont have to build the sample and tests.
check_master_project(FOO_MASTER_PROJECT)
option(ENABLE_SAMPLES "Build samples for foo" ${FOO_MASTER_PROJECT})
option(ENABLE_TESTS "Build tests for foo" ${FOO_MASTER_PROJECT})

# Include the subdirectory that defines the the target
add_subdirectory(foo)

if(ENABLE_SAMPLES)
    add_subdirectory(samples)
endif()

if(ENABLE_TESTS)
    add_subdirectory(tests)
endif()

Setting up a target

# foo/CMakeLists.txt

# -------------------------------------------------
# An example of a library target
file(GLOB_RECURSE source_files
    "${CMAKE_CURRENT_LIST_DIR}/*.hpp"
    "${CMAKE_CURRENT_LIST_DIR}/*.cpp"
)

create_library(eden SOURCE_LIST ${eden_files} CXX_VERSION 17)
target_include_directories(eden PUBLIC
  $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
  $<INSTALL_INTERFACE:include>
)

# -------------------------------------------------
# An example of a header only / interface library
file(GLOB_RECURSE bar_sources "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp")
create_interface_library(bar SOURCE_LIST ${bar_sources} CXX_VERSION 17)
target_include_directories(${BAR_LIB} INTERFACE
  $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
  $<INSTALL_INTERFACE:include>
)

About

Shaded CMake macros and functions

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages