summaryrefslogtreecommitdiffstats
path: root/dev/MinGfx/example/CMakeLists.txt
blob: 5aa7c874f8fef18a05a78d46bb7fee1413ae80b4 (plain) (blame)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Original Author(s) of this File: 
#   Daniel Keefe, 2017, University of Minnesota
#  
# Author(s) of Significant Updates/Modifications to the File:
#   ... 



# You are encouraged to copy this example, move it outside of the MinGfx directory, and use
# it as a starting point for your project.  When you do this, you'll have to edit the
# following line as needed to point to the MinGfx install prefix used on your system.

# !!!!!!!!!!!!! EDIT THE FOLLOWING LINE AS NEEDED !!!!!!!!!!!!! 
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../build/install ../../..)

# For example, you might have installed to a build tree that now looks like this:
# /Users/keefe/courses/cs4611/sw/include/MinGfx-1.0/
# /Users/keefe/courses/cs4611/sw/include/Eigen
# /Users/keefe/courses/cs4611/sw/include/nanogui
# /Users/keefe/courses/cs4611/sw/include/ etc.. 

# /Users/keefe/courses/cs4611/sw/lib/MinGfx-1.0/libMinGfx.a
# /Users/keefe/courses/cs4611/sw/lib/libnanogui.so
# /Users/keefe/courses/cs4611/sw/lib/ etc.. 

# If so, you would set the prefix path as follows:
#list(APPEND CMAKE_PREFIX_PATH /Users/keefe/courses/cs4611/sw)





#### BASIC PROJECT SETUP ####

project(mingfx-example)

# Using 3.9 to get a modern version of FindOpenGL.cmake
cmake_minimum_required (VERSION 3.9) 

# Dependencies that are auto-downloaded, built, and installed for you will go in the 
# directory pointed to by the CMAKE_INSTALL_PREFIX.  It defaults to a location inside
# the build directory.
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR "${CMAKE_INSTALL_PREFIX}" STREQUAL "")
    set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE )
endif()

# Add to paths cmake uses to search for scripts, modules, and config packages
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_INSTALL_PREFIX})
list(INSERT CMAKE_PREFIX_PATH 0 ${CMAKE_INSTALL_PREFIX})

include(MessageMacros)
h1("Building ${PROJECT_NAME}")
h2("Configuring paths")

message(STATUS "Module path: ${CMAKE_MODULE_PATH}")
message(STATUS "Prefix path: ${CMAKE_PREFIX_PATH}")
message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")



#### SOURCE FOR THIS PROJECT ####
h2("Configuring source files")

set(SOURCEFILES
  main-circleviewer.cpp
  CircleViewer.cpp
)

set(HEADERFILES
  CircleViewer.h
)

set(EXTRAFILES
#  README.md
)

set_source_files_properties(${EXTRAFILES} PROPERTIES HEADER_FILE_ONLY TRUE)



#### COMPILE OPTIONS ####

h2("Configuring Compiler Options")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")


message(STATUS "Building for " ${CMAKE_SYSTEM_NAME} ".")

# Linux specific
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  add_definitions(-DLINUX)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()


# Apple specific
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  add_definitions(-DOSX)

  # RPATH settings, see https://cmake.org/Wiki/CMake_RPATH_handling
  set(CMAKE_MACOSX_RPATH ON)

  # use, i.e. don't skip the full RPATH for the build tree
  SET(CMAKE_SKIP_BUILD_RPATH  FALSE)

  # when building, don't use the install RPATH already
  # (but later on when installing)
  SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) 

  SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

  # add the automatically determined parts of the RPATH
  # which point to directories outside the build tree to the install RPATH
  SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

  # the RPATH to be used when installing, but only if it's not a system directory
  LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
  IF("${isSystemDir}" STREQUAL "-1")
     SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
  ENDIF("${isSystemDir}" STREQUAL "-1")

endif()


# Windows specific
if (WIN32)
  add_definitions(-DWIN32)
endif()




#### DEFINE TARGET(S) ####

h2("Defining Target(s)")

add_executable(${PROJECT_NAME} ${SOURCEFILES} ${HEADERFILES} ${EXTRAFILES})



#### FIND AND ADD DEPENDENCIES ####

h2("Adding Dependencies")
set(EXTERNAL_DIR external)


# MinGfx (linked with an imported cmake target so no need to specify include dirs)
# This will try to find MinGfxConfig.cmake, which should have been installed under
# CMAKE_INSTALL_PREFIX/lib/cmake/MinGfx when you installed the MinGfx Toolkit.
find_package(MinGfx REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC MinGfx::MinGfx)

# Add external dependency on OpenGL
include(AutoBuildOpenGL)
AutoBuild_use_package_OpenGL(${PROJECT_NAME} PUBLIC)



#### INSTALL TARGET(S) ####

h2("Configuring Install Target")

# The install locations are relative to the CMAKE_INSTALL_PREFIX variable
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)