Skip to content

Commit

Permalink
simplify the cmake script and add tls target
Browse files Browse the repository at this point in the history
  • Loading branch information
melode11 committed May 22, 2015
1 parent 98eaa16 commit 0c1be1b
Showing 1 changed file with 27 additions and 55 deletions.
82 changes: 27 additions & 55 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,54 +1,6 @@
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
PROJECT(sioclient)

function(get_lib_name out_lib_name component)
if(MSVC)
set(${out_lib_name} "${component}.lib" PARENT_SCOPE)
else()
set(${out_lib_name} "lib${component}.a" PARENT_SCOPE)
endif()
endfunction()

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")
install(FILES ${Boost_SYSTEM_LIBRARY_RELEASE}
CONFIGURATIONS "Release" DESTINATION ${lib_dir} RENAME ${renamed_system}
)
get_lib_name(renamed_date_time "boost_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")
install(FILES ${Boost_RANDOM_LIBRARY_RELEASE}
CONFIGURATIONS "Release" DESTINATION ${lib_dir} RENAME ${renamed_random}
)

install(TARGETS sioclient
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 )
Expand All @@ -67,7 +19,7 @@ find_package(Boost ${BOOST_VER} REQUIRED COMPONENTS system date_time random)
aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/src ALL_SRC)
aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/src/internal ALL_SRC)
file(GLOB ALL_HEADERS ${CMAKE_CURRENT_LIST_DIR}/src/*.h )
MESSAGE(STATUS ${ALL_HEADERS} )
set(SIO_INCLUDEDIR ${CMAKE_CURRENT_LIST_DIR})

add_library(sioclient STATIC ${ALL_SRC})
target_include_directories(sioclient PRIVATE ${Boost_INCLUDE_DIRS}
Expand All @@ -79,12 +31,32 @@ target_include_directories(sioclient PRIVATE ${Boost_INCLUDE_DIRS}
set_property(TARGET sioclient PROPERTY CXX_STANDARD 11)
set_property(TARGET sioclient PROPERTY CXX_STANDARD_REQUIRED ON)
target_link_libraries(sioclient PRIVATE ${Boost_LIBRARIES})

find_package(OpenSSL)
if(OPENSSL_FOUND)
add_library(sioclient_tls STATIC ${ALL_SRC})
target_include_directories(sioclient_tls PRIVATE ${Boost_INCLUDE_DIRS}
${CMAKE_CURRENT_LIST_DIR}/src
${CMAKE_CURRENT_LIST_DIR}/lib/websocketpp
${CMAKE_CURRENT_LIST_DIR}/lib/rapidjson/include
${OPENSSL_INCLUDE_DIR}
)

set_property(TARGET sioclient_tls PROPERTY CXX_STANDARD 11)
set_property(TARGET sioclient_tls PROPERTY CXX_STANDARD_REQUIRED ON)
target_link_libraries(sioclient_tls PRIVATE ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} )
target_compile_definitions(sioclient_tls PRIVATE -DSIO_TLS)

endif()

install(FILES ${ALL_HEADERS}
DESTINATION "${CMAKE_CURRENT_LIST_DIR}/build/include"
)
)

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()
install(TARGETS sioclient
DESTINATION "${CMAKE_CURRENT_LIST_DIR}/build/lib/${CMAKE_BUILD_TYPE}"
)

install(FILES ${Boost_LIBRARIES}
DESTINATION "${CMAKE_CURRENT_LIST_DIR}/build/lib/${CMAKE_BUILD_TYPE}"
)

0 comments on commit 0c1be1b

Please sign in to comment.