Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cmake 2 #285

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ include (GenerateExportHeader)
option(BUILD_SHARED_LIBS "Build Shared Libraries" ON)
option(INSTALL_EXAMPLES "Install source code and build system for examples" ON)

include(osvrStashMapConfig)
include(StashMapConfig)

#-----------------------------------------------------------------------------
# This looks for an osvrConfig.cmake file - most of the time it can be
# autodetected but you might need to specify osvr_DIR to be something like
# C:/Users/Ryan/Desktop/build/OSVR-Core-vc12 or
# C:/Users/Ryan/Downloads/OSVR-Core-Snapshot-v0.1-406-gaa55515-build54-vs12-32bit
# in the CMake GUI or command line
osvr_stash_common_map_config()
stash_common_map_config()
find_package(osvr REQUIRED)
osvr_unstash_common_map_config()
stash_common_map_config()

find_package(Eigen3 REQUIRED)
find_package(JsonCpp REQUIRED)
Expand Down Expand Up @@ -609,7 +609,7 @@ configure_file("cmake/osvrRenderManagerConfig.cmake"

# Copy over the shared CMake modules for use in a build tree,
# and install for an install tree.
foreach(HELPER CMakeBoostHelper FindSDL2 FindGLEW CopyImportedTarget osvrStashMapConfig)
foreach(HELPER CMakeBoostHelper FindSDL2 FindGLEW CopyImportedTarget StashMapConfig)
configure_file("cmake/${HELPER}.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${HELPER}.cmake" COPYONLY)
install(FILES
"cmake/${HELPER}.cmake"
Expand Down
173 changes: 124 additions & 49 deletions cmake/FindJsonCpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,69 +51,136 @@ macro(_jsoncpp_check_for_real_jsoncpplib)
set(__jsoncpp_have_jsoncpplib TRUE)
endif()
endif()
#message(STATUS "__jsoncpp_have_jsoncpplib ${__jsoncpp_have_jsoncpplib}")
endmacro()

include(FindPackageHandleStandardArgs)
# Ensure that if this is TRUE later, it's because we set it.
set(JSONCPP_FOUND FALSE)
set(__jsoncpp_have_jsoncpplib FALSE)

# See if we find a CMake config file.
# See if we find a CMake config file - there is no harm in calling this more than once,
# and we need to call it at least once every CMake invocation to create the original
# imported targets, since those don't stick around like cache variables.
find_package(jsoncpp QUIET NO_MODULE)

# We will always try first to get a config file.
if(NOT JSONCPP_IMPORTED_LIBRARY)
if(jsoncpp_FOUND)
# OK, so we found something.
unset(JSONCPP_IMPORTED_LIBRARY_IS_SHARED)
_jsoncpp_check_for_real_jsoncpplib()
if(__jsoncpp_have_jsoncpplib AND TARGET jsoncpp_lib_static)
# A veritable cache of riches - we have both shared and static!
set(JSONCPP_IMPORTED_LIBRARY_SHARED jsoncpp_lib CACHE INTERNAL "" FORCE)
set(JSONCPP_IMPORTED_LIBRARY_STATIC jsoncpp_lib_static CACHE INTERNAL "" FORCE)
if(WIN32 OR CYGWIN OR MINGW)
# DLL platforms: static library should be default
set(JSONCPP_IMPORTED_LIBRARY ${JSONCPP_IMPORTED_LIBRARY_STATIC} CACHE INTERNAL "" FORCE)
set(JSONCPP_IMPORTED_LIBRARY_IS_SHARED FALSE CACHE INTERNAL "" FORCE)
else()
# Other platforms - might require PIC to be linked into shared libraries, so safest to prefer shared.
set(JSONCPP_IMPORTED_LIBRARY ${JSONCPP_IMPORTED_LIBRARY_SHARED} CACHE INTERNAL "" FORCE)
set(JSONCPP_IMPORTED_LIBRARY_IS_SHARED TRUE CACHE INTERNAL "" FORCE)
endif()
elseif(TARGET jsoncpp_lib_static)
# Well, only one variant, but we know for sure that it's static.
set(JSONCPP_IMPORTED_LIBRARY_STATIC jsoncpp_lib_static CACHE INTERNAL "" FORCE)
set(JSONCPP_IMPORTED_LIBRARY jsoncpp_lib_static CACHE INTERNAL "" FORCE)
set(JSONCPP_IMPORTED_LIBRARY_IS_SHARED FALSE CACHE INTERNAL "" FORCE)
elseif(TARGET __jsoncpp_have_jsoncpplib)
# One variant, and we have no idea if this is just an old version or if
# this is shared based on the target name alone. Hmm.
# TODO figure out if this is shared or static?
set(JSONCPP_IMPORTED_LIBRARY jsoncpp_lib CACHE INTERNAL "" FORCE)
endif()
if(jsoncpp_FOUND)
# Build a string to help us figure out when to invalidate our cache variables.
# start with where we found jsoncpp
set(__jsoncpp_info_string "[${jsoncpp_DIR}]")

# Now, we need include directories. Can't just limit this to old CMakes, since
# new CMakes might be used to build projects designed to support older ones.
if(__jsoncpp_have_jsoncpplib)
get_property(__jsoncpp_interface_include_dirs TARGET jsoncpp_lib PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
if(__jsoncpp_interface_include_dirs)
set(JSONCPP_IMPORTED_INCLUDE_DIRS "${__jsoncpp_interface_include_dirs}" CACHE INTERNAL "" FORCE)
endif()
# part of the string to indicate if we found a real jsoncpp_lib (and what kind)
_jsoncpp_check_for_real_jsoncpplib()

macro(_jsoncpp_apply_map_config target)
if(MSVC)
# Can't do this - different runtimes, incompatible ABI, etc.
set(_jsoncpp_debug_fallback)
else()
set(_jsoncpp_debug_fallback DEBUG)
#osvr_stash_map_config(DEBUG DEBUG RELWITHDEBINFO RELEASE MINSIZEREL NONE)
endif()
if(TARGET jsoncpp_lib_static AND NOT JSONCPP_IMPORTED_INCLUDE_DIRS)
get_property(__jsoncpp_interface_include_dirs TARGET jsoncpp_lib_static PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
if(__jsoncpp_interface_include_dirs)
set(JSONCPP_IMPORTED_INCLUDE_DIRS "${__jsoncpp_interface_include_dirs}" CACHE INTERNAL "" FORCE)
endif()
# Appending, just in case using project or upstream fixes this.
set_property(TARGET ${target} APPEND PROPERTY MAP_IMPORTED_CONFIG_RELEASE RELEASE RELWITHDEBINFO MINSIZEREL NONE ${_jsoncpp_debug_fallback})
set_property(TARGET ${target} APPEND PROPERTY MAP_IMPORTED_CONFIG_RELWITHDEBINFO RELWITHDEBINFO RELEASE MINSIZEREL NONE ${_jsoncpp_debug_fallback})
set_property(TARGET ${target} APPEND PROPERTY MAP_IMPORTED_CONFIG_MINSIZEREL MINSIZEREL RELEASE RELWITHDEBINFO NONE ${_jsoncpp_debug_fallback})
set_property(TARGET ${target} APPEND PROPERTY MAP_IMPORTED_CONFIG_NONE RELEASE RELWITHDEBINFO MINSIZEREL ${_jsoncpp_debug_fallback})
if(NOT MSVC)
set_property(TARGET ${target} APPEND PROPERTY MAP_IMPORTED_CONFIG_DEBUG DEBUG RELWITHDEBINFO RELEASE MINSIZEREL NONE)
endif()
endmacro()
if(__jsoncpp_have_jsoncpplib)
list(APPEND __jsoncpp_info_string "[${__jsoncpp_lib_type}]")
_jsoncpp_apply_map_config(jsoncpp_lib)
else()
list(APPEND __jsoncpp_info_string "[]")
endif()
# part of the string to indicate if we found jsoncpp_lib_static
if(TARGET jsoncpp_lib_static)
list(APPEND __jsoncpp_info_string "[T]")
_jsoncpp_apply_map_config(jsoncpp_lib_static)
else()
list(APPEND __jsoncpp_info_string "[]")
endif()
endif()


# If we found something, and it's not the exact same as what we've found before...
# NOTE: The contents of this "if" block update only (internal) cache variables!
# (since this will only get run the first CMake pass that finds jsoncpp or that finds a different/updated install)
if(jsoncpp_FOUND AND NOT __jsoncpp_info_string STREQUAL "${JSONCPP_CACHED_JSONCPP_DIR_DETAILS}")
#message("Updating jsoncpp cache variables! ${__jsoncpp_info_string}")
set(JSONCPP_CACHED_JSONCPP_DIR_DETAILS "${__jsoncpp_info_string}" CACHE INTERNAL "" FORCE)
unset(JSONCPP_IMPORTED_LIBRARY_SHARED)
unset(JSONCPP_IMPORTED_LIBRARY_STATIC)
unset(JSONCPP_IMPORTED_LIBRARY)
unset(JSONCPP_IMPORTED_INCLUDE_DIRS)
unset(JSONCPP_IMPORTED_LIBRARY_IS_SHARED)

# if(__jsoncpp_have_jsoncpplib) is equivalent to if(TARGET jsoncpp_lib) except it excludes our
# "invented" jsoncpp_lib interface targets, made for convenience purposes after this block.

if(__jsoncpp_have_jsoncpplib AND TARGET jsoncpp_lib_static)

# A veritable cache of riches - we have both shared and static!
set(JSONCPP_IMPORTED_LIBRARY_SHARED jsoncpp_lib CACHE INTERNAL "" FORCE)
set(JSONCPP_IMPORTED_LIBRARY_STATIC jsoncpp_lib_static CACHE INTERNAL "" FORCE)
if(WIN32 OR CYGWIN OR MINGW)
# DLL platforms: static library should be default
set(JSONCPP_IMPORTED_LIBRARY ${JSONCPP_IMPORTED_LIBRARY_STATIC} CACHE INTERNAL "" FORCE)
set(JSONCPP_IMPORTED_LIBRARY_IS_SHARED FALSE CACHE INTERNAL "" FORCE)
else()
# Other platforms - might require PIC to be linked into shared libraries, so safest to prefer shared.
set(JSONCPP_IMPORTED_LIBRARY ${JSONCPP_IMPORTED_LIBRARY_SHARED} CACHE INTERNAL "" FORCE)
set(JSONCPP_IMPORTED_LIBRARY_IS_SHARED TRUE CACHE INTERNAL "" FORCE)
endif()

# As a convenience...
if(TARGET jsoncpp_lib_static AND NOT TARGET jsoncpp_lib)
add_library(jsoncpp_lib INTERFACE)
target_link_libraries(jsoncpp_lib INTERFACE jsoncpp_lib_static)
elseif(TARGET jsoncpp_lib_static)
# Well, only one variant, but we know for sure that it's static.
set(JSONCPP_IMPORTED_LIBRARY_STATIC jsoncpp_lib_static CACHE INTERNAL "" FORCE)
set(JSONCPP_IMPORTED_LIBRARY jsoncpp_lib_static CACHE INTERNAL "" FORCE)
set(JSONCPP_IMPORTED_LIBRARY_IS_SHARED FALSE CACHE INTERNAL "" FORCE)

elseif(__jsoncpp_have_jsoncpplib AND __jsoncpp_lib_type STREQUAL "STATIC_LIBRARY")
# We were able to figure out the mystery library is static!
set(JSONCPP_IMPORTED_LIBRARY_STATIC jsoncpp_lib CACHE INTERNAL "" FORCE)
set(JSONCPP_IMPORTED_LIBRARY jsoncpp_lib CACHE INTERNAL "" FORCE)
set(JSONCPP_IMPORTED_LIBRARY_IS_SHARED FALSE CACHE INTERNAL "" FORCE)

elseif(__jsoncpp_have_jsoncpplib AND __jsoncpp_lib_type STREQUAL "SHARED_LIBRARY")
# We were able to figure out the mystery library is shared!
set(JSONCPP_IMPORTED_LIBRARY_SHARED jsoncpp_lib CACHE INTERNAL "" FORCE)
set(JSONCPP_IMPORTED_LIBRARY jsoncpp_lib CACHE INTERNAL "" FORCE)
set(JSONCPP_IMPORTED_LIBRARY_IS_SHARED TRUE CACHE INTERNAL "" FORCE)

elseif(__jsoncpp_have_jsoncpplib)
# One variant, and we have no idea if this is just an old version or if
# this is shared based on the target name alone. Hmm.
set(JSONCPP_IMPORTED_LIBRARY jsoncpp_lib CACHE INTERNAL "" FORCE)
endif()

# Now, we need include directories. Can't just limit this to old CMakes, since
# new CMakes might be used to build projects designed to support older ones.
if(__jsoncpp_have_jsoncpplib)
get_property(__jsoncpp_interface_include_dirs TARGET jsoncpp_lib PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
if(__jsoncpp_interface_include_dirs)
set(JSONCPP_IMPORTED_INCLUDE_DIRS "${__jsoncpp_interface_include_dirs}" CACHE INTERNAL "" FORCE)
endif()
endif()
if(TARGET jsoncpp_lib_static AND NOT JSONCPP_IMPORTED_INCLUDE_DIRS)
get_property(__jsoncpp_interface_include_dirs TARGET jsoncpp_lib_static PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
if(__jsoncpp_interface_include_dirs)
set(JSONCPP_IMPORTED_INCLUDE_DIRS "${__jsoncpp_interface_include_dirs}" CACHE INTERNAL "" FORCE)
endif()
endif()
endif()

# As a convenience...
if(TARGET jsoncpp_lib_static AND NOT TARGET jsoncpp_lib)
add_library(jsoncpp_lib INTERFACE)
target_link_libraries(jsoncpp_lib INTERFACE jsoncpp_lib_static)
endif()

if(JSONCPP_IMPORTED_LIBRARY)
if(NOT JSONCPP_IMPORTED_INCLUDE_DIRS)
# OK, so we couldn't get it from the target... maybe we can figure it out from jsoncpp_DIR.
Expand Down Expand Up @@ -146,6 +213,7 @@ if(JSONCPP_IMPORTED_LIBRARY)

find_package_handle_standard_args(JsonCpp
DEFAULT_MSG
jsoncpp_DIR
JSONCPP_IMPORTED_LIBRARY
JSONCPP_IMPORTED_INCLUDE_DIRS)
endif()
Expand Down Expand Up @@ -173,6 +241,14 @@ if(JSONCPP_FOUND)
INTERFACE_INCLUDE_DIRECTORIES "${JSONCPP_IMPORTED_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${JSONCPP_IMPORTED_LIBRARY_STATIC}")
endif()

# Hide the stuff we didn't, and no longer, need.
if(NOT JsonCpp_LIBRARY)
unset(JsonCpp_LIBRARY CACHE)
endif()
if(NOT JsonCpp_INCLUDE_DIR)
unset(JsonCpp_INCLUDE_DIR CACHE)
endif()
endif()

set(JSONCPP_LIBRARY ${JSONCPP_IMPORTED_LIBRARY})
Expand Down Expand Up @@ -308,10 +384,9 @@ if(NOT JSONCPP_FOUND)
add_library(JsonCpp::JsonCpp ALIAS jsoncpp_interface)
endif()
endif()
mark_as_advanced(JsonCpp_INCLUDE_DIR JsonCpp_LIBRARY)
endif()
endif()

if(JSONCPP_FOUND)
mark_as_advanced(jsoncpp_DIR)
mark_as_advanced(jsoncpp_DIR JsonCpp_INCLUDE_DIR JsonCpp_LIBRARY)
endif()
34 changes: 22 additions & 12 deletions cmake/FindSDL2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,25 @@

# Set up architectures (for windows) and prefixes (for mingw builds)
if(WIN32)
if(MINGW)
include(MinGWSearchPathExtras OPTIONAL)
if(MINGWSEARCH_TARGET_TRIPLE)
set(SDL2_PREFIX ${MINGWSEARCH_TARGET_TRIPLE})
endif()
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(SDL2_LIB_PATH_SUFFIX lib/x64)
if(NOT MSVC)
if(NOT MSVC AND NOT SDL2_PREFIX)
set(SDL2_PREFIX x86_64-w64-mingw32)
endif()
else()
set(SDL2_LIB_PATH_SUFFIX lib/x86)
if(NOT MSVC)
if(NOT MSVC AND NOT SDL2_PREFIX)
set(SDL2_PREFIX i686-w64-mingw32)
endif()
endif()
endif()

if(SDL2_PREFIX)
set(SDL2_ORIGPREFIXPATH ${CMAKE_PREFIX_PATH})
if(SDL2_ROOT_DIR)
Expand All @@ -38,6 +45,9 @@ if(SDL2_PREFIX)
list(APPEND CMAKE_PREFIX_PATH "${_prefix}/${SDL2_PREFIX}")
endforeach()
endif()
if(MINGWSEARCH_PREFIXES)
list(APPEND CMAKE_PREFIX_PATH ${MINGWSEARCH_PREFIXES})
endif()
endif()

# Invoke pkgconfig for hints
Expand Down Expand Up @@ -182,15 +192,15 @@ if(SDL2_FOUND)
)
endif()

if(APPLE)
# Need Cocoa here, is always a framework
find_library(SDL2_COCOA_LIBRARY Cocoa)
list(APPEND SDL2_EXTRA_REQUIRED SDL2_COCOA_LIBRARY)
if(SDL2_COCOA_LIBRARY)
set_target_properties(SDL2::SDL2 PROPERTIES
IMPORTED_LINK_INTERFACE_LIBRARIES ${SDL2_COCOA_LIBRARY})
endif()
endif()
if(APPLE)
# Need Cocoa here, is always a framework
find_library(SDL2_COCOA_LIBRARY Cocoa)
list(APPEND SDL2_EXTRA_REQUIRED SDL2_COCOA_LIBRARY)
if(SDL2_COCOA_LIBRARY)
set_target_properties(SDL2::SDL2 PROPERTIES
IMPORTED_LINK_INTERFACE_LIBRARIES ${SDL2_COCOA_LIBRARY})
endif()
endif()


# Compute what to do with SDL2main
Expand All @@ -201,7 +211,7 @@ if(SDL2_FOUND)
set_target_properties(SDL2::SDL2main_real
PROPERTIES
IMPORTED_LOCATION "${SDL2_SDLMAIN_LIBRARY}")
list(APPEND SDL2MAIN_LIBRARIES SDL2::SDL2main_real)
set(SDL2MAIN_LIBRARIES SDL2::SDL2main_real ${SDL2MAIN_LIBRARIES})
endif()
if(MINGW)
# MinGW requires some additional libraries to appear earlier in the link line.
Expand Down
Loading