-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
120 lines (95 loc) · 3.51 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
cmake_minimum_required(VERSION 3.0)
project(graphics-engine CXX C)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
file(GLOB_RECURSE SOURCES src/*.cpp src/*.h)
list(REMOVE_ITEM SOURCES ${PROJECT_SOURCE_DIR}/src/main.cpp)
file(GLOB_RECURSE SOURCES_TEST tests/*.cpp tests/*.h)
# Find all required packages
find_package(PkgConfig REQUIRED)
find_package(OpenGL REQUIRED)
find_package(Freetype REQUIRED)
find_package(SOIL REQUIRED)
find_package(glm REQUIRED)
find_package(Bullet)
find_package(Threads)
pkg_search_module(GLFW REQUIRED glfw3)
pkg_search_module(ASSIMP REQUIRED assimp)
pkg_search_module(GLEW REQUIRED glew)
#
# copy recourses into build dir
add_custom_target(copy-runtime-files ALL
COMMAND cmake -E copy_directory ${CMAKE_SOURCE_DIR}/resources ${CMAKE_BINARY_DIR}/resources
DEPENDS render)
# compiler and linker options
set(PROJECT_LIBRARIES
${OPENGL_LIBRARIES}
${GLFW_LIBRARIES}
${GLFW_STATIC_LIBRARIES}
${GLEW_LIBRARIES}
${FREETYPE_LIBRARIES}
${ASSIMP_LIBRARIES}
${SOIL_LIBRARIES}
${BULLET_LIBRARIES}
${THREADS_LIBRARIES}
)
set(PROJECT_INCLUDE_DIRS
"src"
"src/include"
"/usr/include"
"/usr/include/freetype2"
"/usr/include/freetype2/freetype"
${FREETYPE_INCLUDE_DIRS}
${SOIL_INCLUDE_DIR}
${BULLET_INCLUDE_DIRS}
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
link_directories(${GLEW_LIBRARY_DIRS})
# compile & link target
add_executable(render ${SOURCES} src/main.cpp)
SET_TARGET_PROPERTIES(render PROPERTIES
INSTALL_RPATH "${INSTALL_RPATH};${GLEW_LIBRARY_DIRS};${ASSIMP_LIBRARY_DIRS}"
BUILD_WITH_INSTALL_RPATH TRUE)
target_include_directories(render PUBLIC ${PROJECT_INCLUDE_DIRS})
target_link_libraries(render PUBLIC ${PROJECT_LIBRARIES})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # for clang++
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
# dont use libc++ for now
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -stdlib=libc++")
#target_link_libraries(render PUBLIC c++abi) # use libc++
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # for g++
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") # for intel c++ compiler
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") # for visual studio c++
endif()
###
### Unit testing using Google test
###
set(EXTERNAL_PROJECTS_DIR ${PROJECT_SOURCE_DIR}/external)
set(PROJECT_TEST_NAME unit_tests)
add_subdirectory(${EXTERNAL_PROJECTS_DIR}/gtest)
enable_testing()
add_executable(${PROJECT_TEST_NAME} ${SOURCES_TEST} ${SOURCES})
SET_TARGET_PROPERTIES(${PROJECT_TEST_NAME} PROPERTIES
INSTALL_RPATH "${INSTALL_RPATH};${GLEW_LIBRARY_DIRS};${ASSIMP_LIBRARY_DIRS}"
BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
target_include_directories(${PROJECT_TEST_NAME} PUBLIC
${PROJECT_INCLUDE_DIRS}
${GTEST_INCLUDE_DIRS}
tests
)
# removing some libraries, we are mocking them :)
list(REMOVE_ITEM PROJECT_LIBRARIES ${GLEW_LIBRARIES})
# add google test and link that shit
add_dependencies(${PROJECT_TEST_NAME} googletest)
target_link_libraries(${PROJECT_TEST_NAME}
${PROJECT_LIBRARIES}
${GTEST_LIBRARIES}
${GTEST_LIBS_DIR}/libgtest.a
${GTEST_LIBS_DIR}/libgtest_main.a
${GTEST_LIBS_DIR}/../libgmock.a
${GTEST_LIBS_DIR}/../libgmock_main.a
)
target_link_libraries(${PROJECT_TEST_NAME} ${CMAKE_THREAD_LIBS_INIT})
add_test(NAME ${PROJECT_TEST_NAME} COMMAND ${PROJECT_TEST_NAME})