1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-25 11:52:40 +01:00

cmake: do not override find modules but wrap them separately

This commit is contained in:
Anonymous Maarten 2018-02-27 23:28:48 +01:00
parent 8f70b36d6f
commit b6a2b2181d
13 changed files with 66 additions and 118 deletions

View File

@ -14,6 +14,8 @@ include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1) get_git_head_revision(GIT_REFSPEC GIT_SHA1)
message(STATUS "Building ${CMAKE_PROJECT_NAME} GIT SHA1: ${GIT_SHA1}") message(STATUS "Building ${CMAKE_PROJECT_NAME} GIT SHA1: ${GIT_SHA1}")
include(WrapTargets)
find_package(Boost REQUIRED) find_package(Boost REQUIRED)
find_package(Boost COMPONENTS program_options system REQUIRED) find_package(Boost COMPONENTS program_options system REQUIRED)
if(FILESYSTEM_LIBRARY STREQUAL "BOOST") if(FILESYSTEM_LIBRARY STREQUAL "BOOST")
@ -34,6 +36,8 @@ find_package(GLM REQUIRED)
find_package(FFmpeg REQUIRED) find_package(FFmpeg REQUIRED)
find_package(SDL2 REQUIRED) find_package(SDL2 REQUIRED)
rwdep_wrap_find_packages()
if(CHECK_CLANGTIDY) if(CHECK_CLANGTIDY)
find_package(ClangTidy REQUIRED) find_package(ClangTidy REQUIRED)
endif() endif()

View File

@ -1,17 +0,0 @@
# Override CMake's FindBullet module:
# - create a bullet::bullet TARGET
include("${CMAKE_ROOT}/Modules/FindBullet.cmake")
if(BULLET_FOUND AND NOT TARGET bullet::bullet)
add_library(bullet INTERFACE)
target_link_libraries(bullet
INTERFACE
${BULLET_LIBRARIES}
)
target_include_directories(bullet SYSTEM
INTERFACE
"${BULLET_INCLUDE_DIR}"
)
add_library(bullet::bullet ALIAS bullet)
endif()

View File

@ -69,16 +69,3 @@ endif()
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FFmpeg DEFAULT_MSG FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIR) find_package_handle_standard_args(FFmpeg DEFAULT_MSG FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIR)
if(FFMPEG_FOUND AND NOT TARGET ffmpeg::ffmpeg)
add_library(ffmpeg INTERFACE)
target_link_libraries(ffmpeg
INTERFACE
${FFMPEG_LIBRARIES}
)
target_include_directories(ffmpeg SYSTEM
INTERFACE
"${FFMPEG_INCLUDE_DIR}"
)
add_library(ffmpeg::ffmpeg ALIAS ffmpeg)
endif()

View File

@ -63,12 +63,3 @@ IF(GLM_FOUND)
MESSAGE(STATUS "GLM_INCLUDE_DIR = ${GLM_INCLUDE_DIR}") MESSAGE(STATUS "GLM_INCLUDE_DIR = ${GLM_INCLUDE_DIR}")
ENDIF(NOT GLM_FIND_QUIETLY) ENDIF(NOT GLM_FIND_QUIETLY)
ENDIF(GLM_FOUND) ENDIF(GLM_FOUND)
if(GLM_FOUND AND NOT TARGET glm::glm)
add_library(glm INTERFACE)
target_include_directories(glm SYSTEM
INTERFACE
"${GLM_INCLUDE_DIR}"
)
add_library(glm::glm ALIAS glm)
endif()

View File

@ -1,17 +0,0 @@
# Override CMake's FindOpenAL module:
# - create a OpenAL::OpenAL target
include("${CMAKE_ROOT}/Modules/FindOpenAL.cmake")
if(OPENAL_FOUND AND NOT TARGET OpenAL::OpenAL)
add_library(OpenAL INTERFACE)
target_link_libraries(OpenAL
INTERFACE
"${OPENAL_LIBRARY}"
)
target_include_directories(OpenAL SYSTEM
INTERFACE
"${OPENAL_INCLUDE_DIR}"
)
add_library(OpenAL::OpenAL ALIAS OpenAL)
endif()

