|
2 | 2 | # Distributed under the GNU General Public License version 3
|
3 | 3 | # (http://www.gnu.org/licenses)
|
4 | 4 |
|
5 |
| -cmake_minimum_required(VERSION 3.8) |
6 | 5 |
|
7 |
| -# ------- config ------- |
8 | 6 |
|
9 |
| -set(PROJECT_NAME mnist_reader) |
10 |
| -set(PROJECT_VERSION 1.0) |
11 |
| -set(PROJECT_BRIEF "A C++ library to read the mnist dataset.") |
| 7 | +# ------------ cmake minimum version ------------ |
12 | 8 |
|
13 |
| -#bin or library |
14 |
| -set(PROJECT_TYPE library) |
| 9 | +cmake_minimum_required(VERSION 3.16.3) |
15 | 10 |
|
16 |
| -# ------- options ------- |
17 | 11 |
|
18 |
| -option(SHARED_LIBRARY "Type of the output library, shared if set to yes, static if not." OFF) |
19 | 12 |
|
20 |
| -option(BUILD_DOCS "Build documentation" OFF) |
| 13 | +# ------------------ metadatas------------------ |
21 | 14 |
|
22 |
| -option(BUILD_EXAMPLE "Build example" OFF) |
| 15 | +set(PROJECT_NAME "mnist_reader") |
| 16 | +set(PROJECT_VERSION 1.1) |
| 17 | +set(PROJECT_BRIEF "A simple c++ lib to read the mnist database.") |
23 | 18 |
|
24 |
| -# ---------------------- |
| 19 | + |
| 20 | +# -------------- type of output ----------------- |
| 21 | + |
| 22 | +# ----- (BINARY or LIBRARY) ----- |
| 23 | +set(PROJECT_TYPE "LIBRARY") |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +# ------------------- options ------------------- |
| 28 | + |
| 29 | +# ----- (DEBUG or RELEASE) ------ |
| 30 | +set(BUILD_MODE "RELEASE" CACHE STRING "Build mode, possible values are RELEASE and DEBUG.") |
| 31 | + |
| 32 | +if(PROJECT_TYPE STREQUAL "LIBRARY") |
| 33 | +# ----- (SHARED or STATIC) ------ |
| 34 | + set(LIBRARY_TYPE "STATIC" CACHE STRING "Type of the output library, possible values are SHARED and STATIC.") |
| 35 | +endif() |
| 36 | + |
| 37 | +# --------- (ON or OFF) --------- |
| 38 | +option(BUILD_DOC "Build documentation" OFF) |
| 39 | + |
| 40 | +# --------- (ON or OFF) --------- |
| 41 | +option(BUILD_EXAMPLES "Build example" OFF |
| 42 | + |
| 43 | +# --------- (ON or OFF) --------- |
| 44 | +option(MNIST_STATIC_CLASS "Use MnistReader as a static class" OFF) |
| 45 | + |
| 46 | +# --------- (ON or OFF) --------- |
| 47 | +option(MNIST_SUPER_CLASS "Use MnistReader as a super class" OFF) |
| 48 | + |
| 49 | +# --------- (ON or OFF) --------- |
| 50 | +option(C++_STATIC_LIB "Build with the C++ static library" OFF) |
| 51 | + |
| 52 | +# --------------- options feedback -------------- |
25 | 53 |
|
26 | 54 | message(${PROJECT_NAME} " building configuration start with the options :" )
|
27 |
| -if(PROJECT_TYPE STREQUAL "library") |
28 |
| - message("SHARED_LIBRARY : " ${SHARED_LIBRARY}) |
| 55 | +message("PROJECT_TYPE : " ${PROJECT_TYPE}) |
| 56 | +if(PROJECT_TYPE STREQUAL "LIBRARY") |
| 57 | + message("LIBRARY_TYPE : " ${LIBRARY_TYPE}) |
29 | 58 | endif()
|
30 |
| -message("BUILD_DOCS : " ${BUILD_DOCS}) |
31 |
| -message("BUILD_EXAMPLE : " ${BUILD_EXAMPLE}) |
32 |
| -message("You can change this using the -D option of cmake\n") |
| 59 | +message("BUILD_MODE : " ${BUILD_MODE}) |
| 60 | +message("BUILD_DOC : " ${BUILD_DOC}) |
| 61 | +message("BUILD_EXAMPLES : " ${BUILD_EXAMPLES}) |
| 62 | +message("MNIST_STATIC_CLASS : " ${MNIST_STATIC_CLASS}) |
| 63 | +message("MNIST_SUPER_CLASS : " ${MNIST_SUPER_CLASS}) |
| 64 | +message("C++_STATIC_LIB : " ${C++_STATIC_LIB}) |
33 | 65 |
|
34 |
| -# ---------------------- |
| 66 | +message("You can change this options using the -D option of cmake\n") |
35 | 67 |
|
36 |
| -project(${PROJECT_NAME} VERSION ${PROJECT_VERSION}) |
37 | 68 |
|
38 |
| -set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
39 | 69 |
|
40 |
| -add_subdirectory(src) |
| 70 | +# ------------ project configurations ----------- |
41 | 71 |
|
42 |
| -# ---------------------- |
| 72 | +# ---- C++ required standart ---- |
| 73 | +set(CMAKE_CXX_STANDARD 11) |
| 74 | +set(CMAKE_CXX_STANDARD_REQUIRED True) |
43 | 75 |
|
44 |
| -if (BUILD_DOCS) |
45 |
| - find_package(Doxygen) |
| 76 | +# ----- compilation options ----- |
| 77 | +ADD_COMPILE_OPTIONS(-O3 -Ofast -Wall -Wextra) |
| 78 | +if(BUILD_MODE STREQUAL "DEBUG") |
| 79 | + set(DEBUG CMAKE_CXX_FLAGS_DEBUG) |
| 80 | + add_compile_options(-g) |
| 81 | +else() |
| 82 | + set(RELEASE CMAKE_CXX_FLAGS_RELEASE) |
| 83 | +endif() |
| 84 | + |
| 85 | +if(C++_STATIC_LIB) |
| 86 | + add_compile_options(-static -static-libgcc -static-libstdc++) |
| 87 | +endif() |
| 88 | + |
| 89 | +if(MNIST_STATIC_CLASS) |
| 90 | + add_compile_options(-D MNIST_READER_STATIC_CLASS) |
| 91 | +endif() |
| 92 | + |
| 93 | +if(MNIST_SUPER_CLASS) |
| 94 | + add_compile_options(-D MNIST_READER_SUPER_CLASS) |
| 95 | +endif() |
| 96 | + |
| 97 | +# --------- project's name -------- |
| 98 | +set(INSTALL_DIR "${CMAKE_SOURCE_DIR}/${PROJECT_NAME}-${PROJECT_VERSION}") |
| 99 | + |
| 100 | +if(C++_STATIC_LIB) |
| 101 | + set(PROJECT_NAME "${PROJECT_NAME}-csl") |
| 102 | +endif() |
| 103 | + |
| 104 | +if(MNIST_STATIC_CLASS) |
| 105 | + set(PROJECT_NAME "${PROJECT_NAME}-stc") |
| 106 | +endif() |
| 107 | + |
| 108 | +if(MNIST_SUPER_CLASS) |
| 109 | + set(PROJECT_NAME "${PROJECT_NAME}-suc") |
46 | 110 | endif()
|
47 | 111 |
|
48 |
| -if (DOXYGEN_FOUND AND BUILD_DOCS) |
49 |
| - add_subdirectory(docs) |
| 112 | +if(BUILD_MODE STREQUAL "DEBUG") |
| 113 | + set(PROJECT_NAME "${PROJECT_NAME}-d") |
| 114 | +endif() |
| 115 | + |
| 116 | +project(${PROJECT_NAME} VERSION ${PROJECT_VERSION}) |
| 117 | + |
| 118 | +# -- default installation folder -- |
| 119 | +set(CMAKE_INSTALL_PREFIX ${INSTALL_DIR}) |
| 120 | + |
| 121 | + |
| 122 | +# ---------------- subdirectories --------------- |
| 123 | + |
| 124 | +# ------ lib or binary config ----- |
| 125 | +add_subdirectory("src") |
| 126 | + |
| 127 | +# ----------- doc config ---------- |
| 128 | +if (BUILD_DOC) |
| 129 | + find_package(Doxygen) |
| 130 | + if (DOXYGEN_FOUND) |
| 131 | + add_subdirectory("doc") |
| 132 | + endif() |
50 | 133 | endif()
|
51 | 134 |
|
52 |
| -if (BUILD_EXAMPLE) |
53 |
| - add_subdirectory (example) |
| 135 | +# -------- examples config -------- |
| 136 | +if (BUILD_EXAMPLES) |
| 137 | + add_subdirectory("examples") |
54 | 138 | endif()
|
55 | 139 |
|
| 140 | +# ----------------------------------------------- |
0 commit comments