107 lines
3.4 KiB
CMake
107 lines
3.4 KiB
CMake
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
|
|
project(EmberLib C)
|
|
set(CMAKE_C_STANDARD 11)
|
|
set(CMAKE_C_EXTENSIONS OFF)
|
|
|
|
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
|
|
|
# Export compile commands by default.
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
|
|
|
|
# I shamelessly stole this from https://blog.kitware.com/cmake-and-the-default-build-type/
|
|
# Set a default build type if none was specified
|
|
set(default_build_type "Release")
|
|
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
|
|
set(default_build_type "Debug")
|
|
endif()
|
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
|
|
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
|
|
# Set the possible values of build type for cmake-gui
|
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
|
|
endif()
|
|
|
|
# Note that testing requires libcheck to be installed on the system!
|
|
# See the tests/CMakeLists.txt file for details.
|
|
if(NOT DEFINED BUILD_TESTS)
|
|
set(BUILD_TESTS FALSE)
|
|
endif(NOT DEFINED BUILD_TESTS)
|
|
|
|
###############################################################################
|
|
# Set build features
|
|
set(CMAKE_BUILD_TYPE Debug)
|
|
|
|
###############################################################################
|
|
include(CheckCSourceCompiles)
|
|
include(CheckCSourceRuns)
|
|
include(CheckFunctionExists)
|
|
include(CheckIncludeFile)
|
|
include(CheckIncludeFiles)
|
|
include(CheckLibraryExists)
|
|
include(CheckSymbolExists)
|
|
include(CheckTypeSize)
|
|
|
|
###############################################################################
|
|
# Check headers
|
|
set(INCLUDES "")
|
|
macro(ck_check_include_file header var)
|
|
check_include_files("${INCLUDES};${header}" ${var})
|
|
if(${var})
|
|
set(INCLUDES ${INCLUDES} ${header})
|
|
endif(${var})
|
|
endmacro(ck_check_include_file)
|
|
|
|
ck_check_include_file("stdlib.h" HAVE_STDLIB_H)
|
|
|
|
###############################################################################
|
|
# Check functions
|
|
# (Nothing to check for the money example)
|
|
|
|
###############################################################################
|
|
# Check defines
|
|
# (Nothing to check for the money example)
|
|
|
|
###############################################################################
|
|
# Check struct members
|
|
# (Nothing to check for the money example)
|
|
|
|
###############################################################################
|
|
# Check for integer types
|
|
# (The following are used in check.h. Regardless if they are used in
|
|
# the project, they will need to be checked in order to use Check).
|
|
check_type_size(intmax_t INTMAX_T)
|
|
check_type_size(uintmax_t UINTMAX_T)
|
|
|
|
check_type_size(pid_t PID_T)
|
|
if(NOT HAVE_PID_T)
|
|
if(WIN32)
|
|
set(pid_t "int")
|
|
else(WIN32)
|
|
MESSAGE(FATAL_ERROR "pid_t doesn't exist on this platform?")
|
|
endif(WIN32)
|
|
endif(NOT HAVE_PID_T)
|
|
|
|
###############################################################################
|
|
# Check libraries
|
|
|
|
###############################################################################
|
|
# Generate "config.h" from "cmake/config.h.cmake"
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in
|
|
${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
|
include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
|
|
add_definitions(-DHAVE_CONFIG_H)
|
|
set(CONFIG_HEADER ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
|
|
|
add_subdirectory(src)
|
|
add_subdirectory(demo)
|
|
|
|
set(BUILD_TESTS TRUE)
|
|
if(${BUILD_TESTS})
|
|
add_subdirectory(tests)
|
|
|
|
# Unit tests
|
|
enable_testing()
|
|
endif(${BUILD_TESTS})
|
|
|
|
|