forked from chenall/ALMRun
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
124 lines (122 loc) · 4.09 KB
/
CMakeLists.txt
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
cmake_minimum_required(VERSION 2.8.11)
set(PROJ_NAME ALMRun)
set(CMAKE_VS_PLATFORM_TOOLSET v110_xp)
project(${PROJ_NAME})
# platform
math(EXPR BIT "${CMAKE_SIZEOF_VOID_P} * 8")
if(WIN32)
set(PLATFORM win${BIT})
# wxWidgets path
set(WXWIN $ENV{WXWIN})
if (NOT WXWIN)
set(WXWIN D:/dev/wxWidgets)
ENDIF()
if (NOT EXISTS ${WXWIN}/include/msvc/wx/setup.h)
MESSAGE(FATAL_ERROR "\nwxWidgets 库设置(${WXWIN})可能不正确\n编译需要至少wxWidgets 2.9.5以上版本")
endif()
elseif(APPLE)
set(PLATFORM macos)
elseif(UNIX)
set(PLATFORM linux${BIT})
else()
message(FATAL_ERROR "The platform isn't supported")
endif()
message(STATUS "Platform - ${PLATFORM}")
# build type
set(ALL_BUILD_TYPE Release Debug)
if(NOT CMAKE_BUILD_TYPE)
list(GET ALL_BUILD_TYPE 0 BUILD_TYPE_0)
set(CMAKE_BUILD_TYPE ${BUILD_TYPE_0})
endif()
foreach(BUILD_TYPE ${ALL_BUILD_TYPE})
string(TOLOWER ${BUILD_TYPE} BUILD_TYPE_LOWER)
string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER)
if(${BUILD_TYPE_LOWER} STREQUAL ${CMAKE_BUILD_TYPE_LOWER})
set(IS_VALID_BUILD_TYPE 1)
endif()
endforeach()
if(NOT IS_VALID_BUILD_TYPE)
message(FATAL_ERROR "Build type ${CMAKE_BUILD_TYPE} isn't supported")
endif()
message(STATUS "Build type (Makefile) - ${CMAKE_BUILD_TYPE}")
# set output directory
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build)
# add executable
aux_source_directory(src SRCS)
aux_source_directory(src/Dialog SRCS)
include_directories(src src/Dialog)
include_directories(${WXWIN}/include ${WXWIN}/include/msvc)
link_directories(${WXWIN}/lib/vc_lib)
if(NOT APPLE)
file(GLOB OBJC_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/*.mm)
list(REMOVE_ITEM SRCS ${OBJC_SRCS})
endif()
if(WIN32)
add_executable(${PROJ_NAME} WIN32 ${SRCS} resource/merry.rc)
else(APPLE)
add_executable(${PROJ_NAME} MACOSX_BUNDLE ${SRCS})
else()
add_executable(${PROJ_NAME} ${SRCS})
endif()
# add third party libraries
file(GLOB ALL_THIRD_PARTY_PATH third_party/*)
foreach(THIRD_PARTY_PATH ${ALL_THIRD_PARTY_PATH})
if(NOT (${THIRD_PARTY_PATH} MATCHES "\\.svn$"))
message(STATUS "Add third party libraries:\n\tPATH: " ${THIRD_PARTY_PATH})
file(GLOB ALL_INCLUDE_PATH ${THIRD_PARTY_PATH}/${PLATFORM}/include ${THIRD_PARTY_PATH}/include)
message("\tinclude directories:")
foreach(INCLUDE_PATH ${ALL_INCLUDE_PATH})
message("\t " ${THIRD_PARTY_PATH})
include_directories(${INCLUDE_PATH})
endforeach()
foreach(BUILD_TYPE ${ALL_BUILD_TYPE})
string(TOLOWER ${BUILD_TYPE} BUILD_TYPE_LOWER)
if (STATIC)
set(THIRD_PARTY_LIB_PATH ${THIRD_PARTY_PATH}/${PLATFORM}/static)
message(STATUS "Build ${BUILD_TYPE} using STATIC lib")
else()
set(THIRD_PARTY_LIB_PATH ${THIRD_PARTY_PATH}/${PLATFORM}/${BUILD_TYPE_LOWER})
endif()
file(GLOB ALL_LIB_PATH ${THIRD_PARTY_LIB_PATH}/*.a ${THIRD_PARTY_LIB_PATH}/*.lib)
message("\ttarget_link_libraries:(${BUILD_TYPE})")
foreach(LIB_PATH ${ALL_LIB_PATH})
message("\t " ${LIB_PATH})
if(${BUILD_TYPE_LOWER} STREQUAL debug)
target_link_libraries(${PROJ_NAME} debug ${LIB_PATH})
else()
target_link_libraries(${PROJ_NAME} optimized ${LIB_PATH})
endif()
endforeach()
endforeach()
endif()
endforeach()
if(UNIX)
find_package(wxWidgets REQUIRED)
include(${wxWidgets_USE_FILE})
target_link_libraries(${PROJ_NAME} ${wxWidgets_LIBRARIES})
endif()
# set flags 如果使用了-DRTL=MT参数,则使用/MT参数编译,这样产生的程序不依赖运行库
if(WIN32)
if (RTL STREQUAL MT)
foreach(FLAG_VAR
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELWITHDEBINFO)
string(REGEX REPLACE "/MD" "/MT" ${FLAG_VAR} "${${FLAG_VAR}}")
endforeach()
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_UNICODE -DUNICODE /wd4996")
target_link_libraries(${PROJ_NAME} comctl32 rpcrt4)
endif()
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()
# configuration types
if(CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES ${ALL_BUILD_TYPE})
set(CMAKE_CONFIGURATION_TYPES ${CMAKE_CONFIGURATION_TYPES} CACHE STRING
"Configuration types" FORCE)
message(STATUS "Configuration types - ${CMAKE_CONFIGURATION_TYPES}")
endif()