68 lines
1.9 KiB
CMake
68 lines
1.9 KiB
CMake
cmake_minimum_required(VERSION 3.20.0)
|
|
project(StormEngine VERSION 0.1.0 LANGUAGES C)
|
|
|
|
# Find sources
|
|
file(GLOB_RECURSE SOURCES src/main/c/src/**.c)
|
|
|
|
# include header files
|
|
include_directories(src/main/c/includes)
|
|
|
|
# include jni
|
|
set(JAVA_AWT_LIBRARY NotNeeded)
|
|
if(EXISTS "/tmp/jni/jdk/include")
|
|
include_directories(/tmp/jni/jdk/include)
|
|
include_directories(/tmp/jni/jdk/include/linux)
|
|
else()
|
|
find_package(JNI REQUIRED)
|
|
include_directories(${JNI_INCLUDE_DIRS})
|
|
endif()
|
|
|
|
# Create shared library
|
|
add_library(StormEngine SHARED ${SOURCES})
|
|
|
|
# set props for the lib
|
|
target_compile_options(StormEngine PRIVATE -m64 -mavx -mavx2)
|
|
|
|
# set shared library output dir
|
|
set_target_properties(StormEngine PROPERTIES
|
|
CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/shared-folder
|
|
)
|
|
|
|
# include and enable testing
|
|
include(CTest)
|
|
enable_testing()
|
|
|
|
# Grab test files
|
|
file(GLOB_RECURSE TEST_FILES ${CMAKE_SOURCE_DIR}/test/c/**.c)
|
|
set(TEST_DRIVER test_driver.c)
|
|
|
|
# preprocess the test files to use relative paths
|
|
set(TEST_SOURCES "")
|
|
foreach(TEST_FILE ${TEST_FILES})
|
|
file(RELATIVE_PATH REL_TEST_FILE ${CMAKE_SOURCE_DIR} ${TEST_FILE})
|
|
# get_filename_component (TEST_NAME ${TEST_FILE} NAME)
|
|
list(APPEND TEST_SOURCES ${REL_TEST_FILE})
|
|
endforeach()
|
|
|
|
# Add test sources
|
|
create_test_sourcelist(TEST_SOURCE_LIST ${TEST_DRIVER} ${TEST_SOURCES})
|
|
|
|
# Create test executable
|
|
add_executable(test_runner ${TEST_SOURCE_LIST})
|
|
|
|
# emit test driver to outdir
|
|
set_target_properties(test_runner PROPERTIES
|
|
CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/build
|
|
)
|
|
|
|
# link the library to the test executable
|
|
target_link_libraries(test_runner StormEngine)
|
|
|
|
# add tests for each test source file
|
|
foreach (TEST_FILE ${TEST_SOURCES})
|
|
get_filename_component (TEST_NAME ${TEST_FILE} NAME_WE)
|
|
get_filename_component (TEST_PATH ${TEST_FILE} DIRECTORY)
|
|
add_test(NAME ${TEST_NAME} COMMAND test_runner ${TEST_PATH}/${TEST_NAME})
|
|
endforeach ()
|
|
|