Skip to content

Commit 4391c24

Browse files
committed
added FindSDL2.cmake updated build
1 parent da14780 commit 4391c24

File tree

4 files changed

+247
-7
lines changed

4 files changed

+247
-7
lines changed

CMakeLists.txt

+18-6
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,42 @@ endif()
2525
if(WIN32)
2626

2727
elseif(UNIX)
28-
find_package(OpenAL REQUIRED)
29-
find_library(Vulkan REQUIRED)
30-
find_package(Bullet REQUIRED)
3128

3229
include_directories("HatchitCore/include"
3330
"HatchitCore/include/linux"
3431
"HatchitCore/source/inline"
3532
"HatchitGraphics/include"
3633
"HatchitGraphics/include/vulkan"
34+
"HatchitGame/include"
35+
"HatchitGame/include/sdl"
3736
SYSTEM
3837
"ThirdParty/inih/"
3938
"ThirdParty/cppformat/cppformat"
4039
"ThirdParty/json/src/"
4140
"ThirdParty/stb")
4241

42+
# Collect all Hatchit Core source and include
43+
file(GLOB HT_CORE_INC HatchitCore/include/*.h)
4344
file(GLOB HT_CORE_SRC HatchitCore/source/*.cpp HatchitCore/source/linux/*.cpp ThirdParty/inih/*.c ThirdParty/cppformat/cppformat/*.cc)
44-
#file(GLOB HT_GRAPHICS_SRC HatchitGraphics/source/*.cpp)
45+
46+
# Collect all Hatchit Graphics source and include
47+
file(GLOB HT_GRAPHICS_INC HatchitGraphics/include/*.h HatchitGraphics/include/vulkan/*.h)
48+
file(GLOB HT_GRAPHICS_SRC HatchitGraphics/source/*.cpp HatchitGraphics/source/vulkan/*.cpp)
49+
50+
# Collect all Hatchit Game source and include
51+
file(GLOB HT_GAME_INC HatchitGame/include/*.h HatchitGame/include/sdl/*.h)
52+
file(GLOB HT_GAME_SRC HatchitGame/source/*.cpp HatchitGame/source/sdl/*.cpp)
4553

4654
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
4755

48-
add_library(HatchitCore SHARED ${HT_CORE_SRC})
49-
#add_library(HatchitGraphics SHARED ${HT_GRAPHICS_SRC})
56+
add_library(HatchitCore SHARED ${HT_CORE_INC} ${HT_CORE_SRC})
57+
add_library(HatchitGraphics SHARED ${HT_GRAPHICS_INC} ${HT_GRAPHICS_SRC})
58+
add_library(HatchitGame SHARED ${HT_GAME_INC} ${HT_GAME_SRC})
59+
5060
target_compile_definitions(HatchitCore PRIVATE FMT_EXPORT)
5161

62+
target_link_libraries(HatchitGame HatchitCore HatchitGraphics)
63+
5264
endif()
5365

5466
add_subdirectory(HatchitTest)

HatchitGame

Submodule HatchitGame updated 56 files

cmake/FindGLFW3.cmake

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Locate the glfw library
2+
# This module defines the following variables:
3+
# GLFW_LIBRARY, the name of the library;
4+
# GLFW_INCLUDE_DIR, where to find glfw include files.
5+
# GLFW_FOUND, true if both the GLFW_LIBRARY and GLFW_INCLUDE_DIR have been found.
6+
#
7+
# To help locate the library and include file, you could define an environment variable called
8+
# GLFW_ROOT which points to the root of the glfw library installation. This is pretty useful
9+
# on a Windows platform.
10+
#
11+
#
12+
# Usage example to compile an "executable" target to the glfw library:
13+
#
14+
# FIND_PACKAGE (glfw REQUIRED)
15+
# INCLUDE_DIRECTORIES (${GLFW_INCLUDE_DIR})
16+
# ADD_EXECUTABLE (executable ${EXECUTABLE_SRCS})
17+
# TARGET_LINK_LIBRARIES (executable ${GLFW_LIBRARY})
18+
#
19+
# TODO:
20+
# Allow the user to select to link to a shared library or to a static library.
21+
22+
#Search for the include file...
23+
FIND_PATH(GLFW_INCLUDE_DIRS GLFW/glfw3.h DOC "Path to GLFW include directory."
24+
HINTS
25+
$ENV{GLFW_ROOT}
26+
PATH_SUFFIX include #For finding the include file under the root of the glfw expanded archive, typically on Windows.
27+
PATHS
28+
/usr/include/
29+
/usr/local/include/
30+
# By default headers are under GLFW subfolder
31+
/usr/include/GLFW
32+
/usr/local/include/GLFW
33+
${GLFW_ROOT_DIR}/include/ # added by ptr
34+
)
35+
36+
SET(GLFW_LIB_NAMES libglfw3.a glfw3 glfw GLFW3.lib)
37+
38+
FIND_LIBRARY(GLFW_LIBRARIES DOC "Absolute path to GLFW library."
39+
NAMES ${GLFW_LIB_NAMES}
40+
HINTS
41+
$ENV{GLFW_ROOT}
42+
PATH_SUFFIXES lib/win32 #For finding the library file under the root of the glfw expanded archive, typically on Windows.
43+
PATHS
44+
/usr/local/lib
45+
/usr/lib
46+
${GLFW_ROOT_DIR}/lib-msvc100/release # added by ptr
47+
)
48+
IF( APPLE )
49+
find_library(IOKIT NAMES IOKit)
50+
#find_library(OpenGL NAMES OpenGL)
51+
find_library(COREVIDEO NAMES CoreVideo)
52+
find_library(COCOA NAMES Cocoa)
53+
SET(GLFW_LIBRARIES ${GLFW_LIBRARIES} ${IOKIT} ${COREVIDEO} ${COCOA})
54+
endif( APPLE )
55+
56+
IF(GLFW_LIBRARIES AND GLFW_INCLUDE_DIRS)
57+
SET(GLFW_FOUND TRUE)
58+
message(STATUS "Found GLFW3: ${GLFW_LIBRARIES}")
59+
ELSE()
60+
message(STATUS "GLFW3 NOT found!")
61+
ENDIF(GLFW_LIBRARIES AND GLFW_INCLUDE_DIRS)
62+
63+
#if(GLFW_FOUND)
64+
# MARK_AS_ADVANCED(GLFW_INCLUDE_DIRS GLFW_LIBRARIES)
65+
#endif(GLFW_FOUND)

cmake/FindSDL2.cmake

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# Locate SDL2 library
2+
# This module defines
3+
# SDL2_LIBRARY, the name of the library to link against
4+
# SDL2_FOUND, if false, do not try to link to SDL2
5+
# SDL2_INCLUDE_DIR, where to find SDL.h
6+
#
7+
# This module responds to the the flag:
8+
# SDL2_BUILDING_LIBRARY
9+
# If this is defined, then no SDL2main will be linked in because
10+
# only applications need main().
11+
# Otherwise, it is assumed you are building an application and this
12+
# module will attempt to locate and set the the proper link flags
13+
# as part of the returned SDL2_LIBRARY variable.
14+
#
15+
# Don't forget to include SDLmain.h and SDLmain.m your project for the
16+
# OS X framework based version. (Other versions link to -lSDL2main which
17+
# this module will try to find on your behalf.) Also for OS X, this
18+
# module will automatically add the -framework Cocoa on your behalf.
19+
#
20+
#
21+
# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration
22+
# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library
23+
# (SDL2.dll, libsdl2.so, SDL2.framework, etc).
24+
# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again.
25+
# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
26+
# as appropriate. These values are used to generate the final SDL2_LIBRARY
27+
# variable, but when these values are unset, SDL2_LIBRARY does not get created.
28+
#
29+
#
30+
# $SDL2DIR is an environment variable that would
31+
# correspond to the ./configure --prefix=$SDL2DIR
32+
# used in building SDL2.
33+
# l.e.galup 9-20-02
34+
#
35+
# Modified by Eric Wing.
36+
# Added code to assist with automated building by using environmental variables
37+
# and providing a more controlled/consistent search behavior.
38+
# Added new modifications to recognize OS X frameworks and
39+
# additional Unix paths (FreeBSD, etc).
40+
# Also corrected the header search path to follow "proper" SDL guidelines.
41+
# Added a search for SDL2main which is needed by some platforms.
42+
# Added a search for threads which is needed by some platforms.
43+
# Added needed compile switches for MinGW.
44+
#
45+
# On OSX, this will prefer the Framework version (if found) over others.
46+
# People will have to manually change the cache values of
47+
# SDL2_LIBRARY to override this selection or set the CMake environment
48+
# CMAKE_INCLUDE_PATH to modify the search paths.
49+
#
50+
# Note that the header path has changed from SDL2/SDL.h to just SDL.h
51+
# This needed to change because "proper" SDL convention
52+
# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
53+
# reasons because not all systems place things in SDL2/ (see FreeBSD).
54+
55+
#=============================================================================
56+
# Copyright 2003-2009 Kitware, Inc.
57+
#
58+
# Distributed under the OSI-approved BSD License (the "License");
59+
# see accompanying file Copyright.txt for details.
60+
#
61+
# This software is distributed WITHOUT ANY WARRANTY; without even the
62+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
63+
# See the License for more information.
64+
#=============================================================================
65+
# (To distribute this file outside of CMake, substitute the full
66+
# License text for the above reference.)
67+
68+
SET(SDL2_SEARCH_PATHS
69+
~/Library/Frameworks
70+
/Library/Frameworks
71+
/usr/local
72+
/usr
73+
/sw # Fink
74+
/opt/local # DarwinPorts
75+
/opt/csw # Blastwave
76+
/opt
77+
)
78+
79+
FIND_PATH(SDL2_INCLUDE_DIR SDL.h
80+
HINTS
81+
$ENV{SDL2DIR}
82+
PATH_SUFFIXES include/SDL2 include
83+
PATHS ${SDL2_SEARCH_PATHS}
84+
)
85+
86+
FIND_LIBRARY(SDL2_LIBRARY_TEMP
87+
NAMES SDL2
88+
HINTS
89+
$ENV{SDL2DIR}
90+
PATH_SUFFIXES lib64 lib
91+
PATHS ${SDL2_SEARCH_PATHS}
92+
)
93+
94+
IF(NOT SDL2_BUILDING_LIBRARY)
95+
IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
96+
# Non-OS X framework versions expect you to also dynamically link to
97+
# SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
98+
# seem to provide SDL2main for compatibility even though they don't
99+
# necessarily need it.
100+
FIND_LIBRARY(SDL2MAIN_LIBRARY
101+
NAMES SDL2main
102+
HINTS
103+
$ENV{SDL2DIR}
104+
PATH_SUFFIXES lib64 lib
105+
PATHS ${SDL2_SEARCH_PATHS}
106+
)
107+
ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
108+
ENDIF(NOT SDL2_BUILDING_LIBRARY)
109+
110+
# SDL2 may require threads on your system.
111+
# The Apple build may not need an explicit flag because one of the
112+
# frameworks may already provide it.
113+
# But for non-OSX systems, I will use the CMake Threads package.
114+
IF(NOT APPLE)
115+
FIND_PACKAGE(Threads)
116+
ENDIF(NOT APPLE)
117+
118+
# MinGW needs an additional library, mwindows
119+
# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows
120+
# (Actually on second look, I think it only needs one of the m* libraries.)
121+
IF(MINGW)
122+
SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
123+
ENDIF(MINGW)
124+
125+
IF(SDL2_LIBRARY_TEMP)
126+
# For SDL2main
127+
IF(NOT SDL2_BUILDING_LIBRARY)
128+
IF(SDL2MAIN_LIBRARY)
129+
SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP})
130+
ENDIF(SDL2MAIN_LIBRARY)
131+
ENDIF(NOT SDL2_BUILDING_LIBRARY)
132+
133+
# For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
134+
# CMake doesn't display the -framework Cocoa string in the UI even
135+
# though it actually is there if I modify a pre-used variable.
136+
# I think it has something to do with the CACHE STRING.
137+
# So I use a temporary variable until the end so I can set the
138+
# "real" variable in one-shot.
139+
IF(APPLE)
140+
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa")
141+
ENDIF(APPLE)
142+
143+
# For threads, as mentioned Apple doesn't need this.
144+
# In fact, there seems to be a problem if I used the Threads package
145+
# and try using this line, so I'm just skipping it entirely for OS X.
146+
IF(NOT APPLE)
147+
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
148+
ENDIF(NOT APPLE)
149+
150+
# For MinGW library
151+
IF(MINGW)
152+
SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP})
153+
ENDIF(MINGW)
154+
155+
# Set the final string here so the GUI reflects the final state.
156+
SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found")
157+
# Set the temp variable to INTERNAL so it is not seen in the CMake GUI
158+
SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
159+
ENDIF(SDL2_LIBRARY_TEMP)
160+
161+
INCLUDE(FindPackageHandleStandardArgs)
162+
163+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)

0 commit comments

Comments
 (0)