forked from chipsalliance/Surelog
/
CMakeLists.txt
118 lines (104 loc) · 3.45 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
# -*- mode:cmake -*-
cmake_minimum_required(VERSION 3.15)
# Usage:
# After a make install at the top drectory:
# cd tests/TestInstall;
# rm -rf build;
# mkdir -p build;
# cd build;
# cmake ../ -DINSTALL_DIR=/usr/local;
# make
# ./test_hellosureworld --version
project(HELLOSUREWORLD)
# NOTE: Policy changes has to happen before adding any subprojects
cmake_policy(SET CMP0091 NEW)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Python
if (SURELOG_WITH_PYTHON)
find_package(Python3 3.3 REQUIRED COMPONENTS Interpreter Development)
message(STATUS "Python3_LIBRARIES = ${Python3_LIBRARIES}")
message(STATUS "Python3_EXECUTABLE = ${Python3_EXECUTABLE}")
message(STATUS "Python3_INCLUDE_DIRS = ${Python3_INCLUDE_DIRS}")
message(STATUS "Python3_RUNTIME_LIBRARY_DIRS = ${Python3_RUNTIME_LIBRARY_DIRS}")
endif()
if(NOT NO_TCMALLOC)
find_library(TCMALLOC_LIBRARY NAMES tcmalloc)
endif()
# Directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TCMALLOC_COMPILE_OPTIONS} ${MY_CXX_WARNING_FLAGS}")
if(MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${TCMALLOC_COMPILE_OPTIONS} /Zc:__cplusplus /W0 /bigobj ${MY_CXX_WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${TCMALLOC_COMPILE_OPTIONS} /Zc:__cplusplus /W0 /bigobj ${MY_CXX_WARNING_FLAGS}")
else()
# C++ Compilation line
if($<BOOL:${TCMALLOC_LIBRARY}>)
set (TCMALLOC_COMPILE_OPTIONS "-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free")
endif($<BOOL:${TCMALLOC_LIBRARY}>)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${TCMALLOC_COMPILE_OPTIONS} -Wall -O0 -g ${MY_CXX_WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${TCMALLOC_COMPILE_OPTIONS} -Wall -O3 -DNDEBUG ${MY_CXX_WARNING_FLAGS}")
endif()
add_executable(test_hellosureworld ${PROJECT_SOURCE_DIR}/../../src/hellosureworld.cpp)
target_include_directories(test_hellosureworld PRIVATE
${INSTALL_DIR}/include/surelog
${INSTALL_DIR}/include
${Python3_INCLUDE_DIRS}
)
target_link_directories(test_hellosureworld
PRIVATE ${INSTALL_DIR}/lib/surelog
PRIVATE ${INSTALL_DIR}/lib/uhdm
)
if (SURELOG_WITH_PYTHON)
target_link_libraries(test_hellosureworld
surelog
antlr4-runtime$<$<CXX_COMPILER_ID:MSVC,Clang>:-static>
flatbuffers
uhdm
capnp
kj
${Python3_LIBRARIES}
$<$<BOOL:${TCMALLOC_LIBRARY}>:tcmalloc>
)
else()
target_link_libraries(test_hellosureworld
surelog
antlr4-runtime$<$<CXX_COMPILER_ID:MSVC,Clang>:-static>
flatbuffers
uhdm
capnp
kj
$<$<BOOL:${TCMALLOC_LIBRARY}>:tcmalloc>
)
endif()
if (APPLE)
target_link_libraries(test_hellosureworld
dl
util
m
pthread
)
elseif (UNIX)
target_link_libraries(test_hellosureworld
stdc++fs
dl
util
m
rt
pthread
)
endif()
if (WIN32 AND SURELOG_WITH_PYTHON)
add_custom_command(
TARGET test_hellosureworld
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${Python3_RUNTIME_LIBRARY_DIRS}/python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}$<$<CONFIG:Debug>:_d>.dll
$<TARGET_FILE_DIR:test_hellosureworld>)
endif()
add_custom_target(RunInstallTest ALL
DEPENDS test_hellosureworld
COMMAND $<TARGET_FILE:test_hellosureworld> --version
WORKING_DIRECTORY $<TARGET_FILE_DIR:test_hellosureworld>)