Commit cc82fb8f authored by Johan Ström's avatar Johan Ström

Improve openzwave detection on Darwin

parent 0432f9de
......@@ -22,22 +22,22 @@ if(OpenZWave_INCLUDE_BASE_DIR)
set(OpenZWave_LIBRARIES ${OpenZWave_LIBRARIES})
set(OpenZWave_INCLUDE_DIRS ${OpenZWave_INCLUDE_BASE_DIR} ${OpenZWave_INCLUDE_BASE_DIR}/openzwave)
# Determine which version of OpenZWave we have
set(CMAKE_REQUIRED_INCLUDES "${OpenZWave_INCLUDE_DIRS}")
set(CMAKE_REQUIRED_LIBRARIES "${OpenZWave_LIBRARIES}")
IF(NOT DEFINED "OpenZWave_VERSION")
# This mimics CHECK_CXX_SOURCE_RUNS, but need to do manually to use RUN_OUTPUT_VARIABLE
# Determine which version of OpenZWave we have
set(CMAKE_REQUIRED_INCLUDES "${OpenZWave_INCLUDE_DIRS}")
set(CMAKE_REQUIRED_LIBRARIES "${OpenZWave_LIBRARIES}")
set(SOURCE "#include <iostream>
#include <stdint.h>
extern uint16_t ozw_vers_major;
extern uint16_t ozw_vers_minor;
extern uint16_t ozw_vers_revision;
int main(void){
std::cout << ozw_vers_major << ';' << ozw_vers_minor << ';' << ozw_vers_revision;
return 0;
}")
set(SOURCE "#include <iostream>
#include <stdint.h>
extern uint16_t ozw_vers_major;
extern uint16_t ozw_vers_minor;
extern uint16_t ozw_vers_revision;
int main(void){
std::cout << ozw_vers_major << ';' << ozw_vers_minor << ';' << ozw_vers_revision;
return 0;
}")
# This mimics CHECK_CXX_SOURCE_RUNS, but need to do manually to use RUN_OUTPUT_VARIABLE
IF(NOT DEFINED "OpenZWave_VERSION")
set(MACRO_CHECK_FUNCTION_DEFINITIONS "-DOpenZWave_VERSION ${CMAKE_REQUIRED_FLAGS}")
set(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
......@@ -46,6 +46,14 @@ int main(void){
file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx"
"${SOURCE}\n")
if(OS_DARWIN)
# On Darwin it tries to search system paths for library, even if given explicit path
# On FreeBSD (and probably linux?) it uses the rpath flag to link to specific library instead.
set(RESTORE_LIBRARY_PATH "$ENV{DYLD_LIBRARY_PATH}")
get_filename_component(OpenZWave_LIBRARY_PATH "${OpenZWave_LIBRARIES}" DIRECTORY)
set(ENV{DYLD_LIBRARY_PATH} "${OpenZWave_LIBRARY_PATH}:$ENV{DYLD_LIBRARY_PATH}")
endif()
try_run(OpenZWave_VERSION_EXITCODE OpenZWave_VERSION_COMPILED
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx
......@@ -54,19 +62,30 @@ int main(void){
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
-DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH}
"${CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES}"
COMPILE_OUTPUT_VARIABLE OUTPUT
COMPILE_OUTPUT_VARIABLE BUILD_OUTPUT
RUN_OUTPUT_VARIABLE OpenZWave_VERSION)
if(NOT OpenZWave_VERSION_COMPILED)
if(OS_DARWIN)
set(ENV{DYLD_LIBRARY_PATH} "${RESTORE_DYLD_LIBRARY_PATH}")
endif()
if(NOT OpenZWave_VERSION_COMPILED OR OpenZWave_VERSION_EXITCODE)
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Performing C++ SOURCE FILE Test OpenZWave_VERSION failed with the following output:\n"
"${OUTPUT}\n"
"Performing OpenZWave_VERSION test failed.\n"
"Compile result: ${OpenZWave_VERSION_COMPILED}\n"
"Return value: ${OpenZWave_VERSION_EXITCODE}\n"
"Compile output:\n"
"${BUILD_OUTPUT}\n"
"Run output:\n"
"${OpenZWave_VERSION}\n"
"Source file was:\n${SOURCE}\n")
message(FATAL_ERROR "OpenZWave found but failed to determine version, build error."
message(FATAL_ERROR "OpenZWave found but failed to determine version.\n"
"See CMakeError.log for more details.")
endif()
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_LIBRARIES)
set( OpenZWave_VERSION_LIST ${OpenZWave_VERSION} )
separate_arguments(OpenZWave_VERSION_LIST)
list(GET OpenZWave_VERSION_LIST 0 OpenZWave_VERSION_MAJOR)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment