|
| 1 | +find_package(OpenGL) |
| 2 | +if(OpenGL_FOUND) |
| 3 | + find_package(GLUT) |
| 4 | + if(NOT GLUT_FOUND) |
| 5 | + message("FreeGLUT library will be downloaded and built.") |
| 6 | + include(ExternalProject) |
| 7 | + ExternalProject_Add ( |
| 8 | + FREEGLUT-PRJ |
| 9 | + URL https://sourceforge.net/projects/freeglut/files/freeglut/3.2.1/freeglut-3.2.1.tar.gz |
| 10 | + URL_MD5 cd5c670c1086358598a6d4a9d166949d |
| 11 | + CMAKE_GENERATOR ${CMAKE_GENERATOR} --config Release |
| 12 | + CMAKE_GENERATOR_TOOLSET ${CMAKE_GENERATOR_TOOLSET} |
| 13 | + CMAKE_GENERATOR_PLATFORM ${CMAKE_GENERATOR_PLATFORM} |
| 14 | + CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release |
| 15 | + -DFREEGLUT_BUILD_SHARED_LIBS=OFF |
| 16 | + -DFREEGLUT_BUILD_STATIC_LIBS=ON |
| 17 | + -DFREEGLUT_BUILD_DEMOS=OFF |
| 18 | + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/freeglut |
| 19 | + # BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/freeglut-build |
| 20 | + # BUILD_IN_SOURCE ON |
| 21 | + # UPDATE_COMMAND "" |
| 22 | + INSTALL_COMMAND "" |
| 23 | + # CONFIGURE_COMMAND "" |
| 24 | + # BUILD_COMMAND "" |
| 25 | + ) |
| 26 | + ExternalProject_Get_Property(FREEGLUT-PRJ SOURCE_DIR) |
| 27 | + ExternalProject_Get_Property(FREEGLUT-PRJ BINARY_DIR) |
| 28 | + set(FREEGLUT_BIN_DIR ${BINARY_DIR}) |
| 29 | + set(FREEGLUT_SRC_DIR ${SOURCE_DIR}) |
| 30 | + # add_library(libfreeglut STATIC IMPORTED) |
| 31 | + # set_target_properties(libfreeglut PROPERTIES IMPORTED_LOCATION ${FREEGLUT_BIN_DIR}) |
| 32 | + |
| 33 | + # set(FREEGLUT_BUILD_DEMOS OFF CACHE BOOL "") |
| 34 | + # set(FREEGLUT_BUILD_SHARED_LIBS OFF CACHE BOOL "") |
| 35 | + # set(FREEGLUT_BUILD_STATIC_LIBS ON CACHE BOOL "") |
| 36 | + # add_subdirectory(${FREEGLUT_SRC_DIR} ${FREEGLUT_BIN_DIR} EXCLUDE_FROM_ALL) |
| 37 | + # add_subdirectory(${BINARY_DIR}) |
| 38 | + # find_package(FreeGLUT) |
| 39 | + endif(NOT GLUT_FOUND) |
| 40 | +else(OpenGL_FOUND) |
| 41 | + message(WARNING "OPENGL not found. Will not build graphical outputs.") |
| 42 | +endif(OpenGL_FOUND) |
| 43 | + |
| 44 | +# If necessary, use the RELATIVE flag, otherwise each source file may be listed |
| 45 | +# with full pathname. RELATIVE may makes it easier to extract an executable name |
| 46 | +# automatically. |
| 47 | +file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.c ) |
| 48 | +# file( GLOB APP_SOURCES ${CMAKE_SOURCE_DIR}/*.c ) |
| 49 | +# AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} APP_SOURCES) |
| 50 | +foreach( testsourcefile ${APP_SOURCES} ) |
| 51 | + # I used a simple string replace, to cut off .cpp. |
| 52 | + string( REPLACE ".c" "" testname ${testsourcefile} ) |
| 53 | + add_executable( ${testname} ${testsourcefile} ) |
| 54 | + |
| 55 | + # set_target_properties(${testname} PROPERTIES LINKER_LANGUAGE C) |
| 56 | + |
| 57 | + if(OpenMP_C_FOUND) |
| 58 | + target_link_libraries(${testname} PRIVATE OpenMP::OpenMP_C) |
| 59 | + endif() |
| 60 | + |
| 61 | + if(MATH_LIBRARY) |
| 62 | + target_link_libraries(${testname} PRIVATE ${MATH_LIBRARY}) |
| 63 | + endif() |
| 64 | + |
| 65 | + if(OpenGL_FOUND) |
| 66 | + if(NOT GLUT_FOUND) |
| 67 | + add_dependencies(${testname} FREEGLUT-PRJ) |
| 68 | + target_compile_definitions(${testname} PRIVATE FREEGLUT_STATIC) |
| 69 | + target_include_directories(${testname} PRIVATE ${FREEGLUT_SRC_DIR}/include) |
| 70 | + target_link_directories(${testname} PRIVATE ${FREEGLUT_BIN_DIR}/lib) |
| 71 | + target_link_libraries(${testname} PRIVATE OpenGL::GL) |
| 72 | + target_link_libraries(${testname} INTERFACE FREEGLUT-PRJ) |
| 73 | + # target_include_directories(${testname} PRIVATE ${FREEGLUT_INCLUDE_DIRS}) |
| 74 | + # target_link_libraries(${testname} INTERFACE freeglut_static) |
| 75 | + else() |
| 76 | + target_include_directories(${testname} PRIVATE ${GLUT_INCLUDE_DIRS}) |
| 77 | + target_link_libraries(${testname} PRIVATE OpenGL::GL ${GLUT_LIBRARIES}) |
| 78 | + endif() |
| 79 | + target_compile_definitions(${testname} PRIVATE USE_GLUT) |
| 80 | + endif(OpenGL_FOUND) |
| 81 | + |
| 82 | + if(APPLE) |
| 83 | + target_compile_options(${testname} PRIVATE -Wno-deprecated) |
| 84 | + endif(APPLE) |
| 85 | + |
| 86 | + install(TARGETS ${testname} DESTINATION "bin/graphics") |
| 87 | + |
| 88 | +endforeach( testsourcefile ${APP_SOURCES} ) |
0 commit comments