commit 3b14de740df6b5733e65c5d0fe850cb24b1a8cd1
Author: Kornel Benko <[email protected]>
Date: Thu Jun 12 19:02:29 2014 +0200
Cmake build: Symplify use of linking optional libraries found via
find_package
diff --git a/development/cmake/modules/FindMagic.cmake
b/development/cmake/modules/FindMagic.cmake
index 74902a2..6472101 100644
--- a/development/cmake/modules/FindMagic.cmake
+++ b/development/cmake/modules/FindMagic.cmake
@@ -55,22 +55,8 @@ find_library(Magic_LIBRARY NAMES "magic")
check_magic_functions_exists(HAS_MAGIC_FUNCTIONS)
-if(Magic_INCLUDE_DIR AND Magic_LIBRARY AND HAS_MAGIC_FUNCTIONS)
- set(Magic_FOUND TRUE)
-endif()
-
-if(Magic_FOUND)
- if(NOT Magic_FIND_QUIETLY)
- message(STATUS "Found magic library: ${Magic_LIBRARY}")
- endif()
-else()
- if(Magic_FIND_REQUIRED)
- message(STATUS "Looked for magic library named magic.")
- message(STATUS "Found no acceptable magic library. This is fatal.")
- message(STATUS "magic header: ${Magic_INCLUDE_DIR}")
- message(STATUS "magic lib : ${Magic_LIBRARY}")
- message(FATAL_ERROR "Could NOT find magic library")
- endif()
-endif()
+# handle the QUIET and REQUIRED arguments and DEFAULT_MSG
+# set Magic_FOUND to TRUE if all listed variables are TRUE
-mark_as_advanced(Magic_LIBRARY Magic_INCLUDE_DIR)
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Magic DEFAULT_MSG Magic_INCLUDE_DIR
Magic_LIBRARY HAS_MAGIC_FUNCTIONS)
diff --git a/development/cmake/modules/LyXMacros.cmake
b/development/cmake/modules/LyXMacros.cmake
index bcbca73..999fb95 100644
--- a/development/cmake/modules/LyXMacros.cmake
+++ b/development/cmake/modules/LyXMacros.cmake
@@ -329,3 +329,14 @@ macro(setmarkedtestlabel testname reverted)
endif()
endmacro()
+
+macro(lyx_target_link_libraries _target)
+ foreach(_lib ${ARGN})
+ string(TOUPPER ${_lib} _ulib)
+ if(${_ulib}_FOUND)
+ #message(STATUS "target_link_libraries(${_target} ${${_lib}_LIBRARY})")
+ target_link_libraries(${_target} ${${_lib}_LIBRARY})
+ endif()
+ endforeach()
+endmacro()
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2fa3291..fdd33e7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -134,18 +134,7 @@ target_link_libraries(${_lyx}
${QT_QTMAIN_LIBRARY}
${vld_dll})
-if(HUNSPELL_FOUND)
- target_link_libraries(${_lyx} ${HUNSPELL_LIBRARY})
-endif()
-if(ASPELL_FOUND)
- target_link_libraries(${_lyx} ${ASPELL_LIBRARY})
-endif()
-if(ENCHANT_FOUND)
- target_link_libraries(${_lyx} ${ENCHANT_LIBRARY})
-endif()
-if(Magic_FOUND)
- target_link_libraries(${_lyx} ${Magic_LIBRARY})
-endif()
+lyx_target_link_libraries(${_lyx} HUNSPELL ASPELL ENCHANT Magic)
if(APPLE)
target_link_libraries(${_lyx} "-bind_at_load")
diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt
index c7accee..926eebc 100644
--- a/src/client/CMakeLists.txt
+++ b/src/client/CMakeLists.txt
@@ -30,12 +30,9 @@ target_link_libraries(${_lyxclient}
${Lyx_Boost_Libraries}
${ICONV_LIBRARY}
${QT_QTCORE_LIBRARY}
- ${QT_QTGUI_LIBRARY}
- ${Magic_LIBRARY})
+ ${QT_QTGUI_LIBRARY})
-if(ASPELL_FOUND)
- target_link_libraries(${_lyxclient} ${ASPELL_LIBRARY})
-endif()
+lyx_target_link_libraries(${_lyxclient} Magic ASPELL)
if(APPLE)
target_link_libraries(${_lyxclient} "-framework AppKit")
diff --git a/src/support/tests/CMakeLists.txt b/src/support/tests/CMakeLists.txt
index ed4f9bb..990e538 100644
--- a/src/support/tests/CMakeLists.txt
+++ b/src/support/tests/CMakeLists.txt
@@ -15,7 +15,8 @@ macro(sources _program)
add_executable(${_program} ${_tmplist})
target_link_libraries(${_program} support
${Lyx_Boost_Libraries} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY}
- ${ZLIB_LIBRARY} ${ICONV_LIBRARY} ${Magic_LIBRARY})
+ ${ZLIB_LIBRARY} ${ICONV_LIBRARY})
+ lyx_target_link_libraries(${_program} Magic)
endmacro()
file(GLOB test_sources ${TOP_SRC_DIR}/src/support/tests/${LYX_CPP_FILES})
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 2d7aa0c..52ca1e3 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -18,7 +18,8 @@ add_executable(check_layout ${check_layout_SOURCES})
target_link_libraries(check_layout support
${Lyx_Boost_Libraries} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY}
- ${ZLIB_LIBRARY} ${ICONV_LIBRARY} ${Magic_LIBRARY})
+ ${ZLIB_LIBRARY} ${ICONV_LIBRARY})
+lyx_target_link_libraries(check_layout Magic)
add_dependencies(lyx_run_tests check_layout)
set_target_properties(check_layout PROPERTIES FOLDER "tests/src")
diff --git a/src/tex2lyx/CMakeLists.txt b/src/tex2lyx/CMakeLists.txt
index ed827bb..38ae574 100644
--- a/src/tex2lyx/CMakeLists.txt
+++ b/src/tex2lyx/CMakeLists.txt
@@ -48,8 +48,9 @@ target_link_libraries(${_tex2lyx}
${Lyx_Boost_Libraries}
${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
- ${ICONV_LIBRARY}
- ${Magic_LIBRARY})
+ ${ICONV_LIBRARY})
+
+lyx_target_link_libraries(${_tex2lyx} Magic)
add_dependencies(${_tex2lyx} lyx_version)