-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCMakeLists.txt
150 lines (124 loc) · 5.83 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
cmake_minimum_required(VERSION 3.8)
# *******************************************
# ************* CMake Content ***************
# *******************************************
# This CMake create a workspace containing the following projects
#
# Programs
# - stick_game
set (PROJECT_NAME stickgame)
project(${PROJECT_NAME})
# Add definition for relative path into project
add_definitions( -DPROJECT_ROOT_PATH="${CMAKE_CURRENT_SOURCE_DIR}")
# 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.*")
# Link with pthread
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
# Debug or release
if(CMAKE_BUILD_TYPE MATCHES "Debug")
MESSAGE("Generate Debug project")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Debug)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -pg -Wall")
else()
MESSAGE("Generate Release project")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Release)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_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()
# Add definitions for testing purposes
if(${TESTING})
MESSAGE("Testing mode")
add_definitions(-DNB_GENERATIONS=10)
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}")
file(COPY ${GEGELATI_DLL} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
if(${CMAKE_GENERATOR} MATCHES "Visual Studio.*")
file(COPY ${GEGELATI_DLL} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug)
file(COPY ${GEGELATI_DLL} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release)
endif()
endif()
# *******************************************
# ************** Executable ****************
# *******************************************
# Executable to learn the TPG
file(GLOB_RECURSE
stick_game_files
./src/Learn/*.cpp
./src/Learn/*.h
./params.json
)
include_directories(${GEGELATI_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} ${stick_game_files})
target_link_libraries(${PROJECT_NAME} ${GEGELATI_LIBRARIES})
target_compile_definitions(${PROJECT_NAME} PRIVATE ROOT_DIR="${CMAKE_SOURCE_DIR}")
# Code Gen example with the TPG store in the file stick-game/src/CodeGen/StickGame_out_best.dot
# Create the target that will generate the C code of the TPG
set(TARGET_CodeGen ${PROJECT_NAME}CodeGenCompile)
add_executable(${TARGET_CodeGen} src/Learn/instructions.cpp src/CodeGen/mainCodeGenCompile.cpp)
target_link_libraries(${TARGET_CodeGen} ${GEGELATI_LIBRARIES})
target_compile_definitions(${TARGET_CodeGen} PRIVATE ROOT_DIR="${CMAKE_SOURCE_DIR}")
if (WIN32)
set_target_properties(${TARGET_CodeGen} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR})
set_target_properties(${TARGET_CodeGen} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR})
endif()
# set and create the source directory where file generated by the codegen are saved.
# set a variable that groups all the codeGen files
set(SRC_CODEGEN ${CMAKE_CURRENT_BINARY_DIR}/src/)
set(SRC ./src/CodeGen)
file(MAKE_DIRECTORY ${SRC_CODEGEN})
include_directories(${SRC_CODEGEN} ${SRC})
# !!! Files are not properly handled in MSVS if they contains upper-case char or '_'
set(CODEGEN ${SRC_CODEGEN}/${PROJECT_NAME}.c ${SRC_CODEGEN}/${PROJECT_NAME}_program.c ${SRC_CODEGEN}/${PROJECT_NAME}.h ${SRC_CODEGEN}/${PROJECT_NAME}_program.h)
# set codeGen source file as generated
set_source_files_properties(${CODEGEN} PROPERTIES GENERATED TRUE)
# wrap generation of source file in a custom command + custom target
add_custom_command(OUTPUT ${CODEGEN} COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_CodeGen})
set(ExecCodeGen ${PROJECT_NAME}ExecCodeGen)
add_custom_target(${ExecCodeGen} DEPENDS ${CODEGEN})
add_dependencies(${ExecCodeGen} ${TARGET_CodeGen})
# set target name for the executable that use the codeGen files to do an inference
set(TARGET ${PROJECT_NAME}InferenceCodeGen)
# create binary that need the generated file
set(inference_codegen_files ${SRC}/mainCodeGenInference.cpp ./src/Learn/instructions.cpp ./src/Learn/stickGameAdversarial.cpp ${CODEGEN})
add_executable(${TARGET} ${inference_codegen_files})
target_link_libraries(${TARGET} ${GEGELATI_LIBRARIES})
target_include_directories(${TARGET} BEFORE PUBLIC ${SRC_CODEGEN})
target_compile_definitions(${TARGET} PRIVATE ROOT_DIR="${CMAKE_SOURCE_DIR}")
# set the custom target that generate the source file as a dependency of the target
add_dependencies(${TARGET} ${ExecCodeGen})
# Create a project that does the inference from the dot
set(TARGET_TPGInference ${PROJECT_NAME}TPGInference)
set(TARGET_TPGInference_files ${stick_game_files} ${SRC}/mainTPGInference.cpp)
list(REMOVE_ITEM TARGET_TPGInference_files "${CMAKE_CURRENT_SOURCE_DIR}/./src/Learn/main.cpp")
add_executable(${TARGET_TPGInference} ${TARGET_TPGInference_files})
target_compile_definitions(${TARGET_TPGInference} PRIVATE ROOT_DIR="${CMAKE_SOURCE_DIR}")
target_link_libraries(${TARGET_TPGInference} ${GEGELATI_LIBRARIES} )