-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
179 lines (146 loc) · 5.38 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
cmake_minimum_required(VERSION 3.20)
set(PROJECT_NAME pt4)
project(${PROJECT_NAME})
option(USE_OPENMP "Build with OpenMP" ON)
option(BUILD_TESTS "Build unit tests" ON)
set (CMAKE_CXX_STANDARD 20)
set (CMAKE_CXX_STANDARD_REQUIRED True)
set (CMAKE_C_STANDARD 11)
set (CMAKE_C_STANDARD_REQUIRED True)
set(CTDR_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/inc)
set(CTDR_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
set(LIBRARY_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/lib)
set(LEX_YY_C ${CMAKE_BINARY_DIR}/lex.yy.c)
set(Y_TAB_H ${CMAKE_BINARY_DIR}/y.tab.h)
set(Y_TAB_C ${CMAKE_BINARY_DIR}/y.tab.c)
set(PHANTOM_L ${CTDR_SOURCE_DIR}/phantom.l)
set(PHANTOM_Y ${CTDR_SOURCE_DIR}/phantom.y)
##libraries
find_package(netCDF QUIET)
if(NOT netCDF_FOUND)
find_package(PkgConfig REQUIRED)
pkg_search_module(netcdf REQUIRED netcdf)
message(STATUS "netcdf_INCLUDEDIR ${netcdf_INCLUDEDIR}")
message(STATUS "netcdf_LIBDIR ${netcdf_LIBDIR}")
message(STATUS "netcdf_LIBRARIES ${netcdf_LIBRARIES}")
set(netCDF_INCLUDE_DIR ${netcdf_INCLUDEDIR})
set(netCDF_LIB_DIR ${netcdf_LIBDIR})
set(netCDF_LIBRARIES ${netcdf_LIBRARIES})
endif()
add_library(simplecpp ${LIBRARY_INCLUDE_DIR}/simplecpp/simplecpp.cpp)
add_subdirectory(${LIBRARY_INCLUDE_DIR}/libtiff)
if(USE_OPENMP)
find_package(OpenMP)
endif()
set(CTDR_SOURCE_FILES
${CTDR_SOURCE_DIR}/cmd_actions.cpp
${CTDR_SOURCE_DIR}/pt4.cpp
${CTDR_SOURCE_DIR}/primative.cpp
${CTDR_SOURCE_DIR}/quaternion.cpp
${CTDR_SOURCE_DIR}/sim.cpp
${CTDR_SOURCE_DIR}/expression.cpp
${CTDR_SOURCE_DIR}/scan_spec.cpp
${CTDR_SOURCE_DIR}/util.cpp
${CTDR_SOURCE_DIR}/ndvec.cpp
${CTDR_SOURCE_DIR}/quick_rng.cpp
${LEX_YY_C}
${Y_TAB_C}
)
##main lib
add_library(libctdr OBJECT ${CTDR_SOURCE_FILES})
#main target
add_executable(${PROJECT_NAME} ${CTDR_SOURCE_DIR}/main.cpp )
function(open_mp_enable target_name)
target_compile_options(${target_name} PRIVATE
$<$<CXX_COMPILER_ID:MSVC>: /openmp>
$<$<CXX_COMPILER_ID:IntelLLVM>:
$<$<PLATFORM_ID:Windows>: /openmp>
$<$<PLATFORM_ID:Linux>: -fopenmp>
>
$<$<CXX_COMPILER_ID:GNU>: -fopenmp>
)
endfunction()
if(USE_OPENMP)
open_mp_enable(${PROJECT_NAME})
open_mp_enable(libctdr)
endif()
target_compile_options(${PROJECT_NAME} PRIVATE $<$<CXX_COMPILER_ID:IntelLLVM>: $<$<PLATFORM_ID:Windows>: /D_CRT_SECURE_NO_WARNINGS>>)
target_compile_options(libctdr PRIVATE $<$<CXX_COMPILER_ID:IntelLLVM>: $<$<PLATFORM_ID:Linux>: -w -Wno-c++11-narrowing>>)
target_compile_options(libctdr PRIVATE $<$<CXX_COMPILER_ID:GNU>: -pthread>)
target_compile_options(libctdr PRIVATE
$<$<CXX_COMPILER_ID:MSVC>: /fp:fast>
$<$<CXX_COMPILER_ID:GNU>: -ffast-math>
)
target_compile_options(libctdr PRIVATE
$<$<CXX_COMPILER_ID:MSVC>: /arch:AVX2>
$<$<CXX_COMPILER_ID:IntelLLVM>:
$<$<PLATFORM_ID:Windows>: /arch:AVX2>
$<$<PLATFORM_ID:Linux>: -march=broadwell -axSKYLAKE-AVX512,CASCADELAKE,SAPPHIRERAPIDS>
>
$<$<CXX_COMPILER_ID:GNU>: -march=native>
)
target_compile_options(libctdr PRIVATE
$<$<CXX_COMPILER_ID:MSVC>: /favor:INTEL64>
$<$<CXX_COMPILER_ID:GNU>: -mtune=native>
)
if(WIN32)
set_source_files_properties(${CTDR_SOURCE_DIR}/expression.cpp PROPERTIES COMPILE_FLAGS /bigobj)
endif()
include_directories(libctdr PUBLIC
"${CTDR_INCLUDE_DIR}"
"${LIBRARY_INCLUDE_DIR}/exprtk"
"${LIBRARY_INCLUDE_DIR}/libtiff"
"${LIBRARY_INCLUDE_DIR}/simplecpp"
"${netCDF_INCLUDE_DIR}"
"${CMAKE_BINARY_DIR}" #for y.tab.h
)
##link files
if(UNIX)
target_link_libraries(libctdr PUBLIC ${netCDF_LIBRARIES})
elseif(WIN32)
target_link_libraries(libctdr PUBLIC ${netCDF_LIB_DIR}/netcdf.lib)
endif()
target_link_libraries(libctdr PUBLIC simplecpp)
target_link_libraries(libctdr PUBLIC tiff)
if(USE_OPENMP)
target_link_libraries(libctdr PUBLIC ${OpenMP_CXX_LIBRARIES})
endif()
target_link_libraries(${PROJECT_NAME} PUBLIC libctdr)
################## testing ################################
if(BUILD_TESTS)
set(VERIFICATION_SOURCE_DIR ${PROJECT_SOURCE_DIR}/verification)
enable_testing()
include(${VERIFICATION_SOURCE_DIR}/CMakeLists.txt)
endif()
###########################################################
if (UNIX)
##for flex on linux
add_custom_command(
OUTPUT ${LEX_YY_C} # The output generated by the code generator
COMMAND flex -o${LEX_YY_C} ${PHANTOM_L}
DEPENDS ${PHANTOM_L} # Add dependencies like input files or the code generator executable
COMMENT "Flex: generating lexer"
)
##for yacc on linux
add_custom_command(
OUTPUT ${Y_TAB_C} ${Y_TAB_H} # The output generated by the code generator
COMMAND bison -d -o${Y_TAB_C} ${PHANTOM_Y}
DEPENDS ${PHANTOM_Y} # Add dependencies like input files or the code generator executable
COMMENT "Bison: generating parser"
)
elseif(WIN32)
##for flex on windows via wsl
add_custom_command(
OUTPUT ${LEX_YY_C} # The output generated by the code generator
COMMAND wsl flex -o`wslpath -u ${LEX_YY_C}` `wslpath -u ${PHANTOM_L}`
DEPENDS ${PHANTOM_L} # Add dependencies like input files or the code generator executable
COMMENT "Flex: generating lexer"
)
##for yacc on windows via wsl
add_custom_command(
OUTPUT ${Y_TAB_C} ${Y_TAB_H} # The output generated by the code generator
COMMAND wsl yacc -d `wslpath -u ${PHANTOM_Y}` -o`wslpath -u ${Y_TAB_C}`
DEPENDS ${PHANTOM_Y} # Add dependencies like input files or the code generator executable
COMMENT "Yacc: generating parser"
)
endif()