-
Notifications
You must be signed in to change notification settings - Fork 0
/
MeBuild.cmake
101 lines (94 loc) · 3.53 KB
/
MeBuild.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function(me_install_target target)
if(TARGET install-${target})
return()
endif()
if(NOT TARGET install-all)
add_custom_target(install-all)
add_custom_target(install-all-stripped)
endif()
add_custom_target(
install-${target}
DEPENDS ${target}-
COMMENT "[${target}] install"
COMMAND "${CMAKE_COMMAND}"
-DCMAKE_INSTALL_COMPONENT="${target}"
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
)
add_custom_target(
install-${target}-stripped
DEPENDS ${target}-
COMMENT "[${target}-stripped] install"
COMMAND "${CMAKE_COMMAND}"
-DCMAKE_INSTALL_COMPONENT="${target}"
-DCMAKE_INSTALL_DO_STRIP=1
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
)
add_dependencies(install-all install-${target})
add_dependencies(install-all-stripped install-${target}-stripped)
endfunction(me_install_target)
function(me_build_lib)
file(
GLOB_RECURSE sources
${ME_SOURCE_DIR}/*.c
${ME_SOURCE_DIR}/*.cc
${ME_SOURCE_DIR}/*.cpp
${ME_SOURCE_DIR}/*.m
${ME_SOURCE_DIR}/*.mm
)
list(
REMOVE_ITEM sources
${ME_SOURCE_DIR}/main.c ${ME_SOURCE_DIR}/main.cpp
${ME_SOURCE_DIR}/dllmain.c ${ME_SOURCE_DIR}/dllmain.cpp
)
set(version_file ${ME_BUILD_DIR}/version.cpp)
me_generate_version(
${version_file}
${ME_PROJECT_NAME}
${ME_PROJECT_VERSION}
"${ME_MINOR_VERSION}"
"${ME_BUILD_VERSION}"
)
list(APPEND sources ${version_file})
if(EXISTS ${ME_SOURCE_DIR}/api.hpp)
set(header_file ${ME_BUILD_DIR}/include/${ME_PROJECT_NAME}/${ME_PROJECT_NAME}.h)
me_generate_header(
${ME_SOURCE_DIR}/api.hpp
${header_file}
)
list(APPEND sources ${header_file})
include_directories(${ME_BUILD_DIR}/include)
endif()
add_library(${ME_PROJECT} ${sources})
set_target_properties(${ME_PROJECT} PROPERTIES OUTPUT_NAME ${ME_PROJECT_NAME})
endfunction(me_build_lib)
function(me_build_dll)
if(EXISTS ${ME_SOURCE_DIR}/dllmain.cpp)
add_library(${ME_PROJECT}-dll SHARED ${ME_SOURCE_DIR}/dllmain.cpp)
target_link_libraries(${ME_PROJECT}-dll ${ME_PROJECT})
set_target_properties(${ME_PROJECT}-dll PROPERTIES OUTPUT_NAME ${ME_PROJECT_NAME})
install(TARGETS ${ME_PROJECT}-dll COMPONENT ${ME_PROJECT} DESTINATION bin)
me_install_target(${ME_PROJECT})
endif()
endfunction(me_build_dll)
function(me_build_exe)
if(EXISTS ${ME_SOURCE_DIR}/main.cpp)
add_executable(${ME_PROJECT}-exe ${ME_SOURCE_DIR}/main.cpp)
target_link_libraries(${ME_PROJECT}-exe ${ME_PROJECT})
set_target_properties(${ME_PROJECT}-exe PROPERTIES OUTPUT_NAME ${ME_PROJECT_NAME})
install(TARGETS ${ME_PROJECT}-exe COMPONENT ${ME_PROJECT} DESTINATION bin)
me_install_target(${ME_PROJECT})
endif()
endfunction(me_build_exe)
function(me_build_test)
file(GLOB_RECURSE sources ${ME_TEST_DIR}/*.cpp ${ME_TEST_DIR}/*.c)
list(LENGTH sources count)
if(count EQUAL 0)
return()
endif()
list(APPEND X_TEST_DEPENDS gtest-1.8.1--main)
me_import(${X_TEST_DEPENDS})
add_executable(${ME_PROJECT}-test EXCLUDE_FROM_ALL ${sources})
set_target_properties(${ME_PROJECT}-test PROPERTIES OUTPUT_NAME ${ME_PROJECT_NAME}.test)
target_link_libraries(${ME_PROJECT}-test ${ME_PROJECT} ${X_TEST_DEPENDS} ${X_TEST_LIBS})
target_include_directories(${ME_PROJECT}-test PUBLIC ${ME_IMPORTED_INCLUDES})
endfunction(me_build_test)