View File

@ -1,17 +0,0 @@
# Override CMake's FindOpenGL module:
# - create a OPENGL::GL TARGET
include("${CMAKE_ROOT}/Modules/FindOpenGL.cmake")
if(OPENGL_FOUND AND NOT TARGET OpenGL::GL)
add_library(OpenGL INTERFACE)
target_link_libraries(OpenGL
INTERFACE
${OPENGL_LIBRARIES}
)
target_include_directories(OpenGL SYSTEM
INTERFACE
"${OPENGL_INCLUDE_DIR}"
)
add_library(OpenGL::GL ALIAS OpenGL)
endif()

View File

@ -194,16 +194,3 @@ IF(SDL2_STATIC)
SET(SDL2_LIBRARY ${SDL2_LINK_FLAGS}) SET(SDL2_LIBRARY ${SDL2_LINK_FLAGS})
ENDIF() ENDIF()
ENDIF(SDL2_STATIC) ENDIF(SDL2_STATIC)
if(SDL2_FOUND AND NOT TARGET SDL2::SDL2)
add_library(SDL2 INTERFACE)
target_link_libraries(SDL2
INTERFACE
${SDL2_LIBRARY}
)
target_include_directories(SDL2 SYSTEM
INTERFACE
"${SDL2_INCLUDE_DIR}"
)
add_library(SDL2::SDL2 ALIAS SDL2)
endif()

View File

@ -0,0 +1,50 @@
function(rwdep_wrap_find_package TARGET INCLUDE_DIRS LINK_LIBS)
add_library("TMP_${TARGET}" INTERFACE)
target_include_directories("TMP_${TARGET}" SYSTEM
INTERFACE
${INCLUDE_DIRS}
)
target_link_libraries("TMP_${TARGET}"
INTERFACE
${LINK_LIBS}
)
add_library("rwdep::${TARGET}" ALIAS "TMP_${TARGET}")
endfunction()
function(rwdep_wrap_find_packages)
if(BULLET_FOUND)
rwdep_wrap_find_package(bullet "${BULLET_INCLUDE_DIR}" "${BULLET_LIBRARIES}")
endif()
if(FFMPEG_FOUND)
rwdep_wrap_find_package(ffmpeg "${FFMPEG_INCLUDE_DIR}" "${FFMPEG_LIBRARIES}")
endif()
if(GLM_FOUND)
rwdep_wrap_find_package(glm "${GLM_INCLUDE_DIR}" "")
endif()
if(OPENAL_FOUND)
rwdep_wrap_find_package(OpenAL "${OPENAL_INCLUDE_DIR}" "${OPENAL_LIBRARY}")
endif()
if(SDL2_FOUND)
rwdep_wrap_find_package(SDL2 "${SDL2_INCLUDE_DIR}" "${SDL2_LIBRARY}")
endif()
if(Boost_FOUND)
rwdep_wrap_find_package(boost "${Boost_INCLUDE_DIRS}" "")
endif()
if(Boost_SYSTEM_FOUND)
rwdep_wrap_find_package(boost_system "${Boost_INCLUDE_DIRS}" "${Boost_SYSTEM_LIBRARY}")
endif()
if(Boost_FILESYSTEM_FOUND)
rwdep_wrap_find_package(boost_filesystem "${Boost_INCLUDE_DIRS}" "${Boost_FILESYSTEM_LIBRARY};rwdep::boost_system")
endif()
if(Boost_PROGRAM_OPTIONS_FOUND)
rwdep_wrap_find_package(boost_program_options "${Boost_INCLUDE_DIRS}" "${Boost_PROGRAM_OPTIONS_LIBRARY};rwdep::boost_system")
endif()
if(Boost_UNIT_TEST_FRAMEWORK_FOUND)
rwdep_wrap_find_package(boost_unit_test_framework "${Boost_INCLUDE_DIRS}" "${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}")
endif()
endfunction()

