-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(cxx): improve project structure and simplify cmake scripts
- Remove unnecessary comments and sections - Use variables for project name and directories - Simplify test setup and discovery - Update build settings for better portability - Improve code organization and readability
- Loading branch information
Showing
2 changed files
with
26 additions
and
55 deletions.
There are no files selected for viewing
58 changes: 21 additions & 37 deletions
58
template/cxx/{{cookiecutter.project_slug}}/CMakeLists.txt
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 |
---|---|---|
@@ -1,72 +1,56 @@ | ||
# Specify the minimum version of CMake required | ||
cmake_minimum_required(VERSION 3.25) | ||
|
||
# Define the project | ||
project({{cookiecutter.project_slug}} | ||
VERSION {{cookiecutter.project_version}} | ||
DESCRIPTION "{{cookiecutter.project_desc}}" | ||
HOMEPAGE_URL "https://github.com/{{cookiecutter.__gh_slug}}" | ||
LANGUAGES CXX | ||
) | ||
|
||
# ===================== Build Settings ===================== | ||
|
||
# Add custom cmake modules path | ||
# Custom modules | ||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) | ||
|
||
# Set C++ standards | ||
# Build settings | ||
set(CMAKE_CXX_STANDARD {{cookiecutter.cxx_standard_version}}) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
|
||
# Set compile options | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Enable compile commands for clangd | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
|
||
# Set architecture for macOS (if applicable) | ||
if(APPLE) | ||
set(CMAKE_OSX_ARCHITECTURES "arm64") | ||
endif() | ||
|
||
# ===================== Output Directories ===================== | ||
# Build type configuration | ||
if(NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE Release) | ||
endif() | ||
|
||
# Use generator expressions for output directories | ||
# Set output directories | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}/bin>") | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}/lib>") | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}/lib>") | ||
|
||
# ===================== Source Files ===================== | ||
|
||
# Collect source files | ||
# Source files configuration | ||
set(SRC_DIR ${CMAKE_SOURCE_DIR}/src) | ||
set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include) | ||
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS | ||
${CMAKE_SOURCE_DIR}/src/*.cpp | ||
${SRC_DIR}/*.cpp | ||
) | ||
file(GLOB_RECURSE HEADERS CONFIGURE_DEPENDS | ||
${CMAKE_SOURCE_DIR}/include/*.h | ||
${INCLUDE_DIR}/*.h | ||
) | ||
|
||
# ===================== Library Target ===================== | ||
|
||
# Create library target | ||
add_library({{cookiecutter.package_name}}_lib ${SOURCES} ${HEADERS}) | ||
|
||
# Set include directories for the library | ||
target_include_directories({{cookiecutter.package_name}}_lib | ||
# Library target | ||
add_library(${PROJECT_NAME}_lib ${SOURCES} ${HEADERS}) | ||
target_include_directories(${PROJECT_NAME}_lib | ||
PUBLIC | ||
${CMAKE_SOURCE_DIR}/include | ||
) | ||
|
||
# ===================== Executable Target ===================== | ||
|
||
# Create executable target | ||
add_executable({{cookiecutter.project_slug}} ${CMAKE_SOURCE_DIR}/src/main.cpp) | ||
|
||
# Link library and CUDA libraries to the executable | ||
target_link_libraries({{cookiecutter.project_slug}} | ||
PRIVATE | ||
{{cookiecutter.package_name}}_lib | ||
$<BUILD_INTERFACE:${INCLUDE_DIR}> | ||
) | ||
|
||
# ===================== Tests ===================== | ||
# Executable target | ||
add_executable(${PROJECT_NAME} ${SRC_DIR}/main.cpp) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_lib) | ||
|
||
# Add tests subdirectory | ||
# Tests | ||
add_subdirectory(tests) |
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