Skip to content

Commit

Permalink
Clean up CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
jchristopherson committed Sep 13, 2023
1 parent 98a1e49 commit c437e46
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
11 changes: 9 additions & 2 deletions cmake/helper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function(install_library lib_name lib_install_dir bin_install_dir mod_dir instal
RUNTIME DESTINATION ${bin_install_dir}
LIBRARY DESTINATION ${lib_install_dir}
ARCHIVE DESTINATION ${lib_install_dir}
INCLUDES DESTINATION ${install_dir}/include
)
install(
DIRECTORY ${mod_dir}
Expand All @@ -56,13 +57,19 @@ function(install_documentation doc_dir install_dir)
)
endfunction()

# Links the supplied library
function(link_library targ lib include_dir)
target_link_libraries(${targ} ${lib})
target_include_directories(${targ} PUBLIC $<BUILD_INTERFACE:${include_dir}>)
endfunction()

# ------------------------------------------------------------------------------
# Helpful Macros
macro(print_all_variables)
message(STATUS "---------- CURRENTLY DEFIND VARIABLES -----------")
message(STATUS "---------- CURRENTLY DEFINED VARIABLES -----------")
get_cmake_property(varNames VARIABLES)
foreach(varName ${varNames})
message(STATUS ${varName} = ${${varName}})
endforeach()
message(STATUS "---------- END ----------")
endmacro()
endmacro()
File renamed without changes.
46 changes: 19 additions & 27 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
macro(create_test testname codename)
add_executable(${testname} ${codename})
target_link_libraries(${testname} ferror)
target_include_directories(${testname} PUBLIC ${PROJECT_BINARY_DIR}/include)
add_test(
NAME ${testname}
WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
COMMAND $<TARGET_FILE:${testname}>
)
endmacro()

macro(create_c_test testname codename)
add_executable(${testname} ${codename})
target_link_libraries(${testname} ferror)
add_test(
NAME ${testname}
WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
COMMAND $<TARGET_FILE:${testname}>
)
endmacro()
include("${PROJECT_SOURCE_DIR}/cmake/helper.cmake")

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
add_executable(ferror_test ferror_test.f90)
link_library(ferror_test ${PROJECT_NAME} ${PROJECT_INCLUDE_DIR})
add_test(
NAME ferror_test
WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
COMMAND $<TARGET_FILE:ferror_test>
)

create_test(ferror_test ferror_test.f90)

if (${BUILD_C_API})
create_test(ferror_test_c ferror_test_c.c)
endif()
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
)
add_executable(ferror_test_c C/ferror_test_c.c)
link_library(ferror_test_c ${PROJECT_NAME} ${PROJECT_INCLUDE_DIR})
add_test(
NAME ferror_test_c
WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
COMMAND $<TARGET_FILE:ferror_test_c>
)
endif()

0 comments on commit c437e46

Please sign in to comment.