forked from bupticybee/TexasSolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
134 lines (115 loc) · 4.11 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
125
126
127
128
129
130
131
132
133
134
cmake_minimum_required(VERSION 3.20)
option(USE_CUDA "" OFF)
option(QT_GUI "" ON)
option(BUILD_API "" ON)
if(USE_CUDA)
project(TexasSolver LANGUAGES CXX CUDA)
else()
project(TexasSolver LANGUAGES CXX)
endif()
set(CMAKE_CXX_STANDARD 20)
# set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
message("CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories(include)
find_package(OpenMP REQUIRED)
message("OpenMP_CXX_FLAGS=${OpenMP_CXX_FLAGS}")
file(GLOB_RECURSE SRC src/*.cpp)
file(GLOB_RECURSE EXC_SRC src/*format.cpp)
file(GLOB GUI_SRC *.cpp src/ui/*.cpp src/runtime/qsolverjob.cpp)
file(GLOB API_SRC src/api.cpp)
file(GLOB EXE_SRC src/console.cpp)
list(REMOVE_ITEM SRC ${EXC_SRC} ${GUI_SRC} ${EXE_SRC} ${API_SRC})
# message("SRC=${SRC}")
# message("EXC_SRC=${EXC_SRC}")
# message("GUI_SRC=${GUI_SRC}")
# message("API_SRC=${API_SRC}")
# message("EXE_SRC=${EXE_SRC}")
if(USE_CUDA)
add_definitions(-DUSE_CUDA)
file(GLOB_RECURSE CUDA_SRC src/*.cu)
message("CUDA_SRC=${CUDA_SRC}")
set(CMAKE_CUDA_STANDARD 20)
# set(CMAKE_CUDA_STANDARD_REQUIRED ON)
message("CMAKE_MINOR_VERSION=${CMAKE_MINOR_VERSION}")
if(${CMAKE_MINOR_VERSION} GREATER_EQUAL 24)
# set(CMAKE_CUDA_ARCHITECTURES all)
set(CMAKE_CUDA_ARCHITECTURES all-major)
# set(CMAKE_CUDA_ARCHITECTURES native)
else()
set(CMAKE_CUDA_ARCHITECTURES OFF)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -arch=all-major")
endif()
message("CMAKE_CUDA_ARCHITECTURES=${CMAKE_CUDA_ARCHITECTURES}")
message("CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
if((DEFINED CMAKE_BUILD_TYPE) AND (CMAKE_BUILD_TYPE STREQUAL Debug))
set(CMAKE_CUDA_FLAGS "-g -G ${CMAKE_CUDA_FLAGS}")
endif()
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler ${OpenMP_CXX_FLAGS}")
message("CMAKE_CUDA_FLAGS=${CMAKE_CUDA_FLAGS}")
endif()
set(BASE_LIB TexasSolver)
add_library(${BASE_LIB} ${SRC} ${CUDA_SRC})
target_link_libraries(${BASE_LIB} PUBLIC OpenMP::OpenMP_CXX)
if(USE_CUDA)
# set_target_properties(${BASE_LIB} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
endif()
if(BUILD_API)
set(API_TARGET api)
add_library(${API_TARGET} SHARED ${API_SRC})
target_link_libraries(${API_TARGET} PUBLIC ${BASE_LIB})
endif()
set(EXE console_solver)
add_executable(${EXE} ${EXE_SRC})
target_link_libraries(${EXE} PRIVATE ${BASE_LIB})
if(MSVC)
target_link_options(${EXE} PUBLIC "/NODEFAULTLIB:LIBCMT")
endif()
if(QT_GUI)
file(GLOB FORMS *.ui)
file(GLOB RESOURCES *.qrc)
file(GLOB TS_FILES *.ts)
file(GLOB QM_FILES *.qm)
# message("FORMS=${FORMS}")
# message("RESOURCES=${RESOURCES}")
# message("TS_FILES=${TS_FILES}")
# message("QM_FILES=${QM_FILES}")
# set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
set(QT_MAJOR Qt${QT_VERSION_MAJOR})
message("QT_MAJOR=${QT_MAJOR}")
find_package(${QT_MAJOR} REQUIRED COMPONENTS Core Widgets LinguistTools)
SET(ICON_NAME texassolver_logo)
if(WIN32)
file(GLOB ICON_FILE imgs/${ICON_NAME}.rc)
elseif(APPLE)
set(MACOSX_BUNDLE_ICON_FILE ${ICON_NAME}.icns)
file(GLOB ICON_FILE imgs/${ICON_NAME}.icns)
set_source_files_properties(${ICON_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
endif()
# message("ICON_FILE=${ICON_FILE}")
# set(CMAKE_AUTOMOC ON) doesn't work
# Q_OBJECT header
file(GLOB HEADERS *.h include/ui/*.h include/runtime/qsolverjob.h)
# message("HEADERS=${HEADERS}")
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt6_wrap_cpp(GUI_SRC ${HEADERS})
else()
qt5_wrap_cpp(GUI_SRC ${HEADERS})
endif()
# message("GUI_SRC=${GUI_SRC}")
set(GUI TexasSolverGui)
add_executable(${GUI} ${GUI_SRC} ${EXC_SRC} ${RESOURCES} ${FORMS} ${ICON_FILE})
target_link_libraries(${GUI} PRIVATE ${QT_MAJOR}::Widgets ${QT_MAJOR}::Core ${BASE_LIB})
set_target_properties(${GUI} PROPERTIES
WIN32_EXECUTABLE ON
MACOSX_BUNDLE ON
)
endif()