Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 123 lines (92 sloc) 4.602 kb
cbf67dd0 » dscharrer
2011-07-19 Use boost::filesystem to load non-packed asset files.
1
2 function(check_compiler_flag RESULT FLAG)
3
4 if(DEFINED CHECK_COMPILER_FLAG_${FLAG})
5 if(CHECK_COMPILER_FLAG_${FLAG})
6 set(${RESULT} "${FLAG}" PARENT_SCOPE)
7 else()
8 set(${RESULT} "" PARENT_SCOPE)
9 endif()
10 return()
11 endif()
12
e978655d » dscharrer
2011-09-20 Fix library link check for mingw32 on windows.
13 set(compile_test_file "${CMAKE_CURRENT_BINARY_DIR}/compile_flag_test.cpp")
cbf67dd0 » dscharrer
2011-07-19 Use boost::filesystem to load non-packed asset files.
14 file(WRITE ${compile_test_file} "__attribute__((const)) int main(){ return 0; }\n")
f7cc6083 » dscharrer
2011-09-20 There is no need to pass CMAKE_CXX_COMPILER to try_compile.
15 try_compile(CHECK_COMPILER_FLAG ${CMAKE_BINARY_DIR} ${compile_test_file} COMPILE_DEFINITIONS "${FLAG}" OUTPUT_VARIABLE ERRORLOG)
cbf67dd0 » dscharrer
2011-07-19 Use boost::filesystem to load non-packed asset files.
16
17 string(REGEX MATCH "warning:" HAS_WARNING "${ERRORLOG}")
18
19 if(NOT CHECK_COMPILER_FLAG)
20 message(STATUS "Checking compiler flag: ${FLAG} - unsupported")
21 set(${RESULT} "" PARENT_SCOPE)
22 set("CHECK_COMPILER_FLAG_${FLAG}" 0 CACHE INTERNAL "...")
23 elseif(NOT HAS_WARNING STREQUAL "")
24 message(STATUS "Checking compiler flag: ${FLAG} - unsupported (warning)")
25 set(${RESULT} "" PARENT_SCOPE)
26 set("CHECK_COMPILER_FLAG_${FLAG}" 0 CACHE INTERNAL "...")
27 else()
28 message(STATUS "Checking compiler flag: ${FLAG}")
29 set(${RESULT} "${FLAG}" PARENT_SCOPE)
30 set("CHECK_COMPILER_FLAG_${FLAG}" 1 CACHE INTERNAL "...")
31 endif()
32
33 endfunction(check_compiler_flag)
34
35 function(add_cxxflag FLAG)
36
37 check_compiler_flag(RESULT "${FLAG}")
38
39 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${RESULT}" PARENT_SCOPE)
40
41 endfunction(add_cxxflag)
42
0a1b7ca2 » dscharrer
2012-04-03 CMake: Don't include linker flags in CMAKE_CXX_FLAGS or older gcc ver…
43 function(add_ldflag FLAG)
44
45 check_compiler_flag(RESULT "${FLAG}")
46
47 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${RESULT}" PARENT_SCOPE)
48 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${RESULT}" PARENT_SCOPE)
49 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${RESULT}" PARENT_SCOPE)
50
51 endfunction(add_ldflag)
52
cbf67dd0 » dscharrer
2011-07-19 Use boost::filesystem to load non-packed asset files.
53 function(try_link_library LIBRARY_NAME LIBRARY_FILE ERROR_VAR)
54 # See if we can link a simple program with the library using the configured c++ compiler.
e978655d » dscharrer
2011-09-20 Fix library link check for mingw32 on windows.
55 set(link_test_file "${CMAKE_CURRENT_BINARY_DIR}/link_test.cpp")
cbf67dd0 » dscharrer
2011-07-19 Use boost::filesystem to load non-packed asset files.
56 file(WRITE ${link_test_file} "int main(){}\n")
57 if(CMAKE_THREAD_LIBS_INIT)
e978655d » dscharrer
2011-09-20 Fix library link check for mingw32 on windows.
58 list(APPEND LIBRARY_FILE "${CMAKE_THREAD_LIBS_INIT}")
cbf67dd0 » dscharrer
2011-07-19 Use boost::filesystem to load non-packed asset files.
59 endif()
f7cc6083 » dscharrer
2011-09-20 There is no need to pass CMAKE_CXX_COMPILER to try_compile.
60 try_compile(CHECK_${LIBRARY_NAME}_LINK "${CMAKE_BINARY_DIR}" "${link_test_file}" CMAKE_FLAGS "-DLINK_LIBRARIES=${LIBRARY_FILE}" OUTPUT_VARIABLE ERRORLOG)
cbf67dd0 » dscharrer
2011-07-19 Use boost::filesystem to load non-packed asset files.
61 set(${ERROR_VAR} "${ERRORLOG}" PARENT_SCOPE)
62 endfunction(try_link_library)
63
64 ##############################################################################
65 # Check that a a library actually works for the current configuration.
66 function(check_link_library LIBRARY_NAME LIBRARY_VARIABLE)
67
68 set(lib_current "${${LIBRARY_VARIABLE}}")
69 set(found_var "ARX_CLL_${LIBRARY_NAME}_FOUND")
70 set(working_var "ARX_CLL_${LIBRARY_NAME}_WORKING")
71
72 if(CHECK_${LIBRARY_NAME}_LINK)
73 set(lib_found "${${found_var}}")
74 set(lib_working "${${working_var}}")
75 if((lib_current STREQUAL lib_found) OR (lib_current STREQUAL lib_working))
76 set("${LIBRARY_VARIABLE}" "${lib_working}" PARENT_SCOPE)
77 return()
78 endif()
79 endif()
80
81 set("${found_var}" "${lib_current}" CACHE INTERNAL "...")
82
93c7f5b7 » dscharrer
2012-01-06 Improve check_link_library: don't print anything if the library strin…
83 if(NOT lib_current STREQUAL "")
84 message(STATUS "Checking ${LIBRARY_NAME}: ${lib_current}")
85 endif()
cbf67dd0 » dscharrer
2011-07-19 Use boost::filesystem to load non-packed asset files.
86
87 # Check if we can link to the full path found by find_package.
88 try_link_library(${LIBRARY_NAME} "${lib_current}" ERRORLOG1)
89
90 if(CHECK_${LIBRARY_NAME}_LINK)
91 set("${working_var}" "${lib_current}" CACHE INTERNAL "...")
92 return()
93 endif()
94
95 # Check if the linker is smarter than cmake and try to link with only the library name.
96 string(REGEX REPLACE "(^|;)[^;]*/lib([^;/]*)\\.so" "\\1-l\\2" LIBRARY_FILE "${lib_current}")
97
93c7f5b7 » dscharrer
2012-01-06 Improve check_link_library: don't print anything if the library strin…
98 if(NOT LIBRARY_FILE STREQUAL lib_current)
99
100 try_link_library(${LIBRARY_NAME} "${LIBRARY_FILE}" ERRORLOG2)
101
102 if(CHECK_${LIBRARY_NAME}_LINK)
103 message(STATUS " -> using ${LIBRARY_FILE} instead")
104 set("${LIBRARY_VARIABLE}" "${LIBRARY_FILE}" PARENT_SCOPE)
105 set("${working_var}" "${LIBRARY_FILE}" CACHE INTERNAL "...")
106 return()
107 endif()
108
cbf67dd0 » dscharrer
2011-07-19 Use boost::filesystem to load non-packed asset files.
109 endif()
110
111 # Force cmake to search again, as the cached library doesn't work.
112 unset(FIND_PACKAGE_MESSAGE_DETAILS_${ARGV2} CACHE)
113 unset(FIND_PACKAGE_MESSAGE_DETAILS_${LIBRARY_NAME} CACHE)
114
3b0c9abb » dscharrer
2012-02-18 CMake: Improve error message when the found library cannot be linked.
115 message(FATAL_ERROR "\n${ERRORLOG1}\n\n${ERRORLOG2}\n\n!! No suitable version of ${LIBRARY_NAME} found.\n Maybe you don't have the right (32 vs.64 bit) architecture installed?\n\n Tried ${lib_current} and ${LIBRARY_FILE}\n Using compiler ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS}\n\n\n")
cbf67dd0 » dscharrer
2011-07-19 Use boost::filesystem to load non-packed asset files.
116
117 endfunction(check_link_library)
118
119 function(force_recheck_library LIBRARY_NAME)
120 unset(FIND_PACKAGE_MESSAGE_DETAILS_${ARGV1} CACHE)
121 unset(FIND_PACKAGE_MESSAGE_DETAILS_${LIBRARY_NAME} CACHE)
122 unset(CHECK_${LIBRARY_NAME}_LINK CACHE)
123 endfunction()
Something went wrong with that request. Please try again.