56 lines
2.2 KiB
CMake
56 lines
2.2 KiB
CMake
cmake_minimum_required(VERSION 3.11)
|
|
message( "current compiler " ${CMAKE_CXX_COMPILER_ID})
|
|
message("current CXX compiler is " ${CMAKE_CXX_COMPILER})
|
|
message("current X compiler is " ${CMAKE_CXX_COMPILER})
|
|
message("current make is " ${CMAKE_MAKE_PROGRAM})
|
|
enable_language(CXX)
|
|
project(generallib)
|
|
add_subdirectory(general)
|
|
SET(SRC_SDK sdk_main.c test/src/heapsort/main.c)#生成动态库需要至少包含一个源文件
|
|
message("library object is " $<TARGET_OBJECTS:General>)
|
|
add_library(generallib STATIC $<TARGET_OBJECTS:General> ${SRC_SDK})
|
|
message("CMAKE_BINARY_DIR is " ${CMAKE_BINARY_DIR})
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/libd)
|
|
link_directories(general/third/lib)
|
|
set_target_properties(generallib PROPERTIES LINKER_LANGUAGE CXX)
|
|
target_link_libraries(generallib public
|
|
-Wl,--whole-archive
|
|
libevent.a
|
|
-Wl,--no-whole-archive
|
|
)
|
|
message("current path is" ${CMAKE_CURRENT_SOURCE_DIR})
|
|
IF (WIN32)
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
message("using clang")
|
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
|
message("using gcc")
|
|
add_custom_command (
|
|
TARGET generallib POST_BUILD
|
|
COMMAND ar -x
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libd/libevent.a
|
|
COMMENT "package library ar -x ${CMAKE_CURRENT_SOURCE_DIR}/libd/libevent.a "
|
|
)
|
|
add_custom_command (
|
|
TARGET generallib POST_BUILD
|
|
COMMAND ar -x
|
|
${CMAKE_CURRENT_SOURCE_DIR}/cmake-build-debug/libgeneral.a
|
|
COMMENT "package library ar -x ${CMAKE_CURRENT_SOURCE_DIR}/libd/libgeneral.a "
|
|
)
|
|
add_custom_command (
|
|
TARGET generallib POST_BUILD
|
|
COMMAND ar rc libgeneral.a *.o *.obj
|
|
COMMENT "package library ar rc *.o *.obj"
|
|
)
|
|
add_custom_command(
|
|
TARGET generallib POST_BUILD
|
|
COMMAND del *.o *.obj
|
|
COMMENT "remove all step library"
|
|
)
|
|
# using GCC
|
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
|
|
message("using asm")
|
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
|
message("using msvc")
|
|
endif()
|
|
|
|
endif() |