-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
143 lines (120 loc) · 5.06 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
132
133
134
135
136
137
138
139
140
141
142
143
#######################################################################
# IMPORTANT SHORTCOMINGS OF THIS CMAKE CONFIG FOR VISUAL STUDIO USERS
#
# Visual Studio unfortunately defaults to overriding the working directory
# for Google Test set by CMAKE.
# To fix this
# go to Visual Studio's debug menu or tool menu,
# choose the "options" item, and then
# go to the "Test Adapter For GoogleTest" tab.
#
# Set 'Working Directory' to '$(SolutionDir)'
# (note, those are parenthesis around SolutionDir, and not braces
# as one might become accustomed to seeing in CMake).
#
#######################################################################
message("
*********************************************************************
IMPORTANT SHORTCOMINGS OF THIS CMAKE CONFIG FOR VISUAL STUDIO USERS
*********************************************************************
CMake fails to configure the working directory for running
tests in Visual Studio using Google Test.
Before running, got to Visual Studio's debug menu,
choose the 'options' item, and then go to the
'TestAdapterForGoogleTest' tab.
Set 'Working Directory' to '$(SolutionDir)'
(note, those are parenthesis around SolutionDir, and not braces
as one might become accustomed to seeing in CMake).
*********************************************************************
")
################## CMAKE Version ###########################
# Make sure we're using CMAKE 3.1 or higher, ideally the latest
# From https://cliutils.gitlab.io/modern-cmake/chapters/basics.html
############################################################
cmake_minimum_required(VERSION 3.14)
if(${CMAKE_VERSION} VERSION_LESS 3.15)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
cmake_policy(VERSION 3.15)
endif()
################# CMake Project ############################
# The main options of project #
############################################################
set(DICEKEY_LIBRARIES_PROJECT_NAME lib-read-dicekey)
project(${DICEKEY_LIBRARIES_PROJECT_NAME}
VERSION 0.10
DESCRIPTION "Libraries for working with DiceKeys and scanning images of them."
LANGUAGES CXX
)
# Define Release by default.
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
message(STATUS "Build type not specified: Use Release by default.")
endif(NOT CMAKE_BUILD_TYPE)
get_filename_component(DICEKEY_LIBRARIES_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
# set(ANDROID_ABI "x86_64" CACHE STRING "Default architecture to x86_64")
# Paths
message("${DICEKEY_LIBRARIES_PROJECT_NAME}: MAIN PROJECT CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}")
message("${DICEKEY_LIBRARIES_PROJECT_NAME}: MAIN PROJECT CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
message("${DICEKEY_LIBRARIES_PROJECT_NAME}: MAIN PROJECT CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}")
message("${DICEKEY_LIBRARIES_PROJECT_NAME}: MAIN PROJECT CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}")
####################################################
# External libraries to build
#
####################################################
# Ensure OpenCV is installed
include("extern/opencv.cmake")
####################################################
# Libraries to build
####################################################
add_subdirectory("lib-dicekey")
add_subdirectory("lib-read-dicekey")
#############################################################
# Testing
###########
#
# Must come after the libraries being tested
#
#############################################################
option(DICEKEY_CREATE_AND_RUN_TESTS "Create and run tests" False)
message("DICEKEY_CREATE_AND_RUN_TESTS=${DICEKEY_CREATE_AND_RUN_TESTS}")
if ("${DICEKEY_CREATE_AND_RUN_TESTS}" STREQUAL "True")
include(CTest)
enable_testing()
add_subdirectory(tests)
endif()
######################### Flags ############################
# Defines Flags for Windows and Linux #
############################################################
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
endif(NOT MSVC)
# Preprocessor definitions
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(${DICEKEY_LIBRARIES_PROJECT_NAME} PRIVATE
-D_DEBUG
-D_CONSOLE
)
if(MSVC)
target_compile_options(${DICEKEY_LIBRARIES_PROJECT_NAME} PRIVATE /W3 /Od /EHsc) # / Zi /MD
message("*************************************")
endif()
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
target_compile_definitions(${DICEKEY_LIBRARIES_PROJECT_NAME} PRIVATE
-DNDEBUG
-D_CONSOLE
)
if(MSVC)
target_compile_options(${DICEKEY_LIBRARIES_PROJECT_NAME} PRIVATE /W3 /GL /Oi /Gy /EHsc) # /Zi
endif()
endif()
########### Link & Dependencies ############################
# Add project dependencies and Link to project #
############################################################
if(MSVC)
# target_link_libraries(${DICEKEY_LIBRARIES_PROJECT_NAME} PRIVATE Ws2_32.lib )
endif(MSVC)