-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create CMake project * Add cmake test * Misc cleanup
- Loading branch information
1 parent
c476e43
commit 8837bd8
Showing
3 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cmake_minimum_required(VERSION 3.12.4) | ||
|
||
project(byondrs VERSION 0.1.0) | ||
|
||
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) | ||
include(CTest) | ||
endif () | ||
|
||
add_subdirectory(c-ffi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
find_program(CARGO cargo REQUIRED) | ||
|
||
if (CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
set(CARGO_CMD ${CARGO} build) | ||
else () | ||
set(CARGO_CMD ${CARGO} build --release) | ||
endif () | ||
|
||
set(BYONDRS_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/include) | ||
set(BYONDRS_H ${BYONDRS_INCLUDE}/byondrs/byondrs.h) | ||
|
||
add_custom_target( | ||
byondrs_rust ALL | ||
COMMAND ${CMAKE_COMMAND} -E env CARGO_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR} | ||
${CARGO_CMD} | ||
BYPRODUCTS ${BYONDRS_H} | ||
COMMENT "Building byondrs rust library." | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
add_library(byondrs SHARED IMPORTED GLOBAL) | ||
add_dependencies(byondrs byondrs_rust) | ||
|
||
# Hack: target_include_directories() fails at configure time if the directory | ||
# doesn't exist, but the custom target generates it at build time. | ||
file(MAKE_DIRECTORY ${BYONDRS_INCLUDE}) | ||
target_include_directories(byondrs INTERFACE ${BYONDRS_INCLUDE}) | ||
|
||
# Hack: target_sources() fails at configure time if the file doesn't exist, but | ||
# the custom target generates it at build time. | ||
file(MAKE_DIRECTORY ${BYONDRS_INCLUDE}/byondrs) | ||
file(TOUCH ${BYONDRS_H}) | ||
target_sources(byondrs INTERFACE ${BYONDRS_H}) | ||
|
||
# TODO: Verify this works on Windows. | ||
if (CMAKE_SYSTEM_NAME STREQUAL "Windows") | ||
set_property( | ||
TARGET byondrs PROPERTY IMPORTED_LOCATION | ||
${CMAKE_CURRENT_BINARY_DIR}/release/byondrs.dll) | ||
set_property( | ||
TARGET byondrs PROPERTY IMPORTED_IMPLIB | ||
${CMAKE_CURRENT_BINARY_DIR}/release/byondrs.dll.lib) | ||
set_property( | ||
TARGET byondrs PROPERTY IMPORTED_LOCATION_DEBUG | ||
${CMAKE_CURRENT_BINARY_DIR}/debug/byondrs.dll) | ||
set_property( | ||
TARGET byondrs PROPERTY IMPORTED_IMPLIB_DEBUG | ||
${CMAKE_CURRENT_BINARY_DIR}/debug/byondrs.dll.lib) | ||
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") | ||
set_property( | ||
TARGET byondrs | ||
PROPERTY IMPORTED_LOCATION | ||
${CMAKE_CURRENT_BINARY_DIR}/release/libbyondrs.dylib) | ||
set_property( | ||
TARGET byondrs PROPERTY IMPORTED_LOCATION_DEBUG | ||
${CMAKE_CURRENT_BINARY_DIR}/debug/libbyondrs.dylib) | ||
else () | ||
set_property( | ||
TARGET byondrs PROPERTY IMPORTED_LOCATION | ||
${CMAKE_CURRENT_BINARY_DIR}/release/libbyondrs.so) | ||
set_property( | ||
TARGET byondrs PROPERTY IMPORTED_LOCATION_DEBUG | ||
${CMAKE_CURRENT_BINARY_DIR}/debug/libbyondrs.so) | ||
endif () | ||
|
||
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) | ||
add_test( | ||
NAME byondrs_test | ||
COMMAND cargo test | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters