should work if we compile it together on the AMD machin in the cloud
This commit is contained in:
98
CMakeLists.txt
Normal file
98
CMakeLists.txt
Normal file
@@ -0,0 +1,98 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
# -----------------------------
|
||||
# Force Clang before project()
|
||||
# -----------------------------
|
||||
if(NOT DEFINED CMAKE_C_COMPILER)
|
||||
set(CMAKE_C_COMPILER clang CACHE STRING "" FORCE)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED CMAKE_CXX_COMPILER)
|
||||
set(CMAKE_CXX_COMPILER clang++ CACHE STRING "" FORCE)
|
||||
endif()
|
||||
|
||||
# -----------------------------
|
||||
# Project setup
|
||||
# -----------------------------
|
||||
project(learning-hip LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
|
||||
# -----------------------------
|
||||
# System dependency: libsodium
|
||||
# -----------------------------
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Dependencies (vendored)
|
||||
# -----------------------------
|
||||
add_subdirectory(external/spdlog)
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Executable
|
||||
# -----------------------------
|
||||
add_executable(${PROJECT_NAME} src/main.cpp)
|
||||
|
||||
# -----------------------------
|
||||
# Auto-discover include dirs under src/
|
||||
# -----------------------------
|
||||
file(GLOB_RECURSE SRC_SUBDIRS LIST_DIRECTORIES true
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/*"
|
||||
)
|
||||
|
||||
set(SRC_INCLUDES "")
|
||||
foreach(dir ${SRC_SUBDIRS})
|
||||
if(IS_DIRECTORY ${dir})
|
||||
list(APPEND SRC_INCLUDES ${dir})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# -----------------------------
|
||||
# Auto-discover all .cpp except main.cpp
|
||||
# -----------------------------
|
||||
file(GLOB_RECURSE ALL_CPP
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
|
||||
)
|
||||
|
||||
list(REMOVE_ITEM ALL_CPP
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp"
|
||||
)
|
||||
|
||||
# -----------------------------
|
||||
# Apply sources and includes
|
||||
# -----------------------------
|
||||
target_compile_definitions(learning-hip PRIVATE __HIP_PLATFORM_AMD__=1)
|
||||
target_sources(${PROJECT_NAME} PRIVATE ${ALL_CPP})
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${SRC_INCLUDES}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/hip # vendored HIP headers
|
||||
)
|
||||
|
||||
# -----------------------------
|
||||
# Link libraries
|
||||
# -----------------------------
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
spdlog::spdlog
|
||||
amdhip64 # HIP runtime only
|
||||
)
|
||||
|
||||
# -----------------------------
|
||||
# Compiler warnings (Clang / GCC)
|
||||
# -----------------------------
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wconversion
|
||||
-Wshadow
|
||||
-Wnull-dereference
|
||||
-Wdouble-promotion
|
||||
)
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user