Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
rawbby authored and Robert Andreas Fritsch committed Jan 15, 2024
0 parents commit a87e835
Show file tree
Hide file tree
Showing 29 changed files with 382 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/ctest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: CMake on multiple platforms

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false

matrix:
os: [ ubuntu-latest, windows-latest ]
build_type: [ Release, Debug ]
c_compiler: [ gcc, clang, cl ]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl

steps:
- uses: actions/checkout@v3

- name: Set reusable strings
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Configure CMake
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DBUILD_TESTING=ON
-S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ctest --build-config ${{ matrix.build_type }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
cmake-build-*/
4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/simplecmake.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.5)

# setup project
set(PROJECT_NAME "vk")
project(${PROJECT_NAME} LANGUAGES CXX)

# inc all cmake util
include(cmake/all.cmake)

# add project components
add_libraries_directory(core)
add_executables_directory(tool)
add_tests_directory(test)
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
C(LEAN)MAKE
===========
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
C(LEAN)MAKE
===========

Project skeleton for less verbose CMake scripts.
Creates tree new ```add_directory``` commands that create magic directories.

```cmake
add_libraries_directory(<dir>)
add_executables_directory(<dir>)
add_tests_directory(<dir>)
```

add_libraries_directory(dir)
----------------------------

The libraries directory contains only libraries. Each subdirectory with a target.cmake file marks a library root.
A library is either static library or a header only library depending on the presence of a src directory. (src/ -> static_library)

In the target.cmake file the library target can be configured. The target is already created with the name ```${TARGET_NAME}```.

add_executables_directory(dir)
------------------------------

...

add_tests_directory(dir)
------------------------

...
40 changes: 40 additions & 0 deletions cmake/add_executables_directory.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function(add_executables_directory EXECUTABLES_REL_DIR)

file(GLOB_RECURSE TARGET_PATHS "${EXECUTABLES_REL_DIR}/**/target.cmake")
foreach (TARGET_PATH ${TARGET_PATHS})

get_filename_component(TARGET_ABS_PATH "${TARGET_PATH}" ABSOLUTE)
get_filename_component(TARGET_ABS_DIR "${TARGET_ABS_PATH}" DIRECTORY)
file(RELATIVE_PATH TARGET_REL_DIR "${CMAKE_CURRENT_LIST_DIR}/${EXECUTABLES_REL_DIR}" ${TARGET_ABS_DIR})

set(TARGET_NAME "${TARGET_REL_DIR}")

foreach (LOWER_LETTER a b c d e f g h i j k l m n o p q r s t u v w x y z)
string(TOUPPER ${LOWER_LETTER} UPPER_LETTER)
string(REGEX REPLACE "${UPPER_LETTER}" "${LOWER_LETTER}" TARGET_NAME ${TARGET_NAME})
endforeach ()

string(REPLACE "-" "_" TARGET_NAME ${TARGET_NAME})
string(REPLACE " " "_" TARGET_NAME ${TARGET_NAME})
string(REPLACE "/" "_" TARGET_NAME ${TARGET_NAME})
string(REPLACE "\\" "_" TARGET_NAME ${TARGET_NAME})

file(GLOB_RECURSE TARGET_SOURCE
"${TARGET_ABS_DIR}/src/*.hpp"
"${TARGET_ABS_DIR}/src/*.cpp")

add_executable(${TARGET_NAME})
target_sources(${TARGET_NAME} PRIVATE ${TARGET_SOURCE})

set_target_properties(${TARGET_NAME} PROPERTIES
LINKER_LANGUAGE CXX
CXX_STANDARD 20
CXX_STANDARD_REQUIRED ON)

include("${TARGET_ABS_PATH}")

message("${PROJECT_NAME} - Added Executable ${TARGET_NAME}")

endforeach ()

endfunction()
51 changes: 51 additions & 0 deletions cmake/add_libraries_directory.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
function(add_libraries_directory LIBRARIES_REL_DIR)

file(GLOB_RECURSE TARGET_PATHS "${LIBRARIES_REL_DIR}/**/target.cmake")
foreach (TARGET_PATH ${TARGET_PATHS})

get_filename_component(TARGET_ABS_PATH "${TARGET_PATH}" ABSOLUTE)
get_filename_component(TARGET_ABS_DIR "${TARGET_ABS_PATH}" DIRECTORY)
file(RELATIVE_PATH TARGET_REL_DIR "${CMAKE_CURRENT_LIST_DIR}/${LIBRARIES_REL_DIR}" ${TARGET_ABS_DIR})

set(TARGET_NAME "${TARGET_REL_DIR}")

foreach (LOWER_LETTER a b c d e f g h i j k l m n o p q r s t u v w x y z)
string(TOUPPER ${LOWER_LETTER} UPPER_LETTER)
string(REGEX REPLACE "${UPPER_LETTER}" "${LOWER_LETTER}" TARGET_NAME ${TARGET_NAME})
endforeach ()

string(REPLACE "-" "_" TARGET_NAME ${TARGET_NAME})
string(REPLACE " " "_" TARGET_NAME ${TARGET_NAME})
string(REPLACE "/" "_" TARGET_NAME ${TARGET_NAME})
string(REPLACE "\\" "_" TARGET_NAME ${TARGET_NAME})

file(GLOB_RECURSE TARGET_HEADER
"${TARGET_ABS_DIR}/inc/*.hpp")

file(GLOB_RECURSE TARGET_SOURCE
"${TARGET_ABS_DIR}/src/*.hpp"
"${TARGET_ABS_DIR}/src/*.cpp")

if (TARGET_SOURCE)
add_library(${TARGET_NAME} STATIC)
target_sources(${TARGET_NAME} PUBLIC ${TARGET_HEADER})
target_sources(${TARGET_NAME} PRIVATE ${TARGET_SOURCE})
else ()
add_library(${TARGET_NAME} INTERFACE)
target_sources(${TARGET_NAME} INTERFACE ${TARGET_HEADER})
endif ()

target_include_directories(${TARGET_NAME} INTERFACE "${TARGET_ABS_DIR}/inc")

set_target_properties(${TARGET_NAME} PROPERTIES
LINKER_LANGUAGE CXX
CXX_STANDARD 20
CXX_STANDARD_REQUIRED ON)

include("${TARGET_ABS_PATH}")

message("${PROJECT_NAME} - Added Library ${TARGET_NAME}")

endforeach ()

endfunction()
45 changes: 45 additions & 0 deletions cmake/add_python_directory.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/.venv")
execute_process("python -m venv ${PROJECT_SOURCE_DIR}/.venv")
endif()

function(add_python_directory PYTHON_REL_DIR)

file(GLOB_RECURSE TARGET_PATHS "${PYTHON_REL_DIR}/**/target.cmake")
foreach (TARGET_PATH ${TARGET_PATHS})

get_filename_component(TARGET_ABS_PATH "${TARGET_PATH}" ABSOLUTE)
get_filename_component(TARGET_ABS_DIR "${TARGET_ABS_PATH}" DIRECTORY)
file(RELATIVE_PATH TARGET_REL_DIR "${CMAKE_CURRENT_LIST_DIR}/${LIBRARIES_REL_DIR}" ${TARGET_ABS_DIR})

set(TARGET_NAME "${TARGET_REL_DIR}")

foreach (LOWER_LETTER a b c d e f g h i j k l m n o p q r s t u v w x y z)
string(TOUPPER ${LOWER_LETTER} UPPER_LETTER)
string(REGEX REPLACE "${UPPER_LETTER}" "${LOWER_LETTER}" TARGET_NAME ${TARGET_NAME})
endforeach ()

string(REPLACE "-" "_" TARGET_NAME ${TARGET_NAME})
string(REPLACE " " "_" TARGET_NAME ${TARGET_NAME})
string(REPLACE "/" "_" TARGET_NAME ${TARGET_NAME})
string(REPLACE "\\" "_" TARGET_NAME ${TARGET_NAME})

# TODO

set(TARGET_BUILD_PY "${TARGET_ABS_DIR}/src/build.py")
set(TARGET_GENERATE_PY "${TARGET_ABS_DIR}/src/generate.py")

add_library(${TARGET_NAME} STATIC)
target_sources(${TARGET_NAME} PUBLIC ${TARGET_HEADER})

target_include_directories(${TARGET_NAME} INTERFACE "${TARGET_ABS_DIR}/inc")

set_target_properties(${TARGET_NAME} PROPERTIES
LINKER_LANGUAGE CXX
CXX_STANDARD 20
CXX_STANDARD_REQUIRED ON)

include("${TARGET_ABS_PATH}")

endforeach()

endfunction()
58 changes: 58 additions & 0 deletions cmake/add_tests_directory.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
option(BUILD_TESTING "Build Tests" OFF)
if (BUILD_TESTING)
enable_testing()
endif ()

function(add_tests_directory TESTS_REL_DIR)

if (BUILD_TESTING)

get_filename_component(TESTS_ABS_PATH "${TESTS_REL_DIR}" ABSOLUTE)

file(GLOB_RECURSE TARGET_PATHS "${TESTS_REL_DIR}/*.cpp")
foreach (TARGET_PATH ${TARGET_PATHS})

get_filename_component(TARGET_ABS_PATH "${TARGET_PATH}" ABSOLUTE)
get_filename_component(TARGET_ABS_DIR "${TARGET_ABS_PATH}" DIRECTORY)
file(RELATIVE_PATH TARGET_REL_DIR "${TESTS_ABS_PATH}" ${TARGET_ABS_DIR})

get_filename_component(TARGET_NAME "${TARGET_PATH}" NAME_WE)
set(TARGET_NAME "test_${TARGET_REL_DIR}_${TARGET_NAME}")

foreach (LOWER_LETTER a b c d e f g h i j k l m n o p q r s t u v w x y z)
string(TOUPPER ${LOWER_LETTER} UPPER_LETTER)
string(REGEX REPLACE "${UPPER_LETTER}" "${LOWER_LETTER}" TARGET_NAME ${TARGET_NAME})
endforeach ()

string(REPLACE "." "_" TARGET_NAME ${TARGET_NAME})
string(REPLACE "-" "_" TARGET_NAME ${TARGET_NAME})
string(REPLACE " " "_" TARGET_NAME ${TARGET_NAME})
string(REPLACE "/" "_" TARGET_NAME ${TARGET_NAME})
string(REPLACE "\\" "_" TARGET_NAME ${TARGET_NAME})

add_executable(${TARGET_NAME} "${TARGET_ABS_PATH}")
set_target_properties(${TARGET_NAME} PROPERTIES
LINKER_LANGUAGE CXX
CXX_STANDARD 20
CXX_STANDARD_REQUIRED ON)

set(TARGET_REL_DIR_PART ${TARGET_REL_DIR})
while (TARGET_REL_DIR_PART)

file(GLOB TARGET_CONFIG_PATH "${TESTS_ABS_PATH}/${TARGET_REL_DIR_PART}/config.cmake")
if (TARGET_CONFIG_PATH)
include(${TARGET_CONFIG_PATH})
endif ()

get_filename_component(TARGET_REL_DIR_PART "${TARGET_REL_DIR_PART}" DIRECTORY)
endwhile ()

add_test(NAME "${TARGET_NAME}" COMMAND $<TARGET_FILE:${TARGET_NAME}>)

message("${PROJECT_NAME} - Added Test ${TARGET_NAME}")

endforeach ()

endif ()

endfunction()
11 changes: 11 additions & 0 deletions cmake/all.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
message("${PROJECT_NAME} - Added CMake Script all.cmake")

# inc all cmake files from the cmake directory
file(GLOB_RECURSE INCLUDES "cmake/*.cmake")
foreach (INCLUDE ${INCLUDES})
get_filename_component(INCLUDE_NAME "${INCLUDE}" NAME)
if (NOT INCLUDE_NAME STREQUAL "all.cmake")
include(${INCLUDE})
message("${PROJECT_NAME} - Added CMake Script ${INCLUDE_NAME}")
endif ()
endforeach ()
4 changes: 4 additions & 0 deletions cmake/cxx20.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(_IGNORE_CMAKE_C_COMPILER "${CMAKE_C_COMPILER}")

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
3 changes: 3 additions & 0 deletions cmake/normalise_output_directories.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
12 changes: 12 additions & 0 deletions core/scenegraph/inc/scenegraph/scenegraph.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef SAMPLE_HPP
#define SAMPLE_HPP

namespace w {

class SceneGraph {
public:
};

}

#endif
Empty file added core/scenegraph/target.cmake
Empty file.
12 changes: 12 additions & 0 deletions core/test_util/inc/test_util.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef TEST_UTIL_HPP
#define TEST_UTIL_HPP

#include <cstdlib>

inline void trivial_assert(bool condition) {
if (!condition) {
std::exit(1);
}
}

#endif
Empty file added core/test_util/target.cmake
Empty file.
1 change: 1 addition & 0 deletions test/sample/config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target_link_libraries(${TARGET_NAME} PRIVATE test_util scenegraph)
5 changes: 5 additions & 0 deletions test/sample/sample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <sample/sample.hpp>
#include <test_util.hpp>

int main() {
}
Loading

0 comments on commit a87e835

Please sign in to comment.