Skip to content
Permalink
Browse files

Add cmake support for setting up fray

Included download and example setup script for CMake project. Not yet
tested with C::B, but should work on Windows.
  • Loading branch information...
deyan-hadzhiev committed Mar 22, 2018
1 parent f17548f commit 5d90e6e0a7f2e86a78cb02f6b80f0c1248cc9b3e
Showing with 111 additions and 3 deletions.
  1. +3 −0 .gitignore
  2. +39 −0 cmake/CMakeLists.txt
  3. +15 −0 cmake/sdl.cmake
  4. +29 −0 scripts/download_cmake_win.sh
  5. +3 −3 scripts/sdl_win.sh
  6. +22 −0 scripts/setup_cmake_win.sh
@@ -51,5 +51,8 @@ Release/
# Visual Studio Code:
.vs/

# CMake project directory
develop/

# Screenshots:
fray_*.bmp
@@ -0,0 +1,39 @@

cmake_minimum_required(VERSION 3.4)

include(./sdl.cmake)

project(fray)

set (HEADERS
../src/bitmap.h
../src/camera.h
../src/color.h
../src/constants.h
../src/geometry.h
../src/main.h
../src/matrix.h
../src/sdl.h
../src/shading.h
../src/util.h
../src/vector.h
)

set (SOURCES
../src/bitmap.cpp
../src/camera.cpp
../src/geometry.cpp
../src/main.cpp
../src/matrix.cpp
../src/sdl.cpp
../src/shading.cpp
)

add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
target_link_libraries(${PROJECT_NAME} ${SDL_LIB})

# add custom command for copying the SDL dll to the binary dir
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_PROPERTY:SDL,DLL_FILE_LIST> $<TARGET_FILE_DIR:${PROJECT_NAME}>
)
@@ -0,0 +1,15 @@

set(SDL_LIB SDL)
add_library(${SDL_LIB} STATIC IMPORTED)

if (WIN32)
set_target_properties(${SDL_LIB} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${CMAKE_CURRENT_SOURCE_DIR}/../SDK/SDL/include"
)

set_target_properties(${SDL_LIB} PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/../SDK/SDL/lib/x64/SDL.lib")
set_target_properties(${SDL_LIB} PROPERTIES DLL_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../SDK/SDL/lib/x64/SDL.dll")
else ()
# TODO: test
find_package(SDL REQUIRED)
endif ()
@@ -0,0 +1,29 @@
#!/bin/sh

if [ -z $BASH_SOURCE ]; then
echo "ERROR \$BASH_SOURCE is required"
exit 1
fi

BASH_DIR=$(dirname $BASH_SOURCE)
SDK_DIR=$BASH_DIR/../SDK

if [ ! -d $SDK_DIR ]; then
mkdir -p $SDK_DIR
fi

echo ">> Downloading cmake 3.10 into $SDK_DIR"
curl https://cmake.org/files/v3.10/cmake-3.10.3-win64-x64.zip --output $SDK_DIR/cmake.zip

if [ $? -ne 0 ]; then
echo ">> ERROR: cURL failed to download CMake archive"
else

echo ">> Extracting CMake in $SDK_DIR/cmake"
# unzip doesn't handle relative paths well
unzip -q -u $SDK_DIR/cmake.zip -d $SDK_DIR

mv -T $SDK_DIR/cmake-3.10.3-win64-x64 $SDK_DIR/cmake

rm $SDK_DIR/cmake.zip
fi
@@ -16,14 +16,14 @@ echo ">> Downloading SDL 1.2 into $SDK_DIR"
curl https://www.libsdl.org/release/SDL-devel-1.2.15-VC.zip --output $SDK_DIR/sdl.zip

if [ $? -ne 0 ]; then
echo ">> ERROR: cURL failed to download SDL sdk"
echo ">> ERROR: cURL failed to download SDL archive"
else

echo ">> Extracting SDL sdk in $SDK_DIR/SDL"
# unzip doesn't handle relative paths well
unzip -u $SDK_DIR/sdl.zip -d $SDK_DIR
unzip -q -u $SDK_DIR/sdl.zip -d $SDK_DIR

mv $SDK_DIR/SDL-1.2.15 $SDK_DIR/SDL
mv -T $SDK_DIR/SDL-1.2.15 $SDK_DIR/SDL

rm $SDK_DIR/sdl.zip
fi
@@ -0,0 +1,22 @@
#!/bin/sh

if [ -z $BASH_SOURCE ]; then
echo "ERROR \$BASH_SOURCE is required"
exit 1
fi

FRAY_DIR=$(cd $(dirname $BASH_SOURCE)/.. && pwd)

echo $FRAY_DIR

if [ ! -d $FRAY_DIR/develop ]; then
mkdir $FRAY_DIR/develop
fi

# change workdir, because cmake generates project files in its current directory
pushd $FRAY_DIR/develop

# call cmake (the generator can be changed - probably with user interaction?)
$FRAY_DIR/SDK/cmake/bin/cmake.exe -G "Visual Studio 15 2017 Win64" $FRAY_DIR/cmake

popd

0 comments on commit 5d90e6e

Please sign in to comment.
You can’t perform that action at this time.