View File

@ -73,10 +73,8 @@ elseif(FILESYSTEM_LIBRARY STREQUAL "CXXTS")
endif() endif()
elseif(FILESYSTEM_LIBRARY STREQUAL "BOOST") elseif(FILESYSTEM_LIBRARY STREQUAL "BOOST")
target_compile_definitions(rw_interface INTERFACE "RW_FS_LIBRARY=2") target_compile_definitions(rw_interface INTERFACE "RW_FS_LIBRARY=2")
target_include_directories(rw_interface INTERFACE ${Boost_INCLUDE_DIRS})
target_link_libraries(rw_interface INTERFACE target_link_libraries(rw_interface INTERFACE
${Boost_FILESYSTEM_LIBRARY} rwdep::boost_filesystem
${Boost_SYSTEM_LIBRARY}
) )
else() else()
message(FATAL_ERROR "Illegal FILESYSTEM_LIBRARY option. (was '${FILESYSTEM_LIBRARY}')") message(FATAL_ERROR "Illegal FILESYSTEM_LIBRARY option. (was '${FILESYSTEM_LIBRARY}')")

View File

@ -147,10 +147,10 @@ add_library(rwengine
target_link_libraries(rwengine target_link_libraries(rwengine
PUBLIC PUBLIC
rwlib rwlib
bullet::bullet rwdep::bullet
ffmpeg::ffmpeg rwdep::ffmpeg
glm::glm rwdep::glm
OpenAL::OpenAL rwdep::OpenAL
) )
target_include_directories(rwengine target_include_directories(rwengine

View File

@ -43,12 +43,6 @@ add_executable(rwgame
${RWGAME_SOURCES} ${RWGAME_SOURCES}
) )
target_include_directories(rwgame
SYSTEM
PRIVATE
${Boost_INCLUDE_DIRS}
)
target_include_directories(rwgame target_include_directories(rwgame
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/rwgame" "${CMAKE_SOURCE_DIR}/rwgame"
@ -57,8 +51,8 @@ target_include_directories(rwgame
target_link_libraries(rwgame target_link_libraries(rwgame
PRIVATE PRIVATE
rwengine rwengine
${Boost_PROGRAM_OPTIONS_LIBRARY} rwdep::boost_program_options
SDL2::SDL2 rwdep::SDL2
) )
openrw_target_apply_options(TARGET rwgame) openrw_target_apply_options(TARGET rwgame)

View File

@ -47,15 +47,10 @@ target_include_directories(rwlib
"${CMAKE_CURRENT_SOURCE_DIR}/source" "${CMAKE_CURRENT_SOURCE_DIR}/source"
) )
target_include_directories(rwlib
SYSTEM
PRIVATE
${Boost_INCLUDE_DIRS}
)
target_link_libraries(rwlib target_link_libraries(rwlib
PUBLIC PUBLIC
glm::glm rwdep::boost
rwdep::glm
openrw::interface openrw::interface
PRIVATE PRIVATE
OpenGL::GL OpenGL::GL

View File

@ -69,12 +69,6 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
) )
endif() endif()
target_include_directories(rwtests
SYSTEM
PRIVATE
${Boost_INCLUDE_DIRS}
)
target_include_directories(rwtests target_include_directories(rwtests
PRIVATE PRIVATE
"${CMAKE_SOURCE_DIR}/tests" "${CMAKE_SOURCE_DIR}/tests"
@ -84,10 +78,9 @@ target_include_directories(rwtests
target_link_libraries(rwtests target_link_libraries(rwtests
PRIVATE PRIVATE
rwengine rwengine
SDL2::SDL2 rwdep::SDL2
${Boost_FILESYSTEM_LIBRARY} rwdep::boost_filesystem
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} rwdep::boost_unit_test_framework
${Boost_SYSTEM_LIBRARY}
) )
openrw_target_apply_options(TARGET rwtests) openrw_target_apply_options(TARGET rwtests)