From 549c5eccb9e18b6db2f469ca9d38e35dda4e33f1 Mon Sep 17 00:00:00 2001 From: Mathias Froehlich Date: Sun, 11 Sep 2011 11:22:10 +0200 Subject: [PATCH] cmake: Factor out common simgear dependency libs. Factor out and use this core simgear depenency library cmake variable. --- CMakeLists.txt | 32 ++------------------------------ CMakeModules/FindSimGear.cmake | 26 +++++++++++++++++++++++++- src/FDM/YASim/CMakeLists.txt | 2 +- src/Input/CMakeLists.txt | 11 +++-------- src/Main/CMakeLists.txt | 7 +++---- utils/GPSsmooth/CMakeLists.txt | 12 +++--------- utils/TerraSync/CMakeLists.txt | 5 ++--- utils/fgadmin/src/CMakeLists.txt | 2 +- utils/fgpanel/CMakeLists.txt | 4 +--- utils/fgviewer/CMakeLists.txt | 4 ++-- 10 files changed, 43 insertions(+), 62 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 54977bc47..b0d702a18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,33 +158,6 @@ check_cxx_source_compiles( " HAVE_CULLSETTINGS_CLEAR_MASK) -# library required by simgear -# XXX This should go in a module and only run if simgear is not shared. - -if(HAVE_UNISTD_H) -set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH}) -check_cxx_source_compiles( - "#include - #if !defined(_POSIX_TIMERS) || (0 >= _POSIX_TIMERS) - #error clock_gettime is not supported - #endif - - int main() { return 0; } - " - HAVE_CLOCK_GETTIME) -endif(HAVE_UNISTD_H) - -set(RT_LIBRARY "") -if(HAVE_CLOCK_GETTIME) -check_function_exists(clock_gettime CLOCK_GETTIME_IN_LIBC) -if(NOT CLOCK_GETTIME_IN_LIBC) -check_library_exists(rt clock_gettime "" HAVE_RT) -if(HAVE_RT) -set(RT_LIBRARY rt) -endif(HAVE_RT) -endif(NOT CLOCK_GETTIME_IN_LIBC) -endif(HAVE_CLOCK_GETTIME) - if(ENABLE_RTI) find_package(RTI) if(RTI_FOUND) @@ -211,7 +184,6 @@ if(WIN32) endif(MSVC) set(NOMINMAX 1) - set( WINSOCK_LIBRARY "ws2_32.lib" ) endif(WIN32) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTRANT") @@ -219,9 +191,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTR set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSVC_LD_FLAGS}") include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS} - ${Boost_INCLUDE_DIRS} + ${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR} - ${ALUT_INCLUDE_DIR} + ${ALUT_INCLUDE_DIR} ${OPENAL_INCLUDE_DIR} ${SIMGEAR_INCLUDE_DIR} ${PLIB_INCLUDE_DIR} ) diff --git a/CMakeModules/FindSimGear.cmake b/CMakeModules/FindSimGear.cmake index f568d4b01..7481fadb4 100644 --- a/CMakeModules/FindSimGear.cmake +++ b/CMakeModules/FindSimGear.cmake @@ -63,6 +63,10 @@ FIND_LIBRARY(SIMGEAR_LIBRARIES /opt ) +# dependent packages +find_package(ZLIB REQUIRED) +find_package(Threads REQUIRED) + macro(find_sg_component comp libs) set(compLib "sg${comp}") string(TOUPPER "SIMGEAR_${comp}" compLibBase) @@ -146,9 +150,29 @@ if(${SIMGEAR_LIBRARIES} STREQUAL "SIMGEAR_LIBRARIES-NOTFOUND") foreach(component ${scene_comps}) find_sg_component(${component} SIMGEAR_LIBRARIES) endforeach() - + # again link order matters - scene libraires depend on core ones list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES}) + + set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES + ${CMAKE_THREAD_LIBS_INIT} + ${ZLIB_LIBRARY}) + + if(WIN32) + list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES ${WINSOCK_LIBRARY}) + endif(WIN32) + + if(NOT MSVC) + # basic timing routines on non windows systems, may be also cygwin?! + check_function_exists(clock_gettime clock_gettime_in_libc) + if(NOT clock_gettime_in_libc) + check_library_exists(rt clock_gettime "" have_rt) + if(have_rt) + list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES rt) + endif(have_rt) + endif(NOT clock_gettime_in_libc) + endif(NOT MSVC) + endif() # now we've found SimGear, check its version diff --git a/src/FDM/YASim/CMakeLists.txt b/src/FDM/YASim/CMakeLists.txt index 1f91a8ed7..d129acef2 100644 --- a/src/FDM/YASim/CMakeLists.txt +++ b/src/FDM/YASim/CMakeLists.txt @@ -38,7 +38,7 @@ add_executable(yasim yasim-test.cpp) target_link_libraries(yasim fgYASim ${SIMGEAR_CORE_LIBRARIES} - ${ZLIB_LIBRARIES}) + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}) install(TARGETS yasim RUNTIME DESTINATION bin) diff --git a/src/Input/CMakeLists.txt b/src/Input/CMakeLists.txt index 27634bc4e..eb9916107 100644 --- a/src/Input/CMakeLists.txt +++ b/src/Input/CMakeLists.txt @@ -31,22 +31,17 @@ set(FGJS_SOURCES add_executable(fgjs ${FGJS_SOURCES}) -if(WIN32) - set(SOCKETS_LIBRARY wsock32.lib) -endif(WIN32) - target_link_libraries(fgjs ${SIMGEAR_CORE_LIBRARIES} - ${SOCKETS_LIBRARY} - ${PLIB_LIBRARIES} - ${ZLIB_LIBRARY}) + ${PLIB_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}) add_executable(js_demo js_demo.cxx) target_link_libraries(js_demo ${SIMGEAR_CORE_LIBRARIES} ${PLIB_LIBRARIES} - ${ZLIB_LIBRARY}) + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}) flightgear_component(Input "${SOURCES}") diff --git a/src/Main/CMakeLists.txt b/src/Main/CMakeLists.txt index dd1f6d6a9..b7c7e961f 100644 --- a/src/Main/CMakeLists.txt +++ b/src/Main/CMakeLists.txt @@ -71,16 +71,15 @@ endif() target_link_libraries(fgfs ${FG_LIBS} - ${HLA_LIBRARIES} ${SIMGEAR_LIBRARIES} ${OPENSCENEGRAPH_LIBRARIES} ${OPENAL_LIBRARY} ${OPENGL_LIBRARIES} ${ALUT_LIBRARY} - ${ZLIB_LIBRARIES} ${PLIB_LIBRARIES} ${LIBSVN_LIBRARIES} - ${WINSOCK_LIBRARY} - ${RT_LIBRARY}) + ${HLA_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} +) install(TARGETS fgfs RUNTIME DESTINATION bin) diff --git a/utils/GPSsmooth/CMakeLists.txt b/utils/GPSsmooth/CMakeLists.txt index 5e90617c6..2cd60a8cc 100644 --- a/utils/GPSsmooth/CMakeLists.txt +++ b/utils/GPSsmooth/CMakeLists.txt @@ -7,11 +7,8 @@ target_link_libraries(GPSsmooth ${SIMGEAR_CORE_LIBRARIES} ${PLIB_SG_LIBRARY} ${PLIB_UL_LIBRARY} - ${ZLIB_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} ${WINMM_LIBRARY} - ${WINSOCK_LIBRARY} - ${ZLIB_LIBRARIES} - ${RT_LIBRARY} ) target_link_libraries(MIDGsmooth @@ -19,8 +16,7 @@ target_link_libraries(MIDGsmooth ${PLIB_SG_LIBRARY} ${PLIB_UL_LIBRARY} ${WINMM_LIBRARY} - ${WINSOCK_LIBRARY} - ${RT_LIBRARY} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} ) target_link_libraries(UGsmooth @@ -28,9 +24,7 @@ target_link_libraries(UGsmooth ${PLIB_SG_LIBRARY} ${PLIB_UL_LIBRARY} ${WINMM_LIBRARY} - ${WINSOCK_LIBRARY} - ${ZLIB_LIBRARIES} - ${RT_LIBRARY} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} ) install(TARGETS GPSsmooth MIDGsmooth UGsmooth RUNTIME DESTINATION bin) diff --git a/utils/TerraSync/CMakeLists.txt b/utils/TerraSync/CMakeLists.txt index 6c81e0f24..d3819794d 100644 --- a/utils/TerraSync/CMakeLists.txt +++ b/utils/TerraSync/CMakeLists.txt @@ -4,9 +4,8 @@ add_executable(terrasync terrasync.cxx) target_link_libraries(terrasync ${SIMGEAR_CORE_LIBRARIES} - ${ZLIB_LIBRARIES} - ${WINSOCK_LIBRARY} - ${RT_LIBRARY}) + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} +) if(LIBSVN_FOUND) target_link_libraries(terrasync ${LIBSVN_LIBRARIES}) diff --git a/utils/fgadmin/src/CMakeLists.txt b/utils/fgadmin/src/CMakeLists.txt index d0e0812fd..e0f623b60 100644 --- a/utils/fgadmin/src/CMakeLists.txt +++ b/utils/fgadmin/src/CMakeLists.txt @@ -7,9 +7,9 @@ add_dependencies(fgadmin FGAdminUI) target_link_libraries(fgadmin FGAdminUI ${SIMGEAR_LIBRARIES} - ${ZLIB_LIBRARIES} ${PLIB_LIBRARIES} ${FLTK_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} ) install(TARGETS fgadmin RUNTIME DESTINATION bin) diff --git a/utils/fgpanel/CMakeLists.txt b/utils/fgpanel/CMakeLists.txt index 48d905600..ed0b991fb 100644 --- a/utils/fgpanel/CMakeLists.txt +++ b/utils/fgpanel/CMakeLists.txt @@ -20,10 +20,8 @@ if(GLUT_FOUND) ${GLUT_LIBRARIES} ${SIMGEAR_CORE_LIBRARIES} ${OPENGL_LIBRARIES} - ${ZLIB_LIBRARIES} ${PLIB_LIBRARIES} - ${WINSOCK_LIBRARY} - ${RT_LIBRARY} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} ) install(TARGETS fgpanel RUNTIME DESTINATION bin) diff --git a/utils/fgviewer/CMakeLists.txt b/utils/fgviewer/CMakeLists.txt index 5872d8a80..9a803e90a 100644 --- a/utils/fgviewer/CMakeLists.txt +++ b/utils/fgviewer/CMakeLists.txt @@ -5,8 +5,8 @@ target_link_libraries(fgviewer ${SIMGEAR_LIBRARIES} ${OPENSCENEGRAPH_LIBRARIES} ${OPENGL_LIBRARIES} - ${ZLIB_LIBRARIES} ${PLIB_LIBRARIES} - ${RT_LIBRARY}) + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} +) install(TARGETS fgviewer RUNTIME DESTINATION bin)