-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GHI #11 Setup CMake for building project
- Loading branch information
Showing
6 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
include(cmake/util/PreventInSourceBuilds.cmake) | ||
|
||
project( | ||
patomic | ||
VERSION 0.5.1 | ||
DESCRIPTION "Portable C90 Atomics Library" | ||
HOMEPAGE_URL "https://github.com/doodspav/patomic" | ||
LANGUAGES C | ||
) | ||
|
||
# don't change include order, OptionVariables checks if project is top level | ||
include(cmake/util/ProjectIsTopLevel.cmake) | ||
include(cmake/util/OptionVariables.cmake) | ||
|
||
|
||
# ---- Declare Library ---- | ||
|
||
add_library( | ||
patomic_patomic | ||
# include | ||
include/patomic/patomic.h | ||
# src | ||
src/patomic.c | ||
) | ||
|
||
# alias to cause error at configuration time instead of link time if target is missing | ||
add_library(patomic::patomic ALIAS patomic_patomic) | ||
|
||
|
||
# ---- Generate Build Info Headers ---- | ||
|
||
# used in export header generated below | ||
if(NOT BUILD_SHARED_LIBS) | ||
target_compile_definitions(patomic_patomic PUBLIC PATOMIC_STATIC_DEFINE) | ||
endif() | ||
|
||
include(GenerateExportHeader) | ||
generate_export_header( | ||
patomic_patomic | ||
BASE_NAME patomic | ||
EXPORT_FILE_NAME include/patomic/patomic_export.h | ||
) | ||
|
||
|
||
# ---- Library Properties ---- | ||
|
||
set_target_properties( | ||
patomic_patomic PROPERTIES | ||
C_VISIBILITY_PRESET hidden | ||
VISIBILITY_INLINES_HIDDEN YES | ||
VERSION "${PROJECT_VERSION}" | ||
SOVERSION "${PROJECT_VERSION_MAJOR}" | ||
EXPORT_NAME patomic | ||
OUTPUT_NAME patomic | ||
) | ||
|
||
# header files generated by CMake | ||
target_include_directories( | ||
patomic_patomic SYSTEM | ||
PUBLIC | ||
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>" | ||
) | ||
|
||
# header files from /include | ||
target_include_directories( | ||
patomic_patomic ${warning_guard} | ||
PUBLIC | ||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>" | ||
) | ||
|
||
target_compile_features(patomic_patomic PUBLIC c_std_90) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# ---- Developer Mode ---- | ||
|
||
# Developer mode enables targets and code paths in the CMake scripts that are | ||
# only relevant for the developer(s) of patomic. | ||
# Targets necessary to build the project must be provided unconditionally, so | ||
# that consumers can trivially build and package the project. | ||
if(PROJECT_IS_TOP_LEVEL) | ||
option(patomic_DEVELOPER_MODE "Enable developer mode" OFF) | ||
option(BUILD_SHARED_LIBS "Build shared libs" OFF) | ||
endif() | ||
|
||
|
||
# ---- Warning Guard ---- | ||
|
||
# target_include_directories with SYSTEM modifier will request the compiler to | ||
# omit warnings from the provided paths, if the compiler supports that. | ||
# This is to provide a user experience similar to find_package when | ||
# add_subdirectory or FetchContent is used to consume this project. | ||
set(warning_guard "") | ||
if(NOT PROJECT_IS_TOP_LEVEL) | ||
option( | ||
patomic_INCLUDES_WITH_SYSTEM | ||
"Use SYSTEM modifier for patomic's includes, disabling warnings" | ||
ON | ||
) | ||
mark_as_advanced(patomic_INCLUDES_WITH_SYSTEM) | ||
if(patomic_INCLUDES_WITH_SYSTEM) | ||
set(warning_guard SYSTEM) | ||
endif() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# in-source build guard | ||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) | ||
message( | ||
FATAL_ERROR | ||
"In-source builds are not supported. " | ||
"Please read the BUILDING document before trying to build this project. " | ||
"You may need to delete 'CMakeCache.txt' and 'CMakeFiles/' first." | ||
) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# this variable is set by project() in CMake 3.21+ | ||
string( | ||
COMPARE EQUAL | ||
"${CMAKE_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}" | ||
PROJECT_IS_TOP_LEVEL | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef PATOMIC_PATOMIC_H | ||
#define PATOMIC_PATOMIC_H | ||
|
||
#include <patomic/patomic_export.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
|
||
PATOMIC_EXPORT int | ||
patomic_example_add( | ||
int a, | ||
int b | ||
); | ||
|
||
|
||
#ifdef __cplusplus | ||
} /* extern "C" */ | ||
#endif | ||
|
||
#endif /* PATOMIC_PATOMIC_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <patomic/patomic.h> | ||
|
||
|
||
PATOMIC_EXPORT int | ||
patomic_example_add( | ||
int a, | ||
int b | ||
) | ||
{ | ||
return a + b; | ||
} |