Skip to content

Commit ba5a8a1

Browse files
authored
Enhancet Build system with CMake (#43)
* multi component install `cmake --install . --component <lib/cl/unreal>` * Remove Unreal from all build * remove wrong required version * introduce `cpack` for auto release option * Update github/workflows to new build components * update building advices * update README
1 parent 4247ddc commit ba5a8a1

11 files changed

Lines changed: 100 additions & 40 deletions

File tree

.github/workflows/build.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ jobs:
2323
- os: windows-latest
2424
artifact: win64
2525
name: Windows x64
26-
inklecate_url: https://github.com/inkle/ink/releases/download/0.9.0/inklecate_windows_and_linux.zip
26+
inklecate_url: https://github.com/inkle/ink/releases/download/v1.0.0/inklecate_windows.zip
2727
proof: false
2828
- os: "ubuntu-20.04"
2929
artifact: linux
3030
name: Linux x64
31-
inklecate_url: https://github.com/inkle/ink/releases/download/0.9.0/inklecate_windows_and_linux.zip
32-
inklecate_pre: "mono "
33-
inklecate_post: ".exe"
31+
inklecate_url: https://github.com/inkle/ink/releases/download/v1.0.0/inklecate_linux.zip
3432
proof: true
3533

3634
steps:
@@ -94,7 +92,7 @@ jobs:
9492
- name: Install
9593
working-directory: ${{github.workspace}}/build
9694
shell: bash
97-
run: cmake --install . --config $BUILD_TYPE --prefix bin
95+
run: cmake --install . --config $BUILD_TYPE --prefix bin --component cl
9896

9997
# Upload bin directory as artifact
10098
- name: Upload Binary Artifact
@@ -113,7 +111,7 @@ jobs:
113111
cp ../inkcpp_runtime_driver drivers/
114112
chmod +x drivers/inkcpp_runtime_driver
115113
mkdir deps/inkcpp
116-
cp ../../build/bin/bin/* deps/inkcpp/
114+
cp ../../build/bin/* deps/inkcpp/
117115
chmod +x deps/inkcpp/inkcpp_cl
118116
119117
# Run it

CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,53 @@ enable_testing()
77
project(inkcpp VERSION 0.1)
88
SET(CMAKE_CXX_STANDARD 17)
99
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
10+
SET(CMAKE_INSTALL_LIBRARY_DIR lib)
11+
SET(CMAKE_INSTALL_INCLUDE_DIR include)
1012
# Add subdirectories
1113
add_subdirectory(shared)
1214
add_subdirectory(inkcpp)
1315
add_subdirectory(inkcpp_compiler)
1416
add_subdirectory(inkcpp_cl)
1517
add_subdirectory(inkcpp_test)
1618
add_subdirectory(unreal)
19+
20+
21+
get_target_property(TEE inkcpp PUBLIC_HEADER)
22+
install(TARGETS inkcpp inkcpp_compiler inkcpp_shared
23+
EXPORT inkcppTarget
24+
ARCHIVE DESTINATION "lib/ink"
25+
COMPONENT lib EXCLUDE_FROM_ALL
26+
PUBLIC_HEADER DESTINATION "include/ink"
27+
COMPONENT lib EXCLUDE_FROM_ALL
28+
)
29+
30+
install(EXPORT inkcppTarget
31+
FILE inkcppTargets.cmake DESTINATION "lib/cmake/inkcpp"
32+
COMPONENT lib EXCLUDE_FROM_ALL)
33+
34+
include(CMakePackageConfigHelpers)
35+
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
36+
"${CMAKE_CURRENT_BINARY_DIR}/inkcppConfig.cmake"
37+
INSTALL_DESTINATION "lib/cmake/inkcpp"
38+
NO_SET_AND_CHECK_MACRO
39+
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
40+
write_basic_package_version_file(
41+
"${CMAKE_CURRENT_BINARY_DIR}/inkcppConfigVersion.cmake"
42+
VERSION "${inkcpp_VERSION_MAJOR}.${inkcpp_VERSION_MINOR}"
43+
COMPATIBILITY AnyNewerVersion)
44+
install(FILES
45+
${CMAKE_CURRENT_BINARY_DIR}/inkcppConfig.cmake
46+
${CMAKE_CURRENT_BINARY_DIR}/inkcppConfigVersion.cmake
47+
DESTINATION lib/cmake/inkcpp COMPONENT lib EXCLUDE_FROM_ALL)
48+
export(EXPORT inkcppTarget
49+
FILE "${CMAKE_CURRENT_BINARY_DIR}/inkcppTargets.cmake")
50+
51+
# include(InstallRequiredSystemLibraries)
52+
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
53+
set(CPACK_PACKAGE_VERSION_MAJOR "${inkcpp_VERSION_MAJOR}")
54+
set(CPACK_PACKAGE_VERSION_MINOR "${inkcpp_VERSION_MINOR}")
55+
set(CPACK_SOURCE_GENERATOR "ZIP")
56+
set(CPACK_GENERATOR "ZIP")
57+
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
58+
set(CPACK_COMPONENTS_GROUPING IGNORE)
59+
include(CPack)

Config.cmake.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@PACKAGE_INIT@
2+
include ( "${CMAKE_CURRENT_LIST_DIR}/inkcppTargets.cmake" )

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ CMake will then generate the necessary build files for your environment. By defa
8181
8282
To build, either run the generated buildfiles OR you can use `cmake --build . --config <Release|Debug>` from the build folder to automatically execute the relevant toolchain.
8383
84+
For a more in depth installation description please checkout the (wiki)[https://github.com/brwarner/inkcpp/wiki/building].
85+
8486
## Including in C++ Code
8587
8688
Required software: (CMake)[https://cmake.org/]
@@ -89,15 +91,15 @@ Instructions:
8991
9092
1. Clone the repository
9193
2. Configure and build the project with CMake, as described above
92-
3. From your newly-created `build` directory, run `cmake --install . --prefix Path/To/Desired/Library/Directory`. Note that this will currently fail if the project was built for Debug instead of Release.
94+
3. From your newly-created `build` directory, run `cmake --install . --prefix Path/To/Desired/Library/Directory --component <lib/cl/unreal>`.
9395
4. Generated in your chosen directory, you will find a collection of folders. The following must be linked into your build solution for your C++ to compile correctly:
94-
- `include/public`: contains important shared headers.
95-
+ For a Visual Studio project, link this directory as an Include Directory in VC++ Directories.
96-
- `inkcpp/Source/inkcpp/Public`: contains the primary headers for using InkCPP in your code.
96+
- `include/ink`: contains important shared headers.
9797
+ For a Visual Studio project, link this directory as an Include Directory in VC++ Directories.
9898
- `lib/inkcpp.lib` and `lib/inkcpp_compiler.lib`: contains the library code for the InkCPP runner and compiler, respectively.
9999
+ For a Visual Studio project, link these files as Additional Dependencies in Linker->Input.
100100
+ You don't need to link the compiler if you're not using it within your program.
101+
- if you used the `cl` component you will find the `inkcpp_cl` executable in this location
102+
- for `unreal` you will find a `Source` directory containing the Unreal needed libs and headers. **Note:** not working for the current unreal version, we are working to fix this.
101103
5. Reference the headers in your code like so:
102104
103105
```cpp
@@ -106,6 +108,7 @@ Instructions:
106108
#include <ink/runner.h>
107109
#include <ink/choice.h>
108110
```
111+
6. if you use cmake checkout the (wiki)[https://github.com/brwarner/inkcpp/wiki/building#cmake-example] for including the library via cmake
109112

110113

111114
### Troubleshooting

inkcpp/CMakeLists.txt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,19 @@ list(APPEND SOURCES
2626
)
2727
source_group(Collections REGULAR_EXPRESSION collections/.*)
2828
add_library(inkcpp ${SOURCES})
29+
target_include_directories(inkcpp PUBLIC
30+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
31+
$<INSTALL_INTERFACE:include>
32+
)
33+
FILE(GLOB PUBLIC_HEADERS "include/*")
34+
set_target_properties(inkcpp PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}")
2935

3036
# Make sure the include directory is included
31-
target_include_directories(inkcpp
32-
PUBLIC include
33-
PUBLIC ../shared/public
34-
PRIVATE ../shared/private
35-
)
36-
37+
target_link_libraries(inkcpp PRIVATE inkcpp_shared)
3738
# Make sure this project and all dependencies use the C++17 standard
3839
target_compile_features(inkcpp PUBLIC cxx_std_17)
3940

40-
# Default installation
41-
install(TARGETS inkcpp DESTINATION lib)
4241

4342
# Unreal installation
44-
install(DIRECTORY "include/" DESTINATION "inkcpp/Source/inkcpp/Public/ink/" COMPONENT unreal)
45-
install(FILES ${SOURCES} DESTINATION "inkcpp/Source/inkcpp/Private/ink/" COMPONENT unreal)
43+
install(DIRECTORY "include/" DESTINATION "inkcpp/Source/inkcpp/Public/ink/" COMPONENT unreal EXCLUDE_FROM_ALL)
44+
install(FILES ${SOURCES} DESTINATION "inkcpp/Source/inkcpp/Private/ink/" COMPONENT unreal EXCLUDE_FROM_ALL)

inkcpp/functional.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ namespace ink::runtime::internal
1818
return val.get<value_type::int32>();
1919
}
2020

21+
template<>
22+
const char* function_base::pop<const char*>(basic_eval_stack* stack)
23+
{
24+
value val = stack->pop();
25+
inkAssert(val.type() == value_type::string, "Type missmatch!");
26+
return val.get<value_type::string>().str;
27+
}
28+
2129
template<>
2230
void function_base::push<int32_t>(basic_eval_stack* stack, const int32_t& v)
2331
{

inkcpp_cl/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
add_executable(inkcpp_cl inkcpp_cl.cpp test.h test.cpp)
33

44
# Include compiler and runtime libraries
5-
target_link_libraries(inkcpp_cl PUBLIC inkcpp inkcpp_compiler)
5+
target_link_libraries(inkcpp_cl PUBLIC inkcpp inkcpp_compiler inkcpp_shared)
66

77
# For https://en.cppreference.com/w/cpp/filesystem#Notes
88
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
@@ -16,4 +16,4 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
1616
endif()
1717

1818
# Install
19-
install(TARGETS inkcpp_cl DESTINATION bin)
19+
install(TARGETS inkcpp_cl DESTINATION . COMPONENT cl EXCLUDE_FROM_ALL)

inkcpp_compiler/CMakeLists.txt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
list(APPEND SOURCES
1+
list(APPEND SOURCES
22
compiler.cpp binary_stream.h binary_stream.cpp json.hpp
33
json_compiler.h json_compiler.cpp
44
emitter.h emitter.cpp
@@ -11,19 +11,18 @@ list(APPEND SOURCES
1111
add_definitions(-DINK_COMPILER -DINK_EXPOSE_JSON)
1212
add_library(inkcpp_compiler ${SOURCES})
1313

14-
# Make sure the include directory is included
15-
target_include_directories(inkcpp_compiler
16-
PUBLIC include
17-
PUBLIC ../shared/public
18-
PRIVATE ../shared/private
19-
)
14+
target_include_directories(inkcpp_compiler PUBLIC
15+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
16+
$<INSTALL_INTERFACE:include>
17+
)
18+
FILE(GLOB PUBLIC_HEADERS "include/*")
19+
set_target_properties(inkcpp_compiler PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}")
20+
21+
target_link_libraries(inkcpp_compiler PRIVATE inkcpp_shared)
2022

2123
# Make sure this project and all dependencies use the C++17 standard
2224
target_compile_features(inkcpp_compiler PUBLIC cxx_std_17)
2325

24-
# Default installation
25-
install(TARGETS inkcpp_compiler DESTINATION lib)
26-
2726
# Unreal installation
28-
install(DIRECTORY "include/" DESTINATION "inkcpp/Source/inkcpp_editor/Private/ink/" COMPONENT unreal)
29-
install(FILES ${SOURCES} DESTINATION "inkcpp/Source/inkcpp_editor/Private/ink/" COMPONENT unreal)
27+
install(DIRECTORY "include/" DESTINATION "inkcpp/Source/inkcpp_editor/Private/ink/" COMPONENT unreal EXCLUDE_FROM_ALL)
28+
install(FILES ${SOURCES} DESTINATION "inkcpp/Source/inkcpp_editor/Private/ink/" COMPONENT unreal EXCLUDE_FROM_ALL)

inkcpp_test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ add_executable(inkcpp_test catch.hpp Main.cpp
1111
NewLines.cpp
1212
)
1313

14-
target_link_libraries(inkcpp_test PUBLIC inkcpp inkcpp_compiler)
14+
target_link_libraries(inkcpp_test PUBLIC inkcpp inkcpp_compiler inkcpp_shared)
1515
target_include_directories(inkcpp_test PRIVATE ../shared/private/)
1616

1717
# For https://en.cppreference.com/w/cpp/filesystem#Notes

shared/CMakeLists.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
# Install public files into the include directory
2-
install(DIRECTORY public DESTINATION include)
1+
add_library(inkcpp_shared INTERFACE)
2+
3+
target_include_directories(inkcpp_shared
4+
INTERFACE
5+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/public>
6+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/private>
7+
$<INSTALL_INTERFACE:inkcpp>
8+
)
9+
FILE(GLOB PUBLIC_HEADERS "public/*")
10+
set_target_properties(inkcpp_shared PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}")
311

412
# Unreal installation
5-
install(DIRECTORY "public/" DESTINATION "inkcpp/Source/shared/Public/" COMPONENT unreal)
6-
install(DIRECTORY "private/" DESTINATION "inkcpp/Source/shared/Private/" COMPONENT unreal)
13+
install(DIRECTORY "public/" DESTINATION "inkcpp/Source/shared/Public/" COMPONENT unreal EXCLUDE_FROM_ALL)
14+
install(DIRECTORY "private/" DESTINATION "inkcpp/Source/shared/Private/" COMPONENT unreal EXCLUDE_FROM_ALL)

0 commit comments

Comments
 (0)