Browse code

Add project

Robert Cranston authored on 05/04/2021 16:43:56
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,176 @@
1
+## CMake
2
+cmake_minimum_required(VERSION 3.14)
3
+
4
+
5
+## Project
6
+set(PROJECT_NAME glfbo3d)
7
+if ("${CMAKE_PROJECT_NAME}" STREQUAL "${PROJECT_NAME}")
8
+    return()
9
+endif()
10
+project(${PROJECT_NAME}
11
+    VERSION 1.0.0
12
+    LANGUAGES CXX
13
+)
14
+set(CXX_STANDARD          11)
15
+set(CXX_STANDARD_REQUIRED ON)
16
+set(CXX_EXTENSIONS        OFF)
17
+
18
+
19
+## Packages
20
+find_package(OpenGL REQUIRED)
21
+find_package(GLEW REQUIRED)
22
+find_package(glm REQUIRED)
23
+
24
+
25
+## External projects
26
+include(FetchContent)
27
+FetchContent_Declare(glshader
28
+    GIT_REPOSITORY https://git.rcrnstn.net/rcrnstn/glshader
29
+)
30
+FetchContent_Declare(gltest
31
+    GIT_REPOSITORY https://git.rcrnstn.net/rcrnstn/gltest
32
+)
33
+FetchContent_MakeAvailable(
34
+    glshader
35
+    gltest
36
+)
37
+
38
+
39
+## Main target
40
+add_library(${PROJECT_NAME}
41
+    src/${PROJECT_NAME}.cpp
42
+    include/${PROJECT_NAME}.hpp
43
+)
44
+set_property(TARGET ${PROJECT_NAME} PROPERTY PUBLIC_HEADER
45
+    include/${PROJECT_NAME}.hpp
46
+)
47
+target_include_directories(${PROJECT_NAME}
48
+    PUBLIC
49
+        $<INSTALL_INTERFACE:include>
50
+        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
51
+    PRIVATE
52
+        src
53
+)
54
+target_link_libraries(${PROJECT_NAME}
55
+    PUBLIC
56
+        OpenGL::GL
57
+        GLEW::GLEW
58
+)
59
+
60
+
61
+if ("${CMAKE_PROJECT_NAME}" STREQUAL "${PROJECT_NAME}")
62
+
63
+
64
+    ## Test target
65
+    add_executable(${PROJECT_NAME}-test
66
+        tests/${PROJECT_NAME}.cpp
67
+    )
68
+    target_include_directories(${PROJECT_NAME}-test
69
+        PRIVATE
70
+            tests
71
+    )
72
+    target_link_libraries(${PROJECT_NAME}-test
73
+        PRIVATE
74
+            ${PROJECT_NAME}
75
+            OpenGL::GL
76
+            GLEW::GLEW
77
+            glm
78
+            glshader
79
+            gltest
80
+    )
81
+    add_test(
82
+        NAME    ${PROJECT_NAME}-test
83
+        COMMAND ${PROJECT_NAME}-test
84
+        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
85
+    )
86
+
87
+
88
+    ## Default build type for single-configuration generators
89
+    if (NOT CMAKE_BUILD_TYPE)
90
+        set(CMAKE_BUILD_TYPE Debug)
91
+    endif()
92
+
93
+
94
+    ## Language tools and options
95
+    set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
96
+    find_program(CPPCHECK             cppcheck)
97
+    find_program(CLANG_TIDY           clang-tidy)
98
+    find_program(INCLUDE_WHAT_YOU_USE include-what-you-use)
99
+    if(CPPCHECK)
100
+        set(CXX_CPPCHECK ${CPPCHECK} --enable=warning,style --error-exitcode=1)
101
+    endif()
102
+    if(CLANG_TIDY)
103
+        set(CXX_CLANG_TIDY ${CLANG_TIDY})
104
+    endif()
105
+    if(INCLUDE_WHAT_YOU_USE)
106
+        set(CXX_INCLUDE_WHAT_YOU_USE ${INCLUDE_WHAT_YOU_USE})
107
+    endif()
108
+    if (MSVC)
109
+        set(COMPILE_OPTIONS
110
+            /permissive-
111
+            /WX
112
+            /W4
113
+        )
114
+    elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|.*Clang")
115
+        set(COMPILE_OPTIONS
116
+            -pedantic
117
+            -Werror -Wfatal-errors
118
+            -Wall -Wextra
119
+            -Wconversion -Wsign-conversion
120
+            -Wdouble-promotion
121
+            -Wimplicit-fallthrough
122
+            -Wvla
123
+            -Wzero-as-null-pointer-constant
124
+            -Weffc++
125
+        )
126
+        set(SANITIZE_OPTIONS
127
+            $<$<CONFIG:Debug>:-fsanitize=address,leak,undefined>
128
+        )
129
+        list(APPEND COMPILE_OPTIONS ${SANITIZE_OPTIONS})
130
+        list(APPEND LINK_OPTIONS    ${SANITIZE_OPTIONS})
131
+    endif()
132
+    include(CheckIPOSupported)
133
+    check_ipo_supported(RESULT INTERPROCEDURAL_OPTIMIZATION)
134
+    get_directory_property(BUILDSYSTEM_TARGETS BUILDSYSTEM_TARGETS)
135
+    set_target_properties(
136
+        ${BUILDSYSTEM_TARGETS}
137
+        PROPERTIES
138
+            CXX_STANDARD             "${CXX_STANDARD}"
139
+            CXX_STANDARD_REQUIRED    "${CXX_STANDARD_REQUIRED}"
140
+            CXX_EXTENSIONS           "${CXX_EXTENSIONS}"
141
+            CXX_CPPCHECK             "${CXX_CPPCHECK}"
142
+            CXX_CLANG_TIDY           "${CXX_CLANG_TIDY}"
143
+            CXX_INCLUDE_WHAT_YOU_USE "${CXX_INCLUDE_WHAT_YOU_USE}"
144
+            COMPILE_OPTIONS          "${COMPILE_OPTIONS}"
145
+            LINK_OPTIONS             "${LINK_OPTIONS}"
146
+            INTERPROCEDURAL_OPTIMIZATION
147
+                "${INTERPROCEDURAL_OPTIMIZATION}"
148
+    )
149
+
150
+
151
+    ## Testing
152
+    include(CTest)
153
+
154
+
155
+    ## Packaging and installing
156
+    include(CPack)
157
+    install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME})
158
+    include(GNUInstallDirs)
159
+    set(CMAKE_INSTALL_CMAKEDIR ${CMAKE_INSTALL_LIBDIR}/cmake
160
+        CACHE PATH "System CMake package config files"
161
+    )
162
+    install(EXPORT ${PROJECT_NAME}
163
+        FILE ${PROJECT_NAME}Config.cmake
164
+        DESTINATION ${CMAKE_INSTALL_CMAKEDIR}/${PROJECT_NAME}
165
+    )
166
+    include(CMakePackageConfigHelpers)
167
+    write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake
168
+        COMPATIBILITY SameMajorVersion
169
+    )
170
+    install(
171
+        FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
172
+        DESTINATION ${CMAKE_INSTALL_CMAKEDIR}/${PROJECT_NAME}
173
+    )
174
+
175
+
176
+endif()