CMake: use same 3rdParty logic as FlightGear
Avoids need to specify the 3rd-party dir, in the standard/fgmeta layout of source directories, and accept more combinations of path, when the user specifies a value.
This commit is contained in:
parent
2ad6e351ac
commit
83500dd413
@ -118,69 +118,14 @@ include (ExportDebugSymbols)
|
||||
option(OSG_FSTREAM_EXPORT_FIXED "Set to ON if the osgDB fstream export patch is applied" OFF)
|
||||
|
||||
if (MSVC)
|
||||
GET_FILENAME_COMPONENT(PARENT_DIR ${PROJECT_BINARY_DIR} DIRECTORY)
|
||||
if (CMAKE_CL_64)
|
||||
SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty.x64")
|
||||
else (CMAKE_CL_64)
|
||||
SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty")
|
||||
endif (CMAKE_CL_64)
|
||||
if (EXISTS ${TEST_3RDPARTY_DIR})
|
||||
set(MSVC_3RDPARTY_ROOT ${PARENT_DIR} CACHE PATH "Location where the third-party dependencies are extracted")
|
||||
else (EXISTS ${TEST_3RDPARTY_DIR})
|
||||
set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
|
||||
endif (EXISTS ${TEST_3RDPARTY_DIR})
|
||||
|
||||
# override CMake default RelWithDebInfo flags. This is important to ensure
|
||||
# good performance
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/Zi /O2 /Ob2 /D NDEBUG")
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "/Zi /O2 /Ob2 /D NDEBUG")
|
||||
else (MSVC)
|
||||
set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
|
||||
endif (MSVC)
|
||||
endif ()
|
||||
|
||||
if (MSVC AND MSVC_3RDPARTY_ROOT)
|
||||
message(STATUS "3rdparty files located in ${MSVC_3RDPARTY_ROOT}")
|
||||
|
||||
string(SUBSTRING ${MSVC_VERSION} 0 2 MSVC_VERSION_MAJOR)
|
||||
string(SUBSTRING ${MSVC_VERSION} 2 2 MSVC_VERSION_MINOR)
|
||||
|
||||
set( OSG_MSVC "msvc" )
|
||||
if (${MSVC_VERSION_MAJOR} EQUAL "19")
|
||||
if (${MSVC_VERSION_MINOR} GREATER_EQUAL "20")
|
||||
set( OSG_MSVC ${OSG_MSVC}142 )
|
||||
elseif (${MSVC_VERSION_MINOR} GREATER_EQUAL "10")
|
||||
set( OSG_MSVC ${OSG_MSVC}141 )
|
||||
else ()
|
||||
set( OSG_MSVC ${OSG_MSVC}140 )
|
||||
endif ()
|
||||
elseif (${MSVC_VERSION_MAJOR} EQUAL "18")
|
||||
set( OSG_MSVC ${OSG_MSVC}120 )
|
||||
else ()
|
||||
message(FATAL_ERROR "Visual Studio 2013 or higher is required")
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CL_64)
|
||||
set( OSG_MSVC ${OSG_MSVC}-64 )
|
||||
set( MSVC_3RDPARTY_DIR 3rdParty.x64 )
|
||||
else (CMAKE_CL_64)
|
||||
set( MSVC_3RDPARTY_DIR 3rdParty )
|
||||
endif (CMAKE_CL_64)
|
||||
|
||||
set (CMAKE_LIBRARY_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/lib ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenScenegraph/lib ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenRTI/lib )
|
||||
set (CMAKE_INCLUDE_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenScenegraph/include ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenRTI/include)
|
||||
|
||||
if(NOT BOOST_INCLUDEDIR)
|
||||
# if this variable was not set by the user, set it to 3rdparty root's
|
||||
# parent dir, which is the normal location for people using our
|
||||
# windows-3rd-party repo
|
||||
get_filename_component(MSVC_ROOT_PARENT_DIR ${MSVC_3RDPARTY_ROOT} DIRECTORY)
|
||||
set(BOOST_INCLUDEDIR ${MSVC_ROOT_PARENT_DIR})
|
||||
message(STATUS "BOOST_INCLUDEDIR is ${BOOST_INCLUDEDIR}")
|
||||
endif()
|
||||
|
||||
set (OPENAL_INCLUDE_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include)
|
||||
set (OPENAL_LIBRARY_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/lib)
|
||||
endif (MSVC AND MSVC_3RDPARTY_ROOT)
|
||||
# Setup MSVC 3rd party directories
|
||||
include( ConfigureMsvc3rdParty )
|
||||
|
||||
if(APPLE)
|
||||
find_library(COCOA_LIBRARY Cocoa)
|
||||
|
132
CMakeModules/ConfigureMsvc3rdParty.cmake
Normal file
132
CMakeModules/ConfigureMsvc3rdParty.cmake
Normal file
@ -0,0 +1,132 @@
|
||||
# ConfigureMsvc3rdParty.cmake - Configure 3rd Party Library Paths on Windows
|
||||
|
||||
# we want to handle various cases here:
|
||||
# fgmeta layout, where windows-3rd-party is a sibling of our flightgear source dir
|
||||
# - this should work with no manual options
|
||||
# explicitly specifying MSVC_3RDPARTY_ROOT: we'll select a subdir based on MSVC version
|
||||
# and architecture. We want to allow for people specify various paths here:
|
||||
# - path to windows-3rd-party
|
||||
# - path to an MSVC versioned subdir, eg -DMSVC_3RDPARTY_ROOT=C:\FGFS\windows-3rd-party\msvc140
|
||||
# - path to an architecture specific subdir, eg -DMSVC_3RDPARTY_ROOT=C:\FGFS\windows-3rd-party\msvc140\3rdparty.x64
|
||||
|
||||
set(_FOUND_3RDPARTY_DIR "NOTFOUND")
|
||||
set(_FOUND_BOOST_INCLUDE_DIR "NOTFOUND")
|
||||
|
||||
# try various suffixes of a base directory, and
|
||||
# set the variables above on success
|
||||
function(_check_candidate_msvc_path pathToCheck)
|
||||
unset (_freeTypeHeader CACHE )
|
||||
unset (_zlibDll CACHE )
|
||||
unset (_boostHeaders CACHE )
|
||||
|
||||
find_path(_freeTypeHeader include/ft2build.h
|
||||
PATHS
|
||||
${pathToCheck}
|
||||
PATH_SUFFIXES
|
||||
${ARCH_SUBDIR_NAME}
|
||||
${MSVC_SUBDIR_NAME}/${ARCH_SUBDIR_NAME}
|
||||
${COMPAT_SUBDIR_NAME}/${ARCH_SUBDIR_NAME}
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
find_path(_zlibDll bin/zlib.dll
|
||||
PATHS
|
||||
${pathToCheck}
|
||||
PATH_SUFFIXES
|
||||
${ARCH_SUBDIR_NAME}
|
||||
${MSVC_SUBDIR_NAME}/${ARCH_SUBDIR_NAME}
|
||||
${COMPAT_SUBDIR_NAME}/${ARCH_SUBDIR_NAME}
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
find_path(_boostHeaders boost/atomic.hpp
|
||||
PATHS
|
||||
${pathToCheck}
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
if (_freeTypeHeader AND _zlibDll)
|
||||
set(_FOUND_3RDPARTY_DIR "${_freeTypeHeader}" PARENT_SCOPE)
|
||||
|
||||
if (_boostHeaders)
|
||||
set(_FOUND_BOOST_INCLUDE_DIR "${_boostHeaders}" PARENT_SCOPE)
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
|
||||
if (MSVC)
|
||||
# compute values for the compiler and arch subdirs
|
||||
string(SUBSTRING ${MSVC_VERSION} 0 2 MSVC_VERSION_MAJOR)
|
||||
string(SUBSTRING ${MSVC_VERSION} 2 2 MSVC_VERSION_MINOR)
|
||||
|
||||
if (${MSVC_VERSION_MAJOR} EQUAL "19")
|
||||
if (${MSVC_VERSION_MINOR} EQUAL "00")
|
||||
set( MSVC_SUBDIR_NAME msvc140 )
|
||||
else ()
|
||||
set( MSVC_SUBDIR_NAME msvc141 )
|
||||
set( COMPAT_SUBDIR_NAME msvc140 )
|
||||
endif()
|
||||
else ()
|
||||
message(FATAL_ERROR "Visual Studio 2017 is required")
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CL_64)
|
||||
SET(ARCH_SUBDIR_NAME "3rdParty.x64")
|
||||
else (CMAKE_CL_64)
|
||||
SET(ARCH_SUBDIR_NAME "3rdParty")
|
||||
endif (CMAKE_CL_64)
|
||||
|
||||
|
||||
# try the explicitly specified value first
|
||||
if (EXISTS ${MSVC_3RDPARTY_ROOT})
|
||||
_check_candidate_msvc_path("${MSVC_3RDPARTY_ROOT}")
|
||||
endif()
|
||||
|
||||
# then try the fgmeta setup: look for a windows-3rdparty sibling of
|
||||
# our source dir
|
||||
get_filename_component(PARENT_SOURCE_DIR ${PROJECT_SOURCE_DIR} DIRECTORY)
|
||||
get_filename_component(PARENT_BINARY_DIR ${PROJECT_BINARY_DIR} DIRECTORY)
|
||||
|
||||
|
||||
if (NOT _FOUND_3RDPARTY_DIR AND EXISTS "${PARENT_SOURCE_DIR}/windows-3rd-party")
|
||||
message(STATUS "Trying src 3rdparty")
|
||||
_check_candidate_msvc_path("${PARENT_SOURCE_DIR}/windows-3rd-party")
|
||||
endif()
|
||||
|
||||
if (NOT _FOUND_3RDPARTY_DIR AND EXISTS "${PARENT_BINARY_DIR}/windows-3rd-party")
|
||||
message(STATUS "Trying bin 3rdparty")
|
||||
_check_candidate_msvc_path("${PARENT_BINARY_DIR}/windows-3rd-party")
|
||||
endif()
|
||||
|
||||
# try the Jenkins setup, whre the arch dir is copied into the WORKSPACE
|
||||
if (NOT _FOUND_3RDPARTY_DIR AND EXISTS "${PARENT_BINARY_DIR}/${ARCH_SUBDIR_NAME}")
|
||||
message(STATUS "Trying arch subdir ${PARENT_BINARY_DIR}/${ARCH_SUBDIR_NAME}")
|
||||
_check_candidate_msvc_path("${PARENT_BINARY_DIR}/${ARCH_SUBDIR_NAME}")
|
||||
endif()
|
||||
|
||||
if (NOT _FOUND_3RDPARTY_DIR)
|
||||
message(WARNING "Failed to find the Windows 3rdparty files at all.")
|
||||
set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
|
||||
endif()
|
||||
|
||||
else (MSVC)
|
||||
set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
|
||||
endif (MSVC)
|
||||
|
||||
if (MSVC AND _FOUND_3RDPARTY_DIR)
|
||||
message(STATUS "3rdparty files located in ${_FOUND_3RDPARTY_DIR}")
|
||||
list(APPEND CMAKE_PREFIX_PATH ${_FOUND_3RDPARTY_DIR})
|
||||
set(FINAL_MSVC_3RDPARTY_DIR ${_FOUND_3RDPARTY_DIR})
|
||||
|
||||
if (CMAKE_CL_64)
|
||||
set( BOOST_LIB lib64 )
|
||||
else (CMAKE_CL_64)
|
||||
set( BOOST_LIB lib )
|
||||
endif (CMAKE_CL_64)
|
||||
|
||||
if(NOT BOOST_INCLUDEDIR AND _FOUND_BOOST_INCLUDE_DIR)
|
||||
set(BOOST_INCLUDEDIR ${_FOUND_BOOST_INCLUDE_DIR})
|
||||
message(STATUS "found Boost headers at ${_FOUND_BOOST_INCLUDE_DIR}")
|
||||
endif()
|
||||
endif ()
|
Loading…
Reference in New Issue
Block a user