-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
114 lines (95 loc) · 4.19 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
cmake_minimum_required(VERSION 3.8)
project(performance_CodeGen)
# Disable C and C++ compiler extensions.
# C/CXX_EXTENSIONS are ON by default to allow the compilers to use extended
# variants of the C/CXX language.
# However, this could expose cross-platform bugs in user code or in the headers
# of third-party dependencies and thus it is strongly suggested to turn
# extensions off.
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio.*")
# Set to 1 to activate debug compilation (0 for release)
set(DEBUG 0)
# Link with pthread
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
if(${DEBUG})
MESSAGE("Generate Debug project")
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Debug)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -pg -Wall")
else()
MESSAGE("Generate Release project")
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Release)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall")
endif()
#add libmath during non visual studio builds
set(CMAKE_EXTRA_LIB m)
else()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
# *******************************************
# *********** GEGELATI LIBRARY **************
# *******************************************
if(WIN32)
set(LIBS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib)
# find the gegelatilib-x.y.z folder in the lib directory.
file(GLOB GEGELATI_ROOT_DIR "${LIBS_DIR}/gegelatilib-[\\.|0-9]*")
set(ENV{GEGELATI_DIR} ${GEGELATI_ROOT_DIR})
endif()
find_package(GEGELATI)
if (WIN32)
file(GLOB
GEGELATI_DLL
${GEGELATI_ROOT_DIR}/bin/*.dll
)
MESSAGE("Copy GEGELATI DLLs into ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
if(NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio.*")
file(COPY ${GEGELATI_DLL} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
else()
file(COPY ${GEGELATI_DLL} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug)
file(COPY ${GEGELATI_DLL} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release)
endif()
endif()
# *******************************************
# ************** Executable ****************
# *******************************************
# Create the target that will generate the C code of the TPG
file(GLOB_RECURSE
CodeGenCompile_files
./src/CodeGenCompile/*.cpp
./src/CodeGenCompile/*.h
./params.json
)
set(TargetCodeGenCompile CodeGenCompile)
set(filename TPG)
add_executable(${TargetCodeGenCompile} ${CodeGenCompile_files})
target_link_libraries(${TargetCodeGenCompile} ${GEGELATI_LIBRARIES})
target_compile_definitions(${TargetCodeGenCompile} PRIVATE ROOT_DIR="${CMAKE_SOURCE_DIR}")
target_compile_definitions(${TargetCodeGenCompile} PRIVATE TPG_FILENAME="${filename}")
set(SRC_CODEGEN ${CMAKE_CURRENT_BINARY_DIR}/src/)
file(MAKE_DIRECTORY ${SRC_CODEGEN})
set(CODEGEN ${SRC_CODEGEN}/${filename}.c ${SRC_CODEGEN}/${filename}_program.c ${SRC_CODEGEN}/${filename}.h ${SRC_CODEGEN}/${filename}_program.h)
# wrap generation of source file in a custom command + custom target
add_custom_command(OUTPUT ${CODEGEN} COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TargetCodeGenCompile} )
set(ExecCodeGen CodeGenGenerate)
add_custom_target(${ExecCodeGen} DEPENDS ${CODEGEN})
add_dependencies(${ExecCodeGen} ${TargetCodeGenCompile})
include_directories(${SRC_CODEGEN} ./src/Inference/)
file(GLOB_RECURSE
ComparaisonInference_files
./src/Inference/*.cpp
./src/Inference/*.h
./params.json
)
set(TargetInference InferenceCompare)
add_executable(${TargetInference} ${ComparaisonInference_files} ${CODEGEN})
target_link_libraries(${TargetInference} ${GEGELATI_LIBRARIES})
target_compile_definitions(${TargetInference} PRIVATE ROOT_DIR="${CMAKE_SOURCE_DIR}")
target_compile_definitions(${TargetInference} PRIVATE TPG_FILENAME="${filename}")
# set the custom target that generate the source file as a dependency of the target
add_dependencies(${TargetInference} ${ExecCodeGen})