mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-02-12 15:05:47 +08:00
download and build freeglut if not available
This commit is contained in:
@@ -25,16 +25,6 @@ if(USE_OPENMP)
|
||||
message(STATUS "No OpenMP found, no multithreading.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_package(OpenGL)
|
||||
if(NOT OpenGL_FOUND)
|
||||
message(WARNING "OpenGL not found, not compiling graphics programs.")
|
||||
else(NOT OpenGL_FOUND)
|
||||
find_package(GLUT)
|
||||
if(NOT GLUT_FOUND)
|
||||
message(WARNING "GLUT not found, not compiling graphics programs.")
|
||||
endif(NOT GLUT_FOUND)
|
||||
endif(NOT OpenGL_FOUND)
|
||||
|
||||
add_subdirectory(math)
|
||||
add_subdirectory(others)
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(GLUT)
|
||||
if(NOT GLUT_FOUND)
|
||||
message("FreeGLUT library will be downloaded and built.")
|
||||
include(ExternalProject)
|
||||
# Include GLFW
|
||||
ExternalProject_Add (
|
||||
FREEGLUT
|
||||
URL https://sourceforge.net/projects/freeglut/files/freeglut/3.2.1/freeglut-3.2.1.tar.gz
|
||||
URL_MD5 cd5c670c1086358598a6d4a9d166949d
|
||||
CMAKE_ARGS -DCMAKE_BUILD_TYPE=RelWithDebInfo
|
||||
-DFREEGLUT_BUILD_SHARED_LIBS=ON
|
||||
-DFREEGLUT_BUILD_STATIC_LIBS=ON
|
||||
-DFREEGLUT_BUILD_DEMOS=OFF
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/freeglut
|
||||
BUILD_IN_SOURCE ON
|
||||
INSTALL_COMMAND ""
|
||||
)
|
||||
ExternalProject_Get_Property(FREEGLUT SOURCE_DIR)
|
||||
set(FREEGLUT_DIR ${SOURCE_DIR})
|
||||
endif(NOT GLUT_FOUND)
|
||||
|
||||
# If necessary, use the RELATIVE flag, otherwise each source file may be listed
|
||||
# with full pathname. RELATIVE may makes it easier to extract an executable name
|
||||
# automatically.
|
||||
@@ -9,18 +31,25 @@ foreach( testsourcefile ${APP_SOURCES} )
|
||||
string( REPLACE ".cpp" "" testname ${testsourcefile} )
|
||||
add_executable( ${testname} ${testsourcefile} )
|
||||
|
||||
set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX)
|
||||
# set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE CXX)
|
||||
if(OpenMP_CXX_FOUND)
|
||||
target_link_libraries(${testname} OpenMP::OpenMP_CXX)
|
||||
target_link_libraries(${testname} PRIVATE OpenMP::OpenMP_CXX)
|
||||
endif()
|
||||
if (GLUT_FOUND)
|
||||
if(APPLE)
|
||||
target_compile_options(${testname} PUBLIC -Wno-deprecated)
|
||||
endif(APPLE)
|
||||
target_compile_definitions(${testname} PUBLIC GLUT_FOUND)
|
||||
target_include_directories(${testname} PUBLIC ${GLUT_INCLUDE_DIRS})
|
||||
target_link_libraries(${testname} OpenGL::GL ${GLUT_LIBRARIES})
|
||||
endif(GLUT_FOUND)
|
||||
|
||||
if(NOT GLUT_FOUND)
|
||||
add_dependencies(${testname} FREEGLUT)
|
||||
target_include_directories(${testname} PRIVATE ${FREEGLUT_DIR}/include)
|
||||
target_link_directories(${testname} PRIVATE ${FREEGLUT_DIR}/lib)
|
||||
target_link_libraries(${testname} PRIVATE freeglut OpenGL::GL)
|
||||
else()
|
||||
target_include_directories(${testname} PRIVATE ${GLUT_INCLUDE_DIRS})
|
||||
target_link_libraries(${testname} PRIVATE OpenGL::GL ${GLUT_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
target_compile_options(${testname} PRIVATE -Wno-deprecated)
|
||||
endif(APPLE)
|
||||
|
||||
install(TARGETS ${testname} DESTINATION "bin/graphics")
|
||||
|
||||
endforeach( testsourcefile ${APP_SOURCES} )
|
||||
|
||||
@@ -25,13 +25,11 @@
|
||||
#ifdef _OPENMP
|
||||
#include <omp.h>
|
||||
#endif
|
||||
#ifdef GLUT_FOUND // this is set by CMAKE automatically, if available
|
||||
#ifdef __APPLE__
|
||||
#include <GLUT/glut.h> // include path on Macs is different
|
||||
#else
|
||||
#include <GL/glut.h>
|
||||
#endif // __APPLE__
|
||||
#endif // GLUT_FOUND
|
||||
|
||||
/**
|
||||
* @namespace spirograph Functions related to spirograph.cpp
|
||||
@@ -114,7 +112,6 @@ void test() {
|
||||
fp.close();
|
||||
}
|
||||
|
||||
#ifdef GLUT_FOUND // this is set by CMAKE automatically, if available
|
||||
/** A wrapper that is not available in all GLUT implementations.
|
||||
*/
|
||||
static inline void glutBitmapString(void *font, char *message) {
|
||||
@@ -214,12 +211,13 @@ void timer_cb(int t) {
|
||||
glutTimerFunc(25, timer_cb, 0);
|
||||
glutPostRedisplay();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace spirograph
|
||||
|
||||
/** Main function */
|
||||
int main(int argc, char **argv) {
|
||||
#ifdef GLUT_FOUND
|
||||
spirograph::test();
|
||||
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
|
||||
glutCreateWindow("Spirograph");
|
||||
@@ -228,9 +226,6 @@ int main(int argc, char **argv) {
|
||||
glutTimerFunc(25, spirograph::timer_cb, 0);
|
||||
glutDisplayFunc(spirograph::test2);
|
||||
glutMainLoop();
|
||||
#else
|
||||
spirograph::test();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user