Skip to content
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

Retain source folder structure for CMake build #1235

Merged
merged 6 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@ function( add_t8_benchmark )
set( multiValueArgs "SOURCES" )
cmake_parse_arguments( ADD_T8_BENCHMARK "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

# Get the path of the first file listed in the SOURCES list and use it to determine the build directory.
# The executable will be build in the same directory as the first source file.
list(GET ADD_T8_BENCHMARK_SOURCES 0 FIRST_SOURCE)
get_filename_component(BENCHMARK_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/${FIRST_SOURCE}" DIRECTORY)
file(RELATIVE_PATH BENCHMARK_RELATIVE_DIR "${CMAKE_SOURCE_DIR}" "${BENCHMARK_SOURCE_DIR}")
set(BENCHMARK_BUILD_DIR "${CMAKE_BINARY_DIR}/${BENCHMARK_RELATIVE_DIR}")

add_executable( ${ADD_T8_BENCHMARK_NAME} ${ADD_T8_BENCHMARK_SOURCES} )
target_include_directories( ${ADD_T8_BENCHMARK_NAME} PRIVATE ${PROJECT_SOURCE_DIR} )
target_link_libraries( ${ADD_T8_BENCHMARK_NAME} PRIVATE T8 SC::SC )

set_target_properties(${ADD_T8_BENCHMARK_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${BENCHMARK_BUILD_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${BENCHMARK_BUILD_DIR}"
ARCHIVE_OUTPUT_DIRECTORY "${BENCHMARK_BUILD_DIR}"
)

if( T8CODE_EXPORT_COMPILE_COMMANDS )
set_target_properties( ${ADD_T8_BENCHMARK_NAME} PROPERTIES EXPORT_COMPILE_COMMANDS ON )
endif( T8CODE_EXPORT_COMPILE_COMMANDS )
Expand Down
17 changes: 15 additions & 2 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ else()
add_library( t8example STATIC )
endif()
target_sources( t8example PRIVATE common/t8_example_common.cxx common/t8_example_common_functions.cxx )
target_include_directories( t8example PRIVATE ${CMAKE_CURRENT_LIST_DIR}/.. )
target_link_libraries( t8example PRIVATE T8 )
target_include_directories( t8example PRIVATE ${CMAKE_CURRENT_LIST_DIR}/.. ${SC_INCLUDE_DIR} )
target_link_libraries( t8example PRIVATE T8 ${SC_LIBRARIES} m )
install( TARGETS t8example DESTINATION ${CMAKE_INSTALL_PREFIX}/lib )

function( add_t8_example )
Expand All @@ -15,10 +15,23 @@ function( add_t8_example )
set( multiValueArgs "SOURCES" )
cmake_parse_arguments( ADD_T8_EXAMPLE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

# Get the path of the first file listed in the SOURCES list and use it to determine the build directory.
# The executable will be build in the same directory as the first source file.
list(GET ADD_T8_EXAMPLE_SOURCES 0 FIRST_SOURCE)
get_filename_component(EXAMPLE_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/${FIRST_SOURCE}" DIRECTORY)
file(RELATIVE_PATH EXAMPLE_RELATIVE_DIR "${CMAKE_SOURCE_DIR}" "${EXAMPLE_SOURCE_DIR}")
set(EXAMPLE_BUILD_DIR "${CMAKE_BINARY_DIR}/${EXAMPLE_RELATIVE_DIR}")

add_executable( ${ADD_T8_EXAMPLE_NAME} ${ADD_T8_EXAMPLE_SOURCES} )
target_link_libraries( ${ADD_T8_EXAMPLE_NAME} PRIVATE T8 t8example SC::SC )
target_include_directories( ${ADD_T8_EXAMPLE_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/.. )

set_target_properties(${ADD_T8_EXAMPLE_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${EXAMPLE_BUILD_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${EXAMPLE_BUILD_DIR}"
ARCHIVE_OUTPUT_DIRECTORY "${EXAMPLE_BUILD_DIR}"
)

if( T8CODE_EXPORT_COMPILE_COMMANDS )
set_target_properties( ${ADD_T8_EXAMPLE_NAME} PROPERTIES EXPORT_COMPILE_COMMANDS ON )
endif( T8CODE_EXPORT_COMPILE_COMMANDS )
Expand Down
20 changes: 19 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,27 @@ function( add_t8_test )
set( multiValueArgs "SOURCES" )
cmake_parse_arguments( ADD_T8_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

# Get the path of the second file listed in the SOURCES list (if there is one then from the first) and use it to determine the build directory.
# We use the second file, because the first is t8_gtest_main, which is in the root test dir. The executable will be build in the same directory as the second source file.
list (LENGTH ADD_T8_TEST_SOURCES TEST_SOURCES_LENGTH)
if ( TEST_SOURCES_LENGTH GREATER 1 )
list(GET ADD_T8_TEST_SOURCES 1 TEST_SOURCE)
else()
list(GET ADD_T8_TEST_SOURCES 0 TEST_SOURCE)
endif()
get_filename_component(TEST_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/${TEST_SOURCE}" DIRECTORY)
file(RELATIVE_PATH TEST_RELATIVE_DIR "${CMAKE_SOURCE_DIR}" "${TEST_SOURCE_DIR}")
set(TEST_BUILD_DIR "${CMAKE_BINARY_DIR}/${TEST_RELATIVE_DIR}")

add_executable( ${ADD_T8_TEST_NAME} ${ADD_T8_TEST_SOURCES} )
target_link_libraries( ${ADD_T8_TEST_NAME} PRIVATE T8 gtest pthread)

set_target_properties(${ADD_T8_TEST_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${TEST_BUILD_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${TEST_BUILD_DIR}"
ARCHIVE_OUTPUT_DIRECTORY "${TEST_BUILD_DIR}"
)

if( T8CODE_EXPORT_COMPILE_COMMANDS )
set_target_properties( ${ADD_T8_TEST_NAME} PROPERTIES EXPORT_COMPILE_COMMANDS ON )
endif( T8CODE_EXPORT_COMPILE_COMMANDS )
Expand All @@ -29,7 +47,7 @@ function( add_t8_test )
separate_arguments (T8CODE_TEST_COMMAND_LIST NATIVE_COMMAND ${T8CODE_CUSTOM_SERIAL_TEST_COMMAND})
endif ( T8CODE_ENABLE_MPI )

add_test( NAME ${ADD_T8_TEST_NAME} COMMAND ${T8CODE_TEST_COMMAND_LIST} ./${ADD_T8_TEST_NAME} )
add_test( NAME ${ADD_T8_TEST_NAME} COMMAND ${T8CODE_TEST_COMMAND_LIST} ${TEST_BUILD_DIR}/${ADD_T8_TEST_NAME} )
endfunction()

# Copy test files to build folder so that the t8_test programs can find them.
Expand Down
13 changes: 13 additions & 0 deletions tutorials/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,22 @@ function( add_t8_tutorial )
set( multiValueArgs "SOURCES" )
cmake_parse_arguments( ADD_T8_TUTORIAL "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

# Get the path of the first file listed in the SOURCES list and use it to determine the build directory.
# The executable will be build in the same directory as the first source file.
list(GET ADD_T8_TUTORIAL_SOURCES 0 FIRST_SOURCE)
get_filename_component(TUTORIAL_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/${FIRST_SOURCE}" DIRECTORY)
file(RELATIVE_PATH TUTORIAL_RELATIVE_DIR "${CMAKE_SOURCE_DIR}" "${TUTORIAL_SOURCE_DIR}")
set(TUTORIAL_BUILD_DIR "${CMAKE_BINARY_DIR}/${TUTORIAL_RELATIVE_DIR}")

add_executable( ${ADD_T8_TUTORIAL_NAME} ${ADD_T8_TUTORIAL_SOURCES} )
target_link_libraries( ${ADD_T8_TUTORIAL_NAME} PRIVATE T8 SC::SC )
target_include_directories( ${ADD_T8_TUTORIAL_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/.. )

set_target_properties(${ADD_T8_TUTORIAL_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${TUTORIAL_BUILD_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${TUTORIAL_BUILD_DIR}"
ARCHIVE_OUTPUT_DIRECTORY "${TUTORIAL_BUILD_DIR}"
)

if( T8CODE_EXPORT_COMPILE_COMMANDS )
set_target_properties( ${ADD_T8_TUTORIAL_NAME} PROPERTIES EXPORT_COMPILE_COMMANDS ON )
Expand Down