From 40bd46c782f2b73380167faac6c80dc9ce8edc1e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 7 Mar 2014 11:21:36 -0800 Subject: [PATCH] cmake styling cleanup and glew module fixes --- cmake/macros/AutoMTC.cmake | 19 ++++++------- cmake/macros/IncludeGLM.cmake | 13 +++++---- cmake/macros/LinkHifiLibrary.cmake | 32 +++++++++++---------- cmake/macros/SetupHifiLibrary.cmake | 26 +++++++++-------- cmake/macros/SetupHifiProject.cmake | 43 +++++++++++++++-------------- cmake/modules/FindGLEW.cmake | 21 ++++++++++---- 6 files changed, 85 insertions(+), 69 deletions(-) diff --git a/cmake/macros/AutoMTC.cmake b/cmake/macros/AutoMTC.cmake index 1c818d9548..6619419b59 100644 --- a/cmake/macros/AutoMTC.cmake +++ b/cmake/macros/AutoMTC.cmake @@ -1,14 +1,13 @@ macro(AUTO_MTC TARGET ROOT_DIR) - if (NOT TARGET mtc) - add_subdirectory("${ROOT_DIR}/tools/mtc" "${ROOT_DIR}/tools/mtc") - endif (NOT TARGET mtc) - - set(AUTOMTC_SRC ${TARGET}_automtc.cpp) - - file(GLOB INCLUDE_FILES src/*.h) - - add_custom_command(OUTPUT ${AUTOMTC_SRC} COMMAND mtc -o ${AUTOMTC_SRC} ${INCLUDE_FILES} DEPENDS mtc ${INCLUDE_FILES}) - + if (NOT TARGET mtc) + add_subdirectory("${ROOT_DIR}/tools/mtc" "${ROOT_DIR}/tools/mtc") + endif () + + set(AUTOMTC_SRC ${TARGET}_automtc.cpp) + + file(GLOB INCLUDE_FILES src/*.h) + + add_custom_command(OUTPUT ${AUTOMTC_SRC} COMMAND mtc -o ${AUTOMTC_SRC} ${INCLUDE_FILES} DEPENDS mtc ${INCLUDE_FILES}) endmacro() diff --git a/cmake/macros/IncludeGLM.cmake b/cmake/macros/IncludeGLM.cmake index 246590eaf0..d405bbb820 100644 --- a/cmake/macros/IncludeGLM.cmake +++ b/cmake/macros/IncludeGLM.cmake @@ -1,7 +1,10 @@ -MACRO(INCLUDE_GLM TARGET ROOT_DIR) +macro(INCLUDE_GLM TARGET ROOT_DIR) + find_package(GLM REQUIRED) include_directories("${GLM_INCLUDE_DIRS}") -IF(APPLE OR UNIX) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${GLM_INCLUDE_DIRS}") -ENDIF(APPLE OR UNIX) -ENDMACRO(INCLUDE_GLM _target _root_dir) \ No newline at end of file + + if(APPLE OR UNIX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${GLM_INCLUDE_DIRS}") + endif(APPLE OR UNIX) + +endmacro(INCLUDE_GLM _target _root_dir) \ No newline at end of file diff --git a/cmake/macros/LinkHifiLibrary.cmake b/cmake/macros/LinkHifiLibrary.cmake index 925953efcf..02ebc983c2 100644 --- a/cmake/macros/LinkHifiLibrary.cmake +++ b/cmake/macros/LinkHifiLibrary.cmake @@ -1,16 +1,18 @@ -MACRO(LINK_HIFI_LIBRARY LIBRARY TARGET ROOT_DIR) - if (NOT TARGET ${LIBRARY}) - add_subdirectory("${ROOT_DIR}/libraries/${LIBRARY}" "${ROOT_DIR}/libraries/${LIBRARY}") - endif (NOT TARGET ${LIBRARY}) - - include_directories("${ROOT_DIR}/libraries/${LIBRARY}/src") +macro(LINK_HIFI_LIBRARY LIBRARY TARGET ROOT_DIR) + + if (NOT TARGET ${LIBRARY}) + add_subdirectory("${ROOT_DIR}/libraries/${LIBRARY}" "${ROOT_DIR}/libraries/${LIBRARY}") + endif () + + include_directories("${ROOT_DIR}/libraries/${LIBRARY}/src") - add_dependencies(${TARGET} ${LIBRARY}) - target_link_libraries(${TARGET} ${LIBRARY}) - - if (APPLE) - # currently the "shared" library requires CoreServices - # link in required OS X framework - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework CoreServices") - endif (APPLE) -ENDMACRO(LINK_HIFI_LIBRARY _library _target _root_dir) \ No newline at end of file + add_dependencies(${TARGET} ${LIBRARY}) + target_link_libraries(${TARGET} ${LIBRARY}) + + if (APPLE) + # currently the "shared" library requires CoreServices + # link in required OS X framework + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework CoreServices") + endif () + +endmacro(LINK_HIFI_LIBRARY _library _target _root_dir) \ No newline at end of file diff --git a/cmake/macros/SetupHifiLibrary.cmake b/cmake/macros/SetupHifiLibrary.cmake index 217be6b3a0..19428b6723 100644 --- a/cmake/macros/SetupHifiLibrary.cmake +++ b/cmake/macros/SetupHifiLibrary.cmake @@ -1,15 +1,17 @@ -MACRO(SETUP_HIFI_LIBRARY TARGET) - project(${TARGET}) +macro(SETUP_HIFI_LIBRARY TARGET) + + project(${TARGET}) - # grab the implemenation and header files - file(GLOB LIB_SRCS src/*.h src/*.cpp) - set(LIB_SRCS ${LIB_SRCS} ${WRAPPED_SRCS}) + # grab the implemenation and header files + file(GLOB LIB_SRCS src/*.h src/*.cpp) + set(LIB_SRCS ${LIB_SRCS} ${WRAPPED_SRCS}) - # create a library and set the property so it can be referenced later - add_library(${TARGET} ${LIB_SRCS} ${ARGN}) - - find_package(Qt5Core REQUIRED) - qt5_use_modules(${TARGET} Core) + # create a library and set the property so it can be referenced later + add_library(${TARGET} ${LIB_SRCS} ${ARGN}) + + find_package(Qt5Core REQUIRED) + qt5_use_modules(${TARGET} Core) - target_link_libraries(${TARGET} ${QT_LIBRARIES}) -ENDMACRO(SETUP_HIFI_LIBRARY _target) \ No newline at end of file + target_link_libraries(${TARGET} ${QT_LIBRARIES}) + +endmacro(SETUP_HIFI_LIBRARY _target) \ No newline at end of file diff --git a/cmake/macros/SetupHifiProject.cmake b/cmake/macros/SetupHifiProject.cmake index 3b187e6be4..9311189a87 100644 --- a/cmake/macros/SetupHifiProject.cmake +++ b/cmake/macros/SetupHifiProject.cmake @@ -1,24 +1,25 @@ macro(SETUP_HIFI_PROJECT TARGET INCLUDE_QT) - project(${TARGET}) - - # grab the implemenation and header files - file(GLOB TARGET_SRCS src/*) - - file(GLOB SRC_SUBDIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/*) - foreach(DIR ${SRC_SUBDIRS}) - if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/${DIR}") - FILE(GLOB DIR_CONTENTS "src/${DIR}/*") - SET(TARGET_SRCS ${TARGET_SRCS} "${DIR_CONTENTS}") - endif() - endforeach() - - # add the executable, include additional optional sources - add_executable(${TARGET} ${TARGET_SRCS} ${ARGN}) - - IF (${INCLUDE_QT}) - find_package(Qt5Core REQUIRED) - qt5_use_modules(${TARGET} Core) - ENDIF() + project(${TARGET}) + + # grab the implemenation and header files + file(GLOB TARGET_SRCS src/*) + + file(GLOB SRC_SUBDIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/*) + + foreach(DIR ${SRC_SUBDIRS}) + if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/${DIR}") + file(GLOB DIR_CONTENTS "src/${DIR}/*") + set(TARGET_SRCS ${TARGET_SRCS} "${DIR_CONTENTS}") + endif() + endforeach() + + # add the executable, include additional optional sources + add_executable(${TARGET} ${TARGET_SRCS} ${ARGN}) + + if (${INCLUDE_QT}) + find_package(Qt5Core REQUIRED) + qt5_use_modules(${TARGET} Core) + endif () - target_link_libraries(${TARGET} ${QT_LIBRARIES}) + target_link_libraries(${TARGET} ${QT_LIBRARIES}) endmacro() \ No newline at end of file diff --git a/cmake/modules/FindGLEW.cmake b/cmake/modules/FindGLEW.cmake index b0f798a78a..d382c88b33 100644 --- a/cmake/modules/FindGLEW.cmake +++ b/cmake/modules/FindGLEW.cmake @@ -33,10 +33,19 @@ IF (WIN32) DOC "The GLEW library") ENDIF() -IF (GLEW_INCLUDE_PATH) - SET( GLEW_FOUND 1 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise") -ELSE (GLEW_INCLUDE_PATH) - SET( GLEW_FOUND 0 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise") -ENDIF (GLEW_INCLUDE_PATH) +if (GLEW_INCLUDE_DIRS AND GLEW_LIBRARY) + set(GLEW_FOUND TRUE) +endif () -MARK_AS_ADVANCED(GLEW_FOUND) \ No newline at end of file +if (GLEW_FOUND) + if (NOT GLEW_FIND_QUIETLY) + message(STATUS "Found GLEW: ${GLEW_LIBRARY}") + endif (NOT GLEW_FIND_QUIETLY) +else () + if (GLEW_FIND_REQUIRED) + message(FATAL_ERROR "Could not find GLEW") + endif (GLEW_FIND_REQUIRED) +endif () + +# show the GLEW_INCLUDE_DIRS and GLEW_LIBRARY variables only in the advanced view +mark_as_advanced(GLEW_INCLUDE_DIRS GLEW_LIBRARY) \ No newline at end of file