-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial CMake build support #252
Changes from 22 commits
2cacf53
629bd68
6cab7a6
d6988e9
073dbbc
2f3164c
120bfb6
dfdf9fc
3d65521
f10f863
6b36b24
88b7415
d262364
6bca412
4f3890d
976fb7e
3c934c6
fb0fd38
3ae0fda
4653ed9
a433039
a4fe07a
1084476
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
project(greeter CXX) | ||
|
||
include(../../cmake/common.cmake) | ||
|
||
add_executable(client Client.cpp Greeter.ice) | ||
slice2cpp_generate(client) | ||
target_link_libraries(client Ice::Ice) | ||
|
||
add_executable(server Server.cpp Chatbot.cpp Chatbot.h Greeter.ice) | ||
slice2cpp_generate(server) | ||
target_link_libraries(server Ice::Ice) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,37 @@ | |
|
||
The Greeter demo illustrates how to send a request and wait for the response. | ||
|
||
To build the demo run: | ||
|
||
```shell | ||
cmake -B build | ||
cmake --build build --config Release | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default is Debug? Should we just show the default? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I read cmake doesn't have a default and it's all about the generator's default which apparently in several cases is debug. |
||
``` | ||
|
||
To run the demo, first start the server: | ||
|
||
**Linux/macOS:** | ||
|
||
```shell | ||
./build/server | ||
``` | ||
server | ||
|
||
**Windows:** | ||
|
||
```shell | ||
.\build\Release\server | ||
``` | ||
|
||
In a separate window, start the client: | ||
|
||
**Linux/macOS:** | ||
|
||
```shell | ||
./build/client | ||
``` | ||
client | ||
|
||
**Windows:** | ||
|
||
```shell | ||
./build/Release/client | ||
externl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
project(greeter_async CXX) | ||
|
||
include(../../cmake/common.cmake) | ||
|
||
add_executable(client Client.cpp Greeter.ice) | ||
slice2cpp_generate(client) | ||
target_link_libraries(client Ice::Ice) | ||
|
||
add_executable(server Server.cpp Chatbot.cpp Chatbot.h Greeter.ice) | ||
slice2cpp_generate(server) | ||
target_link_libraries(server Ice::Ice) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,12 +2,36 @@ | |||||
|
||||||
The Greeter demo illustrates how to send a request and wait for the response. | ||||||
|
||||||
To build the demo run: | ||||||
|
||||||
```shell | ||||||
cmake -B build | ||||||
cmake --build build --config Release | ||||||
``` | ||||||
|
||||||
To run the demo, first start the server: | ||||||
|
||||||
**Linux/macOS:** | ||||||
|
||||||
```shell | ||||||
./build/server | ||||||
``` | ||||||
server | ||||||
|
||||||
**Windows:** | ||||||
|
||||||
```shell | ||||||
.\build\Release\server | ||||||
``` | ||||||
|
||||||
In a separate window, start the client: | ||||||
|
||||||
**Linux/macOS:** | ||||||
|
||||||
```shell | ||||||
./build/client | ||||||
``` | ||||||
client | ||||||
``` | ||||||
|
||||||
**Windows:** | ||||||
|
||||||
```shell | ||||||
./build/Release/client | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
project(secure CXX) | ||
|
||
include(../../cmake/common.cmake) | ||
|
||
add_executable(client Client.cpp Greeter.ice) | ||
slice2cpp_generate(client) | ||
target_link_libraries(client Ice::Ice) | ||
|
||
add_executable(server Server.cpp Chatbot.cpp Chatbot.h Greeter.ice) | ||
slice2cpp_generate(server) | ||
target_link_libraries(server Ice::Ice) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
find_package(Threads REQUIRED) | ||
|
||
if (NOT Ice_HOME) | ||
externl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (DEFINED ENV{ICE_HOME}) | ||
set(Ice_HOME $ENV{ICE_HOME}) | ||
else() | ||
message(FATAL_ERROR "Ice_HOME not set") | ||
externl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
endif() | ||
endif() | ||
|
||
if (NOT EXISTS ${Ice_HOME}) | ||
message(FATAL_ERROR "The specified Ice_HOME directory does not exist: ${Ice_HOME}") | ||
endif() | ||
|
||
find_program(Ice_SLICE2CPP_EXECUTABLE slice2cpp HINTS ${Ice_HOME}/cpp/bin PATH_SUFFIXES x64/Release x64/Debug) | ||
externl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (NOT Ice_SLICE2CPP_EXECUTABLE) | ||
message(FATAL_ERROR "slice2cpp executable not found") | ||
endif() | ||
|
||
if (NOT DEFINED Ice_SLICE_DIR) | ||
set(Ice_SLICE_DIR ${Ice_HOME}/slice CACHE PATH "Path to Ice slice files") | ||
endif() | ||
|
||
# TODO Use a variable | ||
if (WIN32) | ||
externl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
set(Ice_INCLUDE_DIRS ${Ice_HOME}/cpp/include ${Ice_HOME}/cpp/include/generated ${Ice_HOME}/cpp/include/generated/x64/Release) | ||
find_library(Ice_LIBRARY NAMES ice38a0 HINTS ${Ice_HOME}/cpp/lib PATH_SUFFIXES x64/Release) | ||
# set(Ice_LIBRARY ${ICE_LIBRARY} PARENT_SCOPE) | ||
elseif(APPLE) | ||
set(Ice_INCLUDE_DIRS ${Ice_HOME}/cpp/include ${Ice_HOME}/cpp/include/generated) | ||
set(Ice_LIBRARY ${Ice_HOME}/cpp/lib/libIce.dylib) | ||
# find_library(Ice_LIBRARY NAMES Ice.dylib HINTS ${Ice_HOME}/cpp/lib/) | ||
# set(Ice_LIBRARY ${ICE_LIBRARY} PARENT_SCOPE) | ||
else() | ||
set(Ice_INCLUDE_DIRS ${Ice_HOME}/cpp/include ${Ice_HOME}/cpp/include/generated) | ||
set(Ice_LIBRARY ${Ice_HOME}/cpp/lib/libIce.so) | ||
endif() | ||
|
||
add_library(Ice::Ice SHARED IMPORTED) | ||
set_target_properties(Ice::Ice PROPERTIES IMPORTED_IMPLIB ${Ice_LIBRARY}) | ||
set_target_properties(Ice::Ice PROPERTIES | ||
IMPORTED_LOCATION ${Ice_LIBRARY} | ||
INTERFACE_INCLUDE_DIRECTORIES "${Ice_INCLUDE_DIRS}" | ||
) | ||
|
||
# Function to generate C++ source files from Slice (.ice) files for a target using slice2cpp | ||
# The target must have the Slice files in its sources | ||
# The generated files are added to the target sources | ||
# Usage: | ||
# add_executable(a_target source1.cpp source2.ice source3.ice) | ||
# slice2cpp_generate(a_target) | ||
function(slice2cpp_generate TARGET) | ||
|
||
# Get the list of source files for the target | ||
get_target_property(sources ${TARGET} SOURCES) | ||
|
||
# Create a directory to store the generated files | ||
set(output_dir ${CMAKE_CURRENT_BINARY_DIR}/generated/${TARGET}) | ||
make_directory(${output_dir}) | ||
|
||
# Add the generated headers files to the target include directories | ||
target_include_directories(${TARGET} PRIVATE ${output_dir}) | ||
|
||
# Process each Slice (.ice) file in the source list | ||
# 1. Run the slice2cpp command to generate the header and source files | ||
# 2. Add the generated files to the target sources | ||
foreach(file IN LISTS sources) | ||
externl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if(file MATCHES "\\.ice$") | ||
|
||
get_filename_component(slice_file_name ${file} NAME_WE) | ||
get_filename_component(slice_file_path ${file} ABSOLUTE) | ||
set(output_files ${output_dir}/${slice_file_name}.h ${output_dir}/${slice_file_name}.cpp) | ||
|
||
add_custom_command( | ||
OUTPUT ${output_files} | ||
COMMAND ${Ice_SLICE2CPP_EXECUTABLE} -I${Ice_SLICE_DIR} ${slice_file_path} --output-dir ${output_dir} | ||
DEPENDS ${slice_file_path} | ||
COMMENT "${Ice_SLICE2CPP_EXECUTABLE} ${file} -> ${slice_file_name}.h ${slice_file_name}.cpp" | ||
) | ||
|
||
target_sources(${TARGET} PRIVATE ${output_files}) | ||
|
||
endif() | ||
endforeach() | ||
|
||
endfunction() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sets the
cmake
variableIce_HOME
to our usual "expected" location, adjacent to the ice-demos dir. This way you don't need to open visual studio code with the correct environment.