Make FC's CMakeLists.txt provide a list of required DLLs to projects that use it

This commit is contained in:
Eric Frias 2014-03-14 11:04:37 -04:00
parent d3c2f60fe0
commit 0e6e86f273
2 changed files with 120 additions and 3 deletions

View file

@ -48,7 +48,6 @@ IF( WIN32 )
FIND_PACKAGE(Boost 1.54 REQUIRED COMPONENTS coroutine)
SET(Boost_LIBRARIES ${BOOST_LIBRARIES_TEMP} ${Boost_LIBRARIES})
ENDIF()
ELSE(WIN32)
MESSAGE(STATUS "Configuring fc to build on Unix/Apple")
@ -65,7 +64,6 @@ ELSE(WIN32)
ENDIF(NOT APPLE)
ENDIF(WIN32)
find_package( OpenSSL )
set( CMAKE_FIND_LIBRARY_SUFFIXES ${ORIGINAL_LIB_SUFFIXES} )
@ -162,7 +160,7 @@ list(APPEND sources ${fc_headers})
add_subdirectory( vendor/easylzma )
setup_library( fc SOURCES ${sources} LIBRARY_TYPE STATIC )
setup_library( fc SOURCES ${sources} LIBRARY_TYPE STATIC DONT_INSTALL_LIBRARY )
IF(WIN32)
target_compile_definitions(fc PUBLIC WIN32 NOMINMAX _WIN32_WINNT=0x0501 _CRT_SECURE_NO_WARNINGS
@ -205,5 +203,45 @@ target_link_libraries( fc easylzma_static ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES
#add_executable( test_sleep tests/sleep.cpp )
#target_link_libraries( test_sleep fc )
if(WIN32)
# now generate a list of the DLLs we're using to use during the install process
include (ParseLibraryList)
PARSE_LIBRARY_LIST(${Boost_LIBRARIES}
FOUND parseOk
DEBUG Boost_LIBRARIES_DEBUG
OPT Boost_LIBRARIES_RELEASE
GENERAL Boost_LIBRARIES_GENERAL)
set(SHARED_LIBRARIES_RELEASE)
foreach(boost_import_lib ${Boost_LIBRARIES_RELEASE})
get_filename_component(import_lib_name_root ${boost_import_lib} NAME_WE)
get_filename_component(import_lib_path ${boost_import_lib} PATH)
set(boost_dll "${import_lib_path}/${import_lib_name_root}${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(SHARED_LIBRARIES_RELEASE ${SHARED_LIBRARIES_RELEASE} ${boost_dll})
endforeach()
set(SHARED_LIBRARIES_DEBUG)
foreach(boost_import_lib ${Boost_LIBRARIES_DEBUG})
get_filename_component(import_lib_name_root ${boost_import_lib} NAME_WE)
get_filename_component(import_lib_path ${boost_import_lib} PATH)
set(boost_dll "${import_lib_path}/${import_lib_name_root}${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(SHARED_LIBRARIES_DEBUG ${SHARED_LIBRARIES_DEBUG} ${boost_dll})
endforeach()
foreach(lib ${OPENSSL_LIBRARIES})
get_filename_component(lib_name ${lib} NAME_WE)
if (${lib_name} STREQUAL "libeay32")
get_filename_component(lib_dir ${lib} DIRECTORY)
get_filename_component(lib_bin_dir "${lib_dir}/../bin" REALPATH)
set(SHARED_LIBRARIES_DEBUG ${SHARED_LIBRARIES_DEBUG} "${lib_bin_dir}/${lib_name}${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(SHARED_LIBRARIES_RELEASE ${SHARED_LIBRARIES_RELEASE} "${lib_bin_dir}/${lib_name}${CMAKE_SHARED_LIBRARY_SUFFIX}")
endif()
endforeach()
set_property(TARGET fc PROPERTY SHARED_LIBRARIES_DEBUG ${SHARED_LIBRARIES_DEBUG})
set_property(TARGET fc PROPERTY SHARED_LIBRARIES_RELEASE ${SHARED_LIBRARIES_RELEASE})
endif(WIN32)
MESSAGE(STATUS "Finished fc module configuration...")

View file

@ -0,0 +1,79 @@
# -*- mode: cmake -*-
#
# Shamelessly stolen from MSTK who shamelessly stole from Amanzi open source code https://software.lanl.gov/ascem/trac)
#
# PARSE_LIBRARY_LIST( <lib_list>
# DEBUG <out_debug_list>
# OPT <out_opt_list>
# GENERAL <out_gen_list> )
# CMake module
include(CMakeParseArguments)
function(PARSE_LIBRARY_LIST)
# Macro: _print_usage
macro(_print_usage)
message("PARSE_LIBRARY_LIST <lib_list>\n"
" FOUND <out_flag>\n"
" DEBUG <out_debug_list>\n"
" OPT <out_opt_list>\n"
" GENERAL <out_gen_list>\n"
"lib_list string to parse\n"
"FOUND flag to indicate if keywords were found\n"
"DEBUG variable containing debug libraries\n"
"OPT variable containing optimized libraries\n"
"GENERAL variable containing debug libraries\n")
endmacro()
# Read in args
cmake_parse_arguments(PARSE_ARGS "" "FOUND;DEBUG;OPT;GENERAL" "" ${ARGN})
set(_parse_list "${PARSE_ARGS_UNPARSED_ARGUMENTS}")
if ( (NOT PARSE_ARGS_FOUND) OR
(NOT PARSE_ARGS_DEBUG) OR
(NOT PARSE_ARGS_OPT) OR
(NOT PARSE_ARGS_GENERAL) OR
(NOT _parse_list )
)
_print_usage()
message(FATAL_ERROR "Invalid arguments")
endif()
# Now split the list
set(_debug_libs "")
set(_opt_libs "")
set(_gen_libs "")
foreach( item ${_parse_list} )
if( ${item} MATCHES debug OR
${item} MATCHES optimized OR
${item} MATCHES general )
if( ${item} STREQUAL "debug" )
set( mylist "_debug_libs" )
elseif( ${item} STREQUAL "optimized" )
set( mylist "_opt_libs" )
elseif( ${item} STREQUAL "general" )
set( mylist "_gen_libs" )
endif()
else()
list( APPEND ${mylist} ${item} )
endif()
endforeach()
# Now set output vairables
set(${PARSE_ARGS_DEBUG} "${_debug_libs}" PARENT_SCOPE)
set(${PARSE_ARGS_OPT} "${_opt_libs}" PARENT_SCOPE)
set(${PARSE_ARGS_GENERAL} "${_gen_libs}" PARENT_SCOPE)
# If any of the lib lists are defined set flag to TRUE
if ( (_debug_libs) OR (_opt_libs) OR (_gen_libs) )
set(${PARSE_ARGS_FOUND} TRUE PARENT_SCOPE)
else()
set(${PARSE_ARGS_FOUND} FALSE PARENT_SCOPE)
endif()
endfunction(PARSE_LIBRARY_LIST)