-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
110 lines (92 loc) · 3.48 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
cmake_minimum_required(VERSION 3.14)
project(pbn)
if(POLICY CMP0144)
cmake_policy(SET CMP0144 NEW)
endif()
# Set the default build type if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_VERBOSE_MAKEFILE ON)
set(PUBLISH_DIR "${CMAKE_BINARY_DIR}/publish")
set(PUBLISH_CONFIG "Debug")
set(BOOST_ROOT /opt/homebrew/Cellar/boost/1.85.0)
# Optionally configure platform-specific flags or settings
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(MAKEFILE "Makefile_linux_shared")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(MAKEFILE "Makefile_Mac_clang_shared")
endif()
# Find Boost
find_package(Boost 1.56 REQUIRED COMPONENTS thread CONFIG)
if(Boost_FOUND)
set(CC_BOOST ${BOOST_ROOT})
include_directories(${Boost_INCLUDE_DIRS})
add_definitions(-DBOOST_ALL_NO_LIB)
else()
message(FATAL_ERROR "Could not find Boost libraries")
endif()
# Add the DDS library as an external project
include(ExternalProject)
ExternalProject_Add(dds
# Define where to download the project from
GIT_REPOSITORY "https://github.com/zdenecek/dds.git"
GIT_TAG "develop" # You can specify a branch, tag, or commit
# Directory to store the source and build
PREFIX "${CMAKE_BINARY_DIR}/dds"
# Configure, build, and install commands
CONFIGURE_COMMAND ""
BUILD_COMMAND bash -c "cd src && make -f Makefiles/${MAKEFILE} CC_BOOST=${CC_BOOST} &&\
shopt -s nullglob &&\
mkdir -p ${CMAKE_BINARY_DIR}/pbn-lib &&\
cp *.so *.a *.dll ${CMAKE_BINARY_DIR}/pbn-lib &&\
cp *.so *.a *.dll ${CMAKE_BINARY_DIR}/dds &&\
shopt -u nullglob"
BUILD_IN_SOURCE 1 # Optional: Use if building in the source directory is required
INSTALL_COMMAND ""
TEST_COMMAND ""
)
set(ENV{DDS_LIB_PATH} "${CMAKE_BINARY_DIR}/dds")
# Detect the current platform and set the RID accordingly
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(RUNTIME_IDENTIFIER "win-x64")
else()
set(RUNTIME_IDENTIFIER "win-x86")
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set(RUNTIME_IDENTIFIER "osx-arm64")
else()
set(RUNTIME_IDENTIFIER "osx-x64")
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(RUNTIME_IDENTIFIER "linux-x64")
else()
set(RUNTIME_IDENTIFIER "linux-x86")
endif()
else()
message(FATAL_ERROR "Unsupported platform")
endif()
# Copy the .NET project to the build directory
add_custom_target(
CopyDotnetProject ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/pbn" "${CMAKE_BINARY_DIR}/pbn"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/pbn-lib" "${CMAKE_BINARY_DIR}/pbn-lib"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/pbn.sln" "${CMAKE_BINARY_DIR}/pbn.sln"
COMMENT "Copying .NET project to build directory"
)
# Add custom target for the .NET project to depend on the DDS build
add_custom_target(
DotnetBuild ALL
COMMAND dotnet build "${CMAKE_BINARY_DIR}/pbn" -o "${CMAKE_BINARY_DIR}/build" -r ${RUNTIME_IDENTIFIER}
DEPENDS CopyDotnetProject dds # Ensures that the DDS library is built first
COMMENT "Building .NET Application"
)
add_custom_target(
DotnetPublish ALL
COMMAND dotnet publish "${CMAKE_BINARY_DIR}/pbn" -c ${PUBLISH_CONFIG} -r ${RUNTIME_IDENTIFIER} --self-contained true -o "${PUBLISH_DIR}"
DEPENDS CopyDotnetProject dds # Ensures that the DDS library is built first
COMMENT "Publishing .NET Application"
)