mkdir -p /app/study/cpp/ch8
cd /app/study/cpp/ch8
git init
git branch -m main
cat <<'EOF' > /app/study/cpp/ch8/.gitignore
*.d
*.slo
*.lo
*.o
*.obj
*.gch
*.pch
*.so
*.dylib
*.dll
*.mod
*.smod
*.lai
*.la
*.a
*.lib
*.exe
*.out
*.app
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json
build
[Bb][Uu][Ii][Ll][Dd]/
EOF
git submodule add https://github.com/glfw/glfw.git external/glfw
git submodule update --init --recursive
cat <<'EOF' > /app/study/cpp/ch8/main.cpp
int main()
{
GLFWwindow *window;
if(!glfwInit())
{
fprintf( stderr, "Failed to initialize GLFW\n" );
exit( EXIT_FAILURE );
}
window = glfwCreateWindow( 300, 300, "Gears", NULL, NULL );
if(!window)
{
fprintf( stderr, "Failed to open GLFW window\n" );
glfwTerminate();
exit( EXIT_FAILURE );
}
while( !glfwWindowShouldClose(window) )
{
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return EXIT_SUCCESS;
}
EOF
cat <<'EOF' > /app/study/cpp/ch8/CMakeLists.txt
cmake_minimum_required(VERSION 3.13.4)
project(testGLFW)
add_executable(${PROJECT_NAME} main.cpp)
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL 0)
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/external/glfw/CMakeLists.txt")
message(FATAL_ERROR "The glfw submodule was not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules")
endif()
add_subdirectory(external/glfw)
target_include_directories(${PROJECT_NAME} PUBLIC external/glfw/include)
target_link_directories(${PROJECT_NAME} PRIVATE external/glfw/src)
target_link_libraries(${PROJECT_NAME} glfw)
EOF
mkdir -p /app/study/cpp/ch8/build
cat <<'EOF' > /app/study/cpp/ch8/configure.sh
cmake -DGLFW_BUILD_DOCS=OFF -S . -B build
EOF
cat <<'EOF' > /app/study/cpp/ch8/configure.sh
cmake -DGLFW_BUILD_DOCS=OFF -S . -B build
EOF
cat <<'EOF' > /app/study/cpp/ch8/build.sh
cd build ; make
EOF
cat <<'EOF' > /app/study/cpp/ch8/run.sh
cd build ; ./testGLFW
EOF
chmod u+x /app/study/cpp/ch8/*.sh
/app/study/cpp/ch8/configure.sh
/app/study/cpp/ch8/build.sh
/app/study/cpp/ch8/run.sh