-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
96 lines (84 loc) · 3.08 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
cmake_minimum_required(VERSION 2.8)
project(cghw2)
# Force C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Force C99
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
function(find_path_of_file ARG_VAR RELATIVE_PATH DESC ARG_FILE)
math(EXPR argn ${ARGC}-1)
set(FIND_EXPR)
foreach(index RANGE 3 ${argn})
list(GET ARGV ${index} current)
set(FIND_EXPR ${FIND_EXPR} ${current})
endforeach()
if(NOT ${ARG_VAR})
file(GLOB_RECURSE ${ARG_VAR}_TMP ${FIND_EXPR})
if(${ARG_VAR}_TMP)
list(LENGTH ${ARG_VAR}_TMP l_count)
if(${l_count} GREATER 1)
set(${ARG_VAR} "" CACHE PATH "")
message(FATAL_ERROR "There are multiple copies of a library, please specify the path for ${DESC}.")
else()
get_filename_component(${ARG_VAR}_PATH ${${ARG_VAR}_TMP} DIRECTORY)
get_filename_component(${ARG_VAR} ${${ARG_VAR}_PATH}/${RELATIVE_PATH} ABSOLUTE)
set(${ARG_VAR} ${${ARG_VAR}} PARENT_SCOPE)
message(STATUS "${DESC} is found in ${${ARG_VAR}}")
endif()
else()
set(${ARG_VAR} "" CACHE PATH "")
message(FATAL_ERROR "${DESC} not found, please specify the path or put it inside the ext/ folder.")
endif()
else()
message(STATUS "${DESC} is found in ${${ARG_VAR}}")
endif()
endfunction()
find_path_of_file(GLEW_PATH "./" "GLEW_PATH" "${CMAKE_SOURCE_DIR}/ext/glew.pc.in")
find_path_of_file(GLFW_PATH "../../" "GLFW_PATH" "${CMAKE_SOURCE_DIR}/ext/glfw3.h")
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "")
set(GLFW_BUILD_TESTS OFF CACHE BOOL "")
add_subdirectory(${GLFW_PATH})
find_path_of_file(GLM_PATH "../" "GLM_PATH" "${CMAKE_SOURCE_DIR}/ext/glm.hpp")
set(TINYOBJLOADER_PATH "ext/tinyobjloader")
set(LODEPNG_PATH "ext/lodepng")
project(glew)
set(GLEW_SOURCE ${GLEW_PATH}/src/glew.c)
add_library(glew ${GLEW_SOURCE})
target_include_directories(glew PRIVATE ${GLEW_PATH}/include)
target_compile_definitions(glew PRIVATE GLEW_STATIC)
project(tinyobjloader)
set(TOL ${TINYOBJLOADER_PATH}/tiny_obj_loader.cc)
add_library(tinyobjloader ${TOL})
project(lodepng)
set(LPNG ${LODEPNG_PATH}/lodepng.cpp)
add_library(lodepng ${LPNG})
target_include_directories(lodepng PRIVATE ${LODEPNG_PATH})
# cghw2
project(cghw2)
file(GLOB SOURCE_FILES "*.cpp" "*.h")
add_executable(cghw2 ${SOURCE_FILES})
target_include_directories(cghw2 PRIVATE ${GLFW_PATH}/include)
target_include_directories(cghw2 PRIVATE ${GLM_PATH})
target_include_directories(cghw2 PRIVATE ${GLEW_PATH}/include)
target_include_directories(cghw2 PRIVATE ${TINYOBJLOADER_PATH})
target_include_directories(cghw2 PRIVATE ${LODEPNG_PATH})
target_compile_definitions(cghw2 PRIVATE GLEW_STATIC)
target_link_libraries(cghw2 glew)
target_link_libraries(cghw2 glfw)
if(WIN32)
target_link_libraries(cghw2 opengl32)
endif()
if(UNIX AND NOT APPLE)
target_link_libraries(cghw2 GL)
endif()
if(APPLE)
target_link_libraries(cghw2 "-framework OpenGL")
target_link_libraries(cghw2 "-framework Cocoa")
target_link_libraries(cghw2 "-framework IOKit")
target_link_libraries(cghw2 "-framework CoreVideo")
endif()
target_link_libraries(cghw2 tinyobjloader)
target_link_libraries(cghw2 lodepng)