cmake-cmocka-template/CMakeLists.txt

83 lines
2.1 KiB
CMake

cmake_minimum_required(VERSION 3.20)
# Use the fancy version substitution
project(cmake-cmocka-template
VERSION 1.0
DESCRIPTION "template for cmake + cmocka"
LANGUAGES C CXX
)
enable_testing()
set(TARGET_GROUP production CACHE STRING "Group to build")
# For being able to used LSP
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Request C 11 standard features
set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED True)
set(CMAKE_C_FLAGS "-Wall -Werror -Wpedantic")
# SETUP THE CXX flags for .cpp
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_FLAGS "-Wall -Werror -Wpedantic")
# #######################################
# CMOCKA STUFF
# #######################################
# Add CMocka CMake modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmocka)
set (CMOCKA_PATH "" CACHE STRING "/usr/local/include")
# Search for the CMocka include directory
find_path(CMOCKA_INCLUDE_DIR
NAMES cmocka.h
PATHS ${CMOCKA_PATH}/include
DOC "Where the CMocka header can be found"
)
set(CMOCKA_INCLUDE_DIRS "${CMOCKA_INCLUDE_DIR}")
# Search for the CMocka library directory
find_library(CMOCKA_LIBRARY
NAMES cmocka
PATHS ${CMOCKA_PATH}/lib
DOC "Where the CMocka library can be found"
)
set(CMOCKA_LIBRARIES "${CMOCKA_LIBRARY}")
# Set CMOCKA_FOUND (if all required vars are found).
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CMocka DEFAULT_MSG CMOCKA_INCLUDE_DIRS CMOCKA_LIBRARIES)
# Hide variables from cmake GUIs.
mark_as_advanced(CMOCKA_PATH CMOCKA_INCLUDE_DIR CMOCKA_INCLUDE_DIRS CMOCKA_LIBRARY CMOCKA_LIBRARIES)
if(MSVC OR MSYS OR MINGW)
message("### SETUP FOR WINDOWS ###")
add_definitions(-DWINDOWS)
else()
message("### SETUP FOR UNIX ###")
add_definitions(-DUNIX)
endif()
add_subdirectory(src)
if (UNIT_TESTING)
find_package(cmocka 1.1.5 REQUIRED)
message(STATUS "CMOCKA_LIBRARIES: ${CMOCKA_LIBRARIES}")
include(AddCMockaTest)
add_subdirectory(tests)
endif()
# #######################################
# PROJECT SPECIFIC
# #######################################