Skip to content

Instantly share code, notes, and snippets.

@roxlu
Created January 27, 2018 10:01
Show Gist options
  • Save roxlu/9c1301223472578f7b98d905411f629e to your computer and use it in GitHub Desktop.
Save roxlu/9c1301223472578f7b98d905411f629e to your computer and use it in GitHub Desktop.
Basic CMake for GLEW, GLFW, GLUT, GLM
cmake_minimum_required(VERSION 3.4)
include(ExternalProject)
set(bd ${CMAKE_CURRENT_LIST_DIR}/../)
set(sd ${bd}/src)
include_directories(
${sd}
${CMAKE_INSTALL_PREFIX}/include
)
ExternalProject_Add(
glm
GIT_REPOSITORY https://github.com/g-truc/glm.git
GIT_SHALLOW 1
UPDATE_COMMAND ""
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)
ExternalProject_Add(
glut
URL http://prdownloads.sourceforge.net/freeglut/freeglut-3.0.0.tar.gz
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DFREEGLUT_REPLACE_GLUT=0 -DFREEGLUT_BUILD_DEMOS=0 -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)
ExternalProject_Add(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw.git
GIT_SHALLOW 1
UPDATE_COMMAND ""
CMAKE_ARGS -DGLFW_BUILD_TESTS=Off -DGLFW_BUILD_DOCS=Off -DGLFW_BUILD_EXAMPLES=Off -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)
ExternalProject_Get_Property(glfw install_dir)
include_directories(${install_dir}/include)
if (UNIX)
list(APPEND libs ${CMAKE_INSTALL_PREFIX}/lib/libglfw3.a)
elseif(WIN32)
list(APPEND libs ${CMAKE_INSTALL_PREFIX}/lib/glfw3.lib)
endif()
ExternalProject_Add(
glew
URL https://sourceforge.net/projects/glew/files/glew/2.1.0/glew-2.1.0.tgz/download
UPDATE_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_COMMAND} <SOURCE_DIR>/build/cmake -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)
set(lib_sources
${sd}/bvh.cpp
${sd}/BVHLoader.cpp
${sd}/Phigs3DView.cpp
${sd}/quaternion.cpp
)
add_library(mocap STATIC ${lib_sources})
add_dependencies(mocap glm glut glfw glew)
add_executable(mocapplay ${sd}/main.cpp)
add_dependencies(mocapplay mocap)
install(TARGETS mocapplay DESTINATION bin)
target_link_libraries(mocapplay
X11
dl
Xxf86vm
Xrandr
pthread
dl
Xi
Xinerama
Xcursor
GLU
GL
${CMAKE_INSTALL_PREFIX}/lib64/libfreeglut.a
${CMAKE_INSTALL_PREFIX}/lib64/libGLEW.a
${libs}
mocap
)
#!/bin/sh
# Using gist: https://gist.github.com/roxlu/2ac1aa06222ef788f9df235a5b2fbf7c
d=${PWD}
bd=${d}/../
sd=${bd}/src/
id=${bd}/install
ed=${d}/../
rd=${d}/../reference/
d=${PWD}
is_debug="n"
build_dir="build_unix"
cmake_build_type="Release"
cmake_config="Release"
debug_flag=""
debugger=""
os_debugger=""
parallel_builds=""
cmake_generator=""
# Detect OS.
if [ "$(uname)" == "Darwin" ]; then
if [ "${cmake_generator}" = "" ] ; then
cmake_generator="Unix Makefiles"
fi
os="mac"
os_debugger="lldb"
parallel_builds="-j8"
elif [ "$(expr substr $(uname -s) 1 5)" = "Linux" ]; then
if [ "${cmake_generator}" = "" ] ; then
cmake_generator="Unix Makefiles"
fi
os="linux"
os_debugger="gdb"
parallel_builds="-j8"
else
if [ "${cmake_generator}" = "" ] ; then
cmake_generator="Visual Studio 15 2017 Win64"
build_dir="build_vs2017"
fi
os="win"
os_debugger="cdb"
parallel_builds="/verbosity:q /maxcpucount:8"
fi
# Detect Command Line Options
for var in "$@"
do
if [ "${var}" = "debug" ] ; then
is_debug="y"
cmake_build_type="Debug"
cmake_config="Debug"
debug_flag="_debug"
debugger="${os_debugger}"
elif [ "${var}" = "xcode" ] ; then
build_dir="build_xcode"
cmake_generator="Xcode"
build_dir="build_xcode"
parallel_builds=""
fi
done
# Create unique name for this build type.
bd="${d}/${build_dir}.${cmake_build_type}"
if [ ! -d ${bd} ] ; then
mkdir ${bd}
fi
# Compile the library.
cd ${bd}
cmake -DCMAKE_INSTALL_PREFIX=${id} \
-DCMAKE_BUILD_TYPE=${cmake_build_type} \
-G "${cmake_generator}" \
..
if [ $? -ne 0 ] ; then
echo "Failed to configure"
exit
fi
cmake --build . --target install --config ${cmake_build_type} -- ${parallel_builds}
if [ $? -ne 0 ] ; then
echo "Failed to build"
exit
fi
cd ${id}/bin
${debugger} ./mocapplay${debug_flag}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment