-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
132 lines (108 loc) · 4.47 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
cmake_minimum_required(VERSION 3.22)
project(simulake
VERSION 0.1.0
DESCRIPTION "simulate physics using cellular automata"
LANGUAGES CXX C)
# options
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# source files
file(GLOB_RECURSE SOURCE_FILES
${CMAKE_SOURCE_DIR}/src/*.c
${CMAKE_SOURCE_DIR}/src/*.cpp)
# header files
file(GLOB_RECURSE HEADER_FILES
${CMAKE_SOURCE_DIR}/src/*.h
${CMAKE_SOURCE_DIR}/src/*.hpp)
# submodule dependencies
set(VENDOR_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib")
# shaders
set(SHADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/shaders")
set(SHADER_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/shaders")
file(COPY ${SHADER_DIR} DESTINATION ${CMAKE_BINARY_DIR})
file(MAKE_DIRECTORY "${SHADER_BUILD_DIR}")
add_custom_target(copy_shaders ALL)
# add a custom command to copy assets when they change
add_custom_command(
TARGET copy_shaders
COMMAND ${CMAKE_COMMAND} -E copy_directory "${SHADER_DIR}" "${SHADER_BUILD_DIR}"
DEPENDS "${SHADER_DIR}"
COMMENT "Copying shaders to build directory")
# main executable
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)
target_precompile_headers(${PROJECT_NAME} PRIVATE ${HEADER_FILES})
target_compile_definitions(${PROJECT_NAME} PRIVATE "DEBUG=$<IF:$<CONFIG:Debug>,1,0>")
target_compile_definitions(${PROJECT_NAME} PRIVATE "ENABLE_PROFILING=$<IF:$<CONFIG:Release>,0,1>")
# opengl
find_package(OpenGL REQUIRED)
target_include_directories(${PROJECT_NAME} PRIVATE ${OPENGL_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES})
# threads
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} Threads::Threads)
# threadpool impl
target_include_directories(${PROJECT_NAME} PRIVATE ${VENDOR_DIR}/)
# openmp
if(APPLE)
# NOTE(vir): toggle next line to install libomp using brew
# execute_process(COMMAND brew install libomp)
execute_process (
COMMAND brew --prefix libomp
OUTPUT_VARIABLE HOMEBREW_LIBOMP_PREFIX
)
string(STRIP ${HOMEBREW_LIBOMP_PREFIX} HOMEBREW_LIBOMP_PREFIX)
message(STATUS "homebrew OpenMP found: " ${HOMEBREW_LIBOMP_PREFIX})
# set openmp paths
set(OpenMP_LIBRARIES ${HOMEBREW_LIBOMP_PREFIX}/lib)
set(OpenMP_INCLUDES ${HOMEBREW_LIBOMP_PREFIX}/include)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(OpenMP_C "${CMAKE_C_COMPILER}" CACHE STRING "" FORCE)
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -lomp -Wno-unused-command-line-argument" CACHE STRING "" FORCE)
set(OpenMP_C_LIB_NAMES "omp" CACHE STRING "" FORCE)
set(OpenMP_omp_LIBRARY ${OpenMP_C_LIB_NAMES} CACHE STRING "" FORCE)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(OpenMP_CXX "${CMAKE_CXX_COMPILER}" CACHE STRING "" FORCE)
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -lomp -Wno-unused-command-line-argument" CACHE STRING "" FORCE)
set(OpenMP_CXX_LIB_NAMES "omp" CACHE STRING "" FORCE)
set(OpenMP_omp_LIBRARY ${OpenMP_CXX_LIB_NAMES} CACHE STRING "" FORCE)
endif()
endif()
find_package(OpenMP REQUIRED)
target_include_directories(${PROJECT_NAME} PRIVATE ${OpenMP_INCLUDES})
target_link_directories(${PROJECT_NAME} PRIVATE ${OpenMP_LIBRARIES})
target_link_libraries(${PROJECT_NAME} OpenMP::OpenMP_CXX)
# glm
add_subdirectory(${VENDOR_DIR}/glm/)
target_include_directories(${PROJECT_NAME} PRIVATE ${VENDOR_DIR}/glm/)
# glad
add_subdirectory(${VENDOR_DIR}/glad/)
target_include_directories(${PROJECT_NAME} PRIVATE ${VENDOR_DIR}/glad/include/)
target_link_libraries(${PROJECT_NAME} glad)
# glfw
option(GLFW_BUILD_DOCS OFF)
option(GLFW_BUILD_EXAMPLES OFF)
option(GLFW_BUILD_TESTS OFF)
option(GLFW_INSTALL OFF)
add_subdirectory(${VENDOR_DIR}/glfw/)
target_include_directories(${PROJECT_NAME} PRIVATE ${VENDOR_DIR}/glfw/include/)
target_link_libraries(${PROJECT_NAME} glfw)
# cxxopts
add_subdirectory(${VENDOR_DIR}/cxxopts/)
target_include_directories(${PROJECT_NAME} PRIVATE ${VENDOR_DIR}/cxxopts/include/)
target_link_libraries(${PROJECT_NAME} cxxopts)
# benchmark
# include(FetchContent)
# set(BENCHMARK_DOWNLOAD_DEPENDENCIES ON)
# FetchContent_Declare(benchmark
# GIT_REPOSITORY https://github.com/google/benchmark.git
# GIT_TAG v1.7.0)
# FetchContent_MakeAvailable(benchmark)
# target_link_libraries(${PROJECT_NAME} benchmark::benchmark)
# opencl
find_package(OpenCL REQUIRED)
target_include_directories(${PROJECT_NAME} PRIVATE ${OpenCL_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${OpenCL_LIBRARY})