Create a CMakeLists.txt file in the project root directory:
# Specify minimum required CMake Version
# HEaaN library requires version 3.21 or higher
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
# Project information setup
project(my-heaan-project
VERSION 1.0.0
DESCRIPTION "Project using HEaaN library"
LANGUAGES CXX)
# Include cmake modules
include(cmake/BuildType.cmake)
# C++ standard modules
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED Yes)
set(CMAKE_CXX_EXTENSIONTS no)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Set output directory path
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
# Find HEaaN library
find_package(HEaaN REQUIRED)
# Interface library setup
add_library(heaan INTERFACE)
target_link_libraries(heaan INTERFACE HEaaN::HEaaN)
# Add subdirectories
add_subdirectory(src)
# Add tests and examples (optional)
option(BUILD_TESTS "Build tests" OFF)
option(BUILD_EXAMPLES "Build examples" OFF)
if(BUILD_TESTS)
add_subdirectory(tests)
endif()
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
src/CMakeLists.txt
Create a CMakeLists.txt file in the src directory:
Copy
# Set source files
set(SOURCES
main.cpp
# Additional source files
)
# Include CUDA headers if needed
include_directories("/usr/local/cuda/include")
# Create executable
add_executable(my_program ${SOURCES}
cmake/BuildType.cmake
Create a BuildType.cmake file in the cmake directory:
# Set build type to 'Release' if not specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPE)
message(STATUS "Build type not specified. Setting to 'Release'.")
# Set possible build types
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif()
If you need more information, please refer the CMake official document.