commit c0a7c530f213cb947cc703c39f2d7a4d9d008daf Author: hasufell Date: Sat Jun 8 13:40:12 2013 +0200 CMAKE: add option to use system JThread and use pkg-config diff --git a/cmake/Modules/FindJthread.cmake b/cmake/Modules/FindJthread.cmake index 302a3c2..70d6e92 100644 --- a/cmake/Modules/FindJthread.cmake +++ b/cmake/Modules/FindJthread.cmake @@ -1,16 +1,41 @@ # Look for jthread, use our own if not found -FIND_PATH(JTHREAD_INCLUDE_DIR jthread.h) -FIND_LIBRARY(JTHREAD_LIBRARY NAMES jthread) +option(WITH_SYSTEM_JTHREAD "Use systm JThread copy" OFF) -IF(JTHREAD_LIBRARY AND JTHREAD_INCLUDE_DIR) - SET( JTHREAD_FOUND TRUE ) -ENDIF(JTHREAD_LIBRARY AND JTHREAD_INCLUDE_DIR) +IF(WITH_SYSTEM_JTHREAD) + IF(UNIX) + # try to use pkgconfig file first + FIND_PACKAGE(PkgConfig QUIET) + pkg_check_modules(_PC_JTHREAD jthread) + IF(_PC_JTHREAD_FOUND) + SET(JTHREAD_FOUND TRUE) + # use CFLAGS/LDFLAGS instead of INCLUDE_DIR/LIBRARY + # because we want the full dependencies + SET(JTHREAD_CFLAGS ${_PC_JTHREAD_CFLAGS}) + SET(JTHREAD_LDFLAGS ${_PC_JTHREAD_LDFLAGS}) + ENDIF(_PC_JTHREAD_FOUND) + ENDIF(UNIX) + + # fall back to cmake macros + IF(NOT JTHREAD_FOUND) + FIND_PATH(JTHREAD_INCLUDE_DIR jthread.h PATHS /usr/include/jthread) + FIND_LIBRARY(JTHREAD_LIBRARY NAMES jthread) + + IF(JTHREAD_LIBRARY AND JTHREAD_INCLUDE_DIR) + SET( JTHREAD_FOUND TRUE ) + ENDIF(JTHREAD_LIBRARY AND JTHREAD_INCLUDE_DIR) + ENDIF(NOT JTHREAD_FOUND) +ENDIf(WITH_SYSTEM_JTHREAD) IF(JTHREAD_FOUND) - MESSAGE(STATUS "Found system jthread header file in ${JTHREAD_INCLUDE_DIR}") - MESSAGE(STATUS "Found system jthread library ${JTHREAD_LIBRARY}") + IF(_PC_JTHREAD_FOUND) + MESSAGE(STATUS "Found system jthread: ${_PC_JTHREAD_VERSION}") + ELSE(_PC_JTHREAD_FOUND) + MESSAGE(STATUS "Found system jthread header file in ${JTHREAD_INCLUDE_DIR}") + MESSAGE(STATUS "Found system jthread library ${JTHREAD_LIBRARY}") + ENDIF(_PC_JTHREAD_FOUND) +# fall back to bundled jthread ELSE(JTHREAD_FOUND) SET(JTHREAD_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/jthread) SET(JTHREAD_LIBRARY jthread) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3d7e815..f4586e7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -420,6 +420,9 @@ if(BUILD_CLIENT) ${CGUITTFONT_LIBRARY} ) endif(USE_FREETYPE) + set_target_properties(${PROJECT_NAME} + PROPERTIES COMPILE_FLAGS "${JTHREAD_CFLAGS}" + LINK_FLAGS "${JTHREAD_LDFLAGS}") endif(BUILD_CLIENT) if(BUILD_SERVER) @@ -440,6 +443,9 @@ if(BUILD_SERVER) ${CURL_LIBRARY} ) endif(USE_CURL) + set_target_properties(${PROJECT_NAME}server + PROPERTIES COMPILE_FLAGS "${JTHREAD_CFLAGS}" + LINK_FLAGS "${JTHREAD_LDFLAGS}") endif(BUILD_SERVER)