From 95c3d47cd71b086c050c92b228e68c4c9729bdc8 Mon Sep 17 00:00:00 2001 From: "melo.yao" Date: Thu, 16 Apr 2015 01:20:50 +0800 Subject: [PATCH] fix stupid cmake mistakes --- CMakeLists.txt | 76 +++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4eb76218..d3cc01a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,60 +9,52 @@ set(${out_lib_name} "lib${component}.a" PARENT_SCOPE) endif() endfunction() -function(select_lib output_lib lib_list configuration) -list(LENGTH lib_list LIB_LEN ) -if(LIB_LEN GREATER 1) -set(LIB_MET OFF) -foreach(lib_i ${lib_list}) - if(LIB_MET) - set(${output_lib} ${lib_i} PARENT_SCOPE) - return() - endif() - if(NOT lib_i MATCHES ".*[Bb]oost.*" ) - if(lib_i STREQUAL "debug" ) - if(configuration STREQUAL "Debug") - set(${LIB_MET} ON) - endif() - else() - if(configuration STREQUAL "Release") - set(${LIB_MET} ON) - endif() - endif() - endif() -endforeach(lib_i) -else() -set(${output_lib} ${lib_list} PARENT_SCOPE) -endif() -endfunction() - -function(install_libs configuration lib_dir) +function(install_debug_libs lib_dir) +get_lib_name(renamed_system "boost_system") +install(FILES ${Boost_SYSTEM_LIBRARY_DEBUG} + CONFIGURATIONS "Debug" DESTINATION ${lib_dir} RENAME ${renamed_system} +) +get_lib_name(renamed_date_time "boost_date_time") +install(FILES ${Boost_DATE_TIME_LIBRARY_DEBUG} + CONFIGURATIONS "Debug" DESTINATION ${lib_dir} RENAME ${renamed_date_time} +) +get_lib_name(renamed_random "boost_random") +install(FILES ${Boost_RANDOM_LIBRARY_DEBUG} + CONFIGURATIONS "Debug" DESTINATION ${lib_dir} RENAME ${renamed_random} +) +install(TARGETS sioclient + CONFIGURATIONS "Debug" DESTINATION ${lib_dir} +) +endfunction() +function(install_release_libs lib_dir) get_lib_name(renamed_system "boost_system") -select_lib(src_lib_x ${Boost_SYSTEM_LIBRARY} ${configuration} ) -install(FILES ${src_lib_x} - CONFIGURATIONS ${configuration} DESTINATION ${lib_dir} RENAME ${renamed_system} +install(FILES ${Boost_SYSTEM_LIBRARY_RELEASE} + CONFIGURATIONS "Release" DESTINATION ${lib_dir} RENAME ${renamed_system} ) get_lib_name(renamed_date_time "boost_date_time") -select_lib(src_lib_y ${Boost_SYSTEM_LIBRARY} ${configuration} ) -install(FILES ${src_lib_y} - CONFIGURATIONS ${configuration} DESTINATION ${lib_dir} RENAME ${renamed_date_time} +install(FILES ${Boost_DATE_TIME_LIBRARY_RELEASE} + CONFIGURATIONS "Release" DESTINATION ${lib_dir} RENAME ${renamed_date_time} ) get_lib_name(renamed_random "boost_random") -select_lib(src_lib_z ${Boost_SYSTEM_LIBRARY} ${configuration} ) -install(FILES ${src_lib_z} - CONFIGURATIONS ${configuration} DESTINATION ${lib_dir} RENAME ${renamed_random} +install(FILES ${Boost_RANDOM_LIBRARY_RELEASE} + CONFIGURATIONS "Release" DESTINATION ${lib_dir} RENAME ${renamed_random} ) install(TARGETS sioclient - CONFIGURATIONS ${configuration} DESTINATION ${lib_dir} + CONFIGURATIONS "Release" DESTINATION ${lib_dir} ) endfunction() + MESSAGE(STATUS ${CMAKE_CURRENT_LIST_DIR}) if(NOT CMAKE_BUILD_TYPE ) MESSAGE(STATUS "not define build type, set to release" ) set(CMAKE_BUILD_TYPE Release ) +elseif(NOT (${CMAKE_BUILD_TYPE} STREQUAL "Release" OR ${CMAKE_BUILD_TYPE} STREQUAL "Debug" )) +MESSAGE(SEND_ERROR "CMAKE_BUILD_TYPE must be either Release or Debug") +return() endif() set(BOOST_VER "1.55.0" CACHE STRING "boost version" ) @@ -110,7 +102,9 @@ target_link_libraries(sioclient PRIVATE ${Boost_LIBRARIES}) install(FILES ${ALL_HEADERS} DESTINATION "${CMAKE_CURRENT_LIST_DIR}/build/include" ) -set(LIB_DIR_DEBUG "${CMAKE_CURRENT_LIST_DIR}/build/lib/debug") -set(LIB_DIR_RELEASE "${CMAKE_CURRENT_LIST_DIR}/build/lib/release") -install_libs(Debug ${LIB_DIR_DEBUG}) -install_libs(Release ${LIB_DIR_RELEASE}) + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") +install_debug_libs("${CMAKE_CURRENT_LIST_DIR}/build/lib/${CMAKE_BUILD_TYPE}" ) +else() +install_release_libs("${CMAKE_CURRENT_LIST_DIR}/build/lib/${CMAKE_BUILD_TYPE}" ) +endif()