diff --git a/CMakeModules/FindOpenThreads.cmake b/CMakeModules/FindOpenThreads.cmake index 3d75b27aa..09c5f5609 100644 --- a/CMakeModules/FindOpenThreads.cmake +++ b/CMakeModules/FindOpenThreads.cmake @@ -39,7 +39,25 @@ FIND_PATH(OPENTHREADS_INCLUDE_DIR OpenThreads/Thread FIND_LIBRARY(OPENTHREADS_LIBRARY - NAMES OpenThreads OpenThreadsd OpenThreadsWin32 OpenThreadsWin32d + NAMES OpenThreads OpenThreadsWin32 + PATHS + ${CMAKE_INSTALL_PREFIX}/lib + $ENV{OPENTHREADS_DIR}/lib + $ENV{OSG_DIR}/lib + ~/Library/Frameworks + /Library/Frameworks + /usr/local/lib64 + /usr/local/lib + /usr/lib64 + /usr/lib + /sw/lib + /opt/local/lib + /opt/csw/lib + /opt/lib + [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/lib +) +FIND_LIBRARY(OPENTHREADS_LIBRARY_DEBUG + NAMES OpenThreadsd OpenThreadsWin32d PATHS ${CMAKE_INSTALL_PREFIX}/lib $ENV{OPENTHREADS_DIR}/lib @@ -60,6 +78,10 @@ FIND_LIBRARY(OPENTHREADS_LIBRARY SET(OPENTHREADS_FOUND "NO") IF(OPENTHREADS_INCLUDE_DIR AND OPENTHREADS_LIBRARY) SET(OPENTHREADS_FOUND "YES") - MESSAGE("-- Found OpenThreads: "${OPENTHREADS_LIBRARY}) + MESSAGE("-- Found OpenThreads: "${OPENTHREADS_LIBRARY}) + IF(NOT OPENTHREADS_LIBRARY_DEBUG) + MESSAGE("-- Warning Debug OpenThreads not found, using: ${OPENTHREADS_LIBRARY}") + SET(OPENTHREADS_LIBRARY_DEBUG "${OPENTHREADS_LIBRARY}") + ENDIF(NOT OPENTHREADS_LIBRARY_DEBUG) ENDIF(OPENTHREADS_INCLUDE_DIR AND OPENTHREADS_LIBRARY) diff --git a/CMakeModules/OsgMacroUtils.cmake b/CMakeModules/OsgMacroUtils.cmake index faa849dab..70b255b95 100644 --- a/CMakeModules/OsgMacroUtils.cmake +++ b/CMakeModules/OsgMacroUtils.cmake @@ -1,3 +1,50 @@ + +####################################################################################################### +# macro for linking libraries that come from Findxxxx commands, so there is a variable that contains the +# full path of the library name. in order to differentiate release and debug, this macro get the +# NAME of the variables, so the macro gets as arguments the target name and the following list of parameters +# is intended as a list of variable names each one containing the path of the libraries to link to +# The existance of a varibale name with _DEBUG appended is tested and, in case it' s value is used +# for linking to when in debug mode +# the content of this library for linking when in debugging +####################################################################################################### + + +MACRO(LINK_WITH_VARIABLES TRGTNAME) + FOREACH(varname ${ARGN}) + IF(${varname}_DEBUG) + TARGET_LINK_LIBRARIES(${TRGTNAME} optimized "${${varname}}" debug "${${varname}_DEBUG}") + ELSE(${varname}_DEBUG) + TARGET_LINK_LIBRARIES(${TRGTNAME} "${${varname}}" ) + ENDIF(${varname}_DEBUG) + ENDFOREACH(varname) +ENDMACRO(LINK_WITH_VARIABLES TRGTNAME) + +MACRO(LINK_INTERNAL TRGTNAME) + FOREACH(LINKLIB ${ARGN}) + TARGET_LINK_LIBRARIES(${TRGTNAME} optimized "${LINKLIB}" debug "${LINKLIB}${CMAKE_DEBUG_POSTFIX}") + ENDFOREACH(LINKLIB) +ENDMACRO(LINK_INTERNAL TRGTNAME) + +MACRO(LINK_EXTERNAL TRGTNAME) + FOREACH(LINKLIB ${ARGN}) + TARGET_LINK_LIBRARIES(${TRGTNAME} "${LINKLIB}" ) + ENDFOREACH(LINKLIB) +ENDMACRO(LINK_EXTERNAL TRGTNAME) + + +####################################################################################################### +# macro for common setup of core libraries: it links OPENGL_LIBRARIES in undifferentiated mode and +# OPENTHREADS_LIBRARY as Differentiated, so if existe the variable OPENTHREADS_LIBRARY_DEBUG, it uses +# the content of this library for linking when in debugging +####################################################################################################### + +MACRO(LINK_CORELIB_DEFAULT CORELIB_NAME) + LINK_EXTERNAL(${CORELIB_NAME} ${OPENGL_LIBRARIES}) + LINK_WITH_VARIABLES(${CORELIB_NAME} OPENTHREADS_LIBRARY) +ENDMACRO(LINK_CORELIB_DEFAULT CORELIB_NAME) + + ####################################################################################################### # macro for common setup of plugins, examples and applications it expect some variables to be set: # either within the local CMakeLists or higher in hierarchy @@ -11,33 +58,37 @@ ########################################################################################################## MACRO(SETUP_LINK_LIBRARIES) -###################################################################### -# -# This set up the libraries to link to, it assumes there are two variable: one common for a group of examples or plagins -# kept in the variable TARGET_COMMON_LIBRARIES and an example or plugin specific kept in TARGET_ADDED_LIBRARIES -# they are combined in a single list checked for unicity -# the suffix ${CMAKE_DEBUG_POSTFIX} is used for differentiating optimized and debug -# -# a second variable TARGET_EXTERNAL_LIBRARIES hold the list of libraries not differentiated between debug and optimized -################################################################################## - SET(TARGET_LIBRARIES ${TARGET_COMMON_LIBRARIES}) - FOREACH(LINKLIB ${TARGET_ADDED_LIBRARIES}) + ###################################################################### + # + # This set up the libraries to link to, it assumes there are two variable: one common for a group of examples or plagins + # kept in the variable TARGET_COMMON_LIBRARIES and an example or plugin specific kept in TARGET_ADDED_LIBRARIES + # they are combined in a single list checked for unicity + # the suffix ${CMAKE_DEBUG_POSTFIX} is used for differentiating optimized and debug + # + # a second variable TARGET_EXTERNAL_LIBRARIES hold the list of libraries not differentiated between debug and optimized + ################################################################################## + SET(TARGET_LIBRARIES ${TARGET_COMMON_LIBRARIES}) + + FOREACH(LINKLIB ${TARGET_ADDED_LIBRARIES}) SET(TO_INSERT TRUE) FOREACH (value ${TARGET_COMMON_LIBRARIES}) - IF (${value} STREQUAL ${LINKLIB}) - SET(TO_INSERT FALSE) - ENDIF (${value} STREQUAL ${LINKLIB}) - ENDFOREACH (value ${TARGET_COMMON_LIBRARIES}) + IF (${value} STREQUAL ${LINKLIB}) + SET(TO_INSERT FALSE) + ENDIF (${value} STREQUAL ${LINKLIB}) + ENDFOREACH (value ${TARGET_COMMON_LIBRARIES}) IF(TO_INSERT) - LIST(APPEND TARGET_LIBRARIES ${LINKLIB}) + LIST(APPEND TARGET_LIBRARIES ${LINKLIB}) ENDIF(TO_INSERT) - ENDFOREACH(LINKLIB) - FOREACH(LINKLIB ${TARGET_LIBRARIES}) - TARGET_LINK_LIBRARIES(${TARGET_TARGETNAME} optimized ${LINKLIB} debug "${LINKLIB}${CMAKE_DEBUG_POSTFIX}") - ENDFOREACH(LINKLIB) - FOREACH(LINKLIB ${TARGET_EXTERNAL_LIBRARIES}) - TARGET_LINK_LIBRARIES(${TARGET_TARGETNAME} ${LINKLIB}) - ENDFOREACH(LINKLIB) + ENDFOREACH(LINKLIB) + + FOREACH(LINKLIB ${TARGET_LIBRARIES}) + TARGET_LINK_LIBRARIES(${TARGET_TARGETNAME} optimized ${LINKLIB} debug "${LINKLIB}${CMAKE_DEBUG_POSTFIX}") + ENDFOREACH(LINKLIB) + + FOREACH(LINKLIB ${TARGET_EXTERNAL_LIBRARIES}) + TARGET_LINK_LIBRARIES(${TARGET_TARGETNAME} ${LINKLIB}) + ENDFOREACH(LINKLIB) + ENDMACRO(SETUP_LINK_LIBRARIES) ############################################################################################ diff --git a/src/osg/CMakeLists.txt b/src/osg/CMakeLists.txt index 43a8ab202..baef1227a 100644 --- a/src/osg/CMakeLists.txt +++ b/src/osg/CMakeLists.txt @@ -291,10 +291,7 @@ ADD_LIBRARY(${LIB_NAME} dxtctool.h ) -TARGET_LINK_LIBRARIES(${LIB_NAME} - ${OPENTHREADS_LIBRARY} - ${OPENGL_LIBRARIES} - ${MATH_LIBRARY} -) +LINK_EXTERNAL(${LIB_NAME} ${MATH_LIBRARY} ) +LINK_CORELIB_DEFAULT(${LIB_NAME} ${MATH_LIBRARY} ) INCLUDE(ModuleInstall OPTIONAL) diff --git a/src/osgDB/CMakeLists.txt b/src/osgDB/CMakeLists.txt index 3d7bc3ff9..6e0252067 100644 --- a/src/osgDB/CMakeLists.txt +++ b/src/osgDB/CMakeLists.txt @@ -59,11 +59,10 @@ IF(APPLE) SET(OSGDB_PLATFORM_SPECIFIC_LIBRARIES ${CARBON_LIBRARY}) ENDIF(APPLE) -TARGET_LINK_LIBRARIES(${LIB_NAME} +LINK_INTERNAL(${LIB_NAME} osg - ${OPENTHREADS_LIBRARY} - ${OPENGL_LIBRARIES} - ${OSGDB_PLATFORM_SPECIFIC_LIBRARIES} ) +LINK_EXTERNAL(${LIB_NAME} ${OSGDB_PLATFORM_SPECIFIC_LIBRARIES} ) +LINK_CORELIB_DEFAULT(${LIB_NAME}) INCLUDE(ModuleInstall OPTIONAL) diff --git a/src/osgFX/CMakeLists.txt b/src/osgFX/CMakeLists.txt index 7f6dac344..4e24348bf 100644 --- a/src/osgFX/CMakeLists.txt +++ b/src/osgFX/CMakeLists.txt @@ -37,12 +37,11 @@ ADD_LIBRARY(${LIB_NAME} Validator.cpp ) -TARGET_LINK_LIBRARIES(${LIB_NAME} +LINK_INTERNAL(${LIB_NAME} osgUtil osgDB osg - ${OPENTHREADS_LIBRARY} - ${OPENGL_LIBRARIES} ) +LINK_CORELIB_DEFAULT(${LIB_NAME}) INCLUDE(ModuleInstall OPTIONAL) diff --git a/src/osgIntrospection/CMakeLists.txt b/src/osgIntrospection/CMakeLists.txt index c0c57e773..201dbd8c5 100644 --- a/src/osgIntrospection/CMakeLists.txt +++ b/src/osgIntrospection/CMakeLists.txt @@ -54,10 +54,8 @@ ADD_LIBRARY(${LIB_NAME} Value.cpp ) -TARGET_LINK_LIBRARIES(${LIB_NAME} - ${OPENTHREADS_LIBRARY} - ${OPENGL_LIBRARIES} -) +LINK_CORELIB_DEFAULT(${LIB_NAME}) + INCLUDE(ModuleInstall OPTIONAL) diff --git a/src/osgManipulator/CMakeLists.txt b/src/osgManipulator/CMakeLists.txt index 341de0741..48802d1d4 100644 --- a/src/osgManipulator/CMakeLists.txt +++ b/src/osgManipulator/CMakeLists.txt @@ -57,12 +57,11 @@ ADD_LIBRARY(${LIB_NAME} TranslatePlaneDragger.cpp ) -TARGET_LINK_LIBRARIES(${LIB_NAME} +LINK_INTERNAL(${LIB_NAME} osgGA osgUtil osg - ${OPENTHREADS_LIBRARY} - ${OPENGL_LIBRARIES} ) +LINK_CORELIB_DEFAULT(${LIB_NAME}) INCLUDE(ModuleInstall OPTIONAL) diff --git a/src/osgParticle/CMakeLists.txt b/src/osgParticle/CMakeLists.txt index edbfe3e84..eab0d6f98 100644 --- a/src/osgParticle/CMakeLists.txt +++ b/src/osgParticle/CMakeLists.txt @@ -76,12 +76,11 @@ ADD_LIBRARY(${LIB_NAME} Version.cpp ) -TARGET_LINK_LIBRARIES(${LIB_NAME} +LINK_INTERNAL(${LIB_NAME} osgUtil osgDB osg - ${OPENTHREADS_LIBRARY} - ${OPENGL_LIBRARIES} ) +LINK_CORELIB_DEFAULT(${LIB_NAME}) INCLUDE(ModuleInstall OPTIONAL) diff --git a/src/osgShadow/CMakeLists.txt b/src/osgShadow/CMakeLists.txt index 535773b8e..8fc213d63 100644 --- a/src/osgShadow/CMakeLists.txt +++ b/src/osgShadow/CMakeLists.txt @@ -33,12 +33,11 @@ ADD_LIBRARY(${LIB_NAME} Version.cpp ) -TARGET_LINK_LIBRARIES(${LIB_NAME} +LINK_INTERNAL(${LIB_NAME} osgUtil osgDB osg - ${OPENTHREADS_LIBRARY} - ${OPENGL_LIBRARIES} ) +LINK_CORELIB_DEFAULT(${LIB_NAME}) INCLUDE(ModuleInstall OPTIONAL) diff --git a/src/osgSim/CMakeLists.txt b/src/osgSim/CMakeLists.txt index a4cb56cc3..66cf679a8 100644 --- a/src/osgSim/CMakeLists.txt +++ b/src/osgSim/CMakeLists.txt @@ -63,12 +63,11 @@ ADD_LIBRARY(${LIB_NAME} VisibilityGroup.cpp ) -TARGET_LINK_LIBRARIES(${LIB_NAME} +LINK_INTERNAL(${LIB_NAME} osgText osgUtil osg - ${OPENTHREADS_LIBRARY} - ${OPENGL_LIBRARIES} ) +LINK_CORELIB_DEFAULT(${LIB_NAME}) INCLUDE(ModuleInstall OPTIONAL) diff --git a/src/osgTerrain/CMakeLists.txt b/src/osgTerrain/CMakeLists.txt index 406ff5b00..9510a408b 100644 --- a/src/osgTerrain/CMakeLists.txt +++ b/src/osgTerrain/CMakeLists.txt @@ -28,13 +28,12 @@ ADD_LIBRARY(${LIB_NAME} Version.cpp ) -TARGET_LINK_LIBRARIES(${LIB_NAME} - osg - osgDB +LINK_INTERNAL(${LIB_NAME} osgUtil - ${OPENTHREADS_LIBRARY} - ${OPENGL_LIBRARIES} + osgDB + osg ) +LINK_CORELIB_DEFAULT(${LIB_NAME}) INCLUDE(ModuleInstall OPTIONAL) diff --git a/src/osgText/CMakeLists.txt b/src/osgText/CMakeLists.txt index d8e878f2f..6c91e7592 100644 --- a/src/osgText/CMakeLists.txt +++ b/src/osgText/CMakeLists.txt @@ -29,11 +29,10 @@ ADD_LIBRARY(${LIB_NAME} Version.cpp ) -TARGET_LINK_LIBRARIES(${LIB_NAME} +LINK_INTERNAL(${LIB_NAME} osgDB osg - ${OPENTHREADS_LIBRARY} - ${OPENGL_LIBRARIES} ) +LINK_CORELIB_DEFAULT(${LIB_NAME}) INCLUDE(ModuleInstall OPTIONAL) diff --git a/src/osgUtil/CMakeLists.txt b/src/osgUtil/CMakeLists.txt index b1bc8bdda..aa98afbcb 100644 --- a/src/osgUtil/CMakeLists.txt +++ b/src/osgUtil/CMakeLists.txt @@ -80,10 +80,9 @@ ADD_LIBRARY(${LIB_NAME} Version.cpp ) -TARGET_LINK_LIBRARIES(${LIB_NAME} +LINK_INTERNAL(${LIB_NAME} osg - ${OPENTHREADS_LIBRARY} - ${OPENGL_LIBRARIES} ) +LINK_CORELIB_DEFAULT(${LIB_NAME}) INCLUDE(ModuleInstall OPTIONAL) diff --git a/src/osgViewer/CMakeLists.txt b/src/osgViewer/CMakeLists.txt index edc002fba..65990ae45 100644 --- a/src/osgViewer/CMakeLists.txt +++ b/src/osgViewer/CMakeLists.txt @@ -72,20 +72,19 @@ ENDIF(WIN32) -TARGET_LINK_LIBRARIES(${LIB_NAME} +LINK_INTERNAL(${LIB_NAME} osgGA osgText osgDB osgUtil osg - ${OPENTHREADS_LIBRARY} - ${OPENGL_LIBRARIES} ) +LINK_CORELIB_DEFAULT(${LIB_NAME}) IF(MINGW) - TARGET_LINK_LIBRARIES(${LIB_NAME} + LINK_EXTERNAL(${LIB_NAME} gdi32 - ) + ) ENDIF(MINGW) INCLUDE(ModuleInstall OPTIONAL)