Commit 6d03890c by FritzFlorian

Initial CMake project setup.

Seperate library from other parts of project (samples, playground, testing, ...). We still are in one 'toplevel' cmake project, so we can for exmaple compile everything (library and playground) in debug mode, for simple development.
parents
# IDE
.idea
.idea/
# Build Output
/cmake-build-*/
cmake_minimum_required(VERSION 3.13)
project(predictable_parallel_patterns
VERSION 0.0.1
DESCRIPTION "predictable parallel patterns for scalable smart systems using work stealing")
set(CMAKE_CXX_STANDARD 11)
# seperate library and test/example executable output paths.
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
# specific setup code is located in individual files.
include(cmake/DisabelInSource.cmake)
include(cmake/SetupOptimizationLevel.cmake)
include(cmake/SetupThreadingSupport.cmake)
# make our internal cmake script collection avaliable in the build process.
list(APPEND CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR}/cmake")
# Include external libraries within the project structure (prefered, as no instalation is reqired).
# Each library has an own CMakeLists.txt that should make it avaliabale as a library target,
# thus allowing one to include it as any cmake dependency later on.
add_subdirectory(extern/catch2)
# Include all internal subprojects (library, examples, testing).
add_subdirectory(lib/pls)
add_subdirectory(app/playground)
\ No newline at end of file
# P³LS³
**P**redictable **P**arallel **P**atterns **L**ibrary for **S**calable **S**mart **S**ystems
## Project Structure
The project uses [CMAKE](https://cmake.org/) as it's build system,
the recommended IDE is either a simple text editor or [CLion](https://www.jetbrains.com/clion/).
We divide the project into subtargets to separate for the library
itself, testing and example code. The library itself can be found in
`lib/pls`, testing related code is in `test`, example and playground
apps are in `app`.
\ No newline at end of file
add_executable(playground main.cpp)
# Example for adding the library to your app (as a cmake project dependency)
target_link_libraries(playground pls)
\ No newline at end of file
// Headers are available because we added the pls target
#include <pls/library.h>
int main() {
// All interfaces are scoped in the pls namespace...
// ...explicitly name it...
pls::hello();
// ...or use the namespace...
using namespace pls;
hello();
}
#################################################################################
# disable in-source builds to prevent source tree corruption.
# this REQUIRES the user to build in a seperate directory (not the project root).
#################################################################################
if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "
FATAL: In-source builds are not allowed.
You should create a separate directory for build files.
")
endif()
\ No newline at end of file
#################################################################################
# Setup compiler flags to enable or disable optimization
# By default: Release with -O3, Debug -O0
#################################################################################
# make sure a build type is set, default to release
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
message("-- Using Build Type: " ${CMAKE_BUILD_TYPE})
# Enable optimizations in release builds
if(CMAKE_BUILD_TYPE STREQUAL "Release")
# Link time optimization
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
# -O2 is often seen as 'the most speed',
# but inlining functions and SIMD/Vectorization is
# only enabled by -O3, thus it's way faster in some
# array calculations.
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
endif()
\ No newline at end of file
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
\ No newline at end of file
add_library(catch2 INTERFACE)
target_include_directories(catch2 INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
\ No newline at end of file
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
# List all required files here (cmake best practice to NOT automate this step!)
add_library(pls STATIC
src/library.cpp include/pls/library.h)
# Add everything in `./include` to be in the include path of this project
target_include_directories(pls
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src # TODO: Set this up when we require private headers
)
# Add cmake dependencies here if needed
target_link_libraries(pls
Threads::Threads # pthread support
)
# Rules for istalling the library on a system
# ...binaries
install(TARGETS pls
LIBRARY
DESTINATION lib
ARCHIVE
DESTINATION lib
)
# ...all headers in `include`
INSTALL (
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION include
FILES_MATCHING PATTERN "*.h*"
)
# Enable warnings/tidy code checking from our compiler
target_compile_options(pls PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall>
$<$<CXX_COMPILER_ID:MSVC>:
-W4>)
\ No newline at end of file
#ifndef PLS_LIBRARY_H
#define PLS_LIBRARY_H
namespace pls {
void hello();
}
#endif
\ No newline at end of file
#include "pls/library.h"
#include <iostream>
namespace pls {
void hello() {
std::cout << "Hello from PLS!" << std::endl;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment