- CamelCase or snake_case. Function names start with uppercase, variable names start with lowercase. Follow PyTorch conventions where applicable.
├── ProjectName
│ ├── CMakeLists.txt
│ ├── include
│ │ └── ProjectName
│ │ ├── xxx.h
│ │ └── xxx2.h
│ └── src
│ ├── xxx.cpp
│ └── xxx2.cpp
Each subproject is packaged as a static library:
file(GLOB_RECURSE srcs CONFIGURE_DEPENDS src/*.cpp include/*.h)
add_library(ProjectName STATIC ${srcs})
target_include_directories(ProjectName PUBLIC include)- Template functions must be implemented in .h files — implementing them in .cpp will cause linker errors.
- Standalone (non-member) functions implemented in headers must be marked
inlineto avoid multiple-definition errors.
#pragma once
namespace ProjectName {
void FunctionName();
}- Should not contain additional internal includes. Long functions should be declared in .h and implemented in .cpp.
#include <ProjectName/ModuleName.h>
namespace ProjectName {
void FunctionName() { /* implementation */ }
}Sets default build type, C++ standard, and adds all subprojects:
cmake_minimum_required(VERSION 3.18)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake;${CMAKE_MODULE_PATH}")
project(SEC-PPDL LANGUAGES CXX)
add_subdirectory(Datatype)
add_subdirectory(HE)
add_subdirectory(Operator)
add_subdirectory(Layer)
add_subdirectory(Test)Example structure:
├── LinearLayer
│ ├── CMakeLists.txt
│ ├── include
│ │ └── LinearLayer
│ │ ├── Conv.h
│ │ └── DWConv.h
│ └── src
│ ├── Conv.cpp
│ └── DWConv.cpp
In Conv.h, reference DWConv.h directly with the project namespace:
#include <LinearLayer/DWConv.h>
LinearLayer::DWConv dwconv;To use HE in LinearLayer, include and use with namespace:
#include <HE/HE.h>
HE::HE he;Also add the dependency in CMakeLists.txt (HE must be compiled before LinearLayer):
target_link_libraries(LinearLayer PUBLIC HE)