-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
57 lines (48 loc) · 1.74 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
cmake_minimum_required(VERSION 3.16)
project(bellshadeFortran LANGUAGES Fortran)
add_compile_options(
-Wall
-Wextra
-Wpedantic
-Waliasing
-Wconversion-extra
-Wimplicit-interface
-Wimplicit-procedure
-Wsurprising
-Werror
)
function(source_fortran DIR SOURCES)
file(GLOB_RECURSE NEW_SOURCES "${DIR}/*.f90")
list(APPEND ${SOURCES} ${NEW_SOURCES})
set(${SOURCES} ${${SOURCES}} PARENT_SCOPE)
endfunction()
set(MODULE_SOURCES)
source_fortran(${CMAKE_SOURCE_DIR}/module MODULE_SOURCES)
add_library(module STATIC ${MODULE_SOURCES})
function(buat_nama_file_unik FILE_NAME OUTPUT_NAME)
file(RELATIVE_PATH REL_PATH "${CMAKE_SOURCE_DIR}" "${FILE_NAME}")
get_filename_component(CUR_EXT "${REL_PATH}" LAST_EXT)
string(REPLACE "/" "_" UNIQUE_NAME "${REL_PATH}")
string(REPLACE "${CUR_EXT}" "" UNIQUE_NAME "${UNIQUE_NAME}")
set(${OUTPUT_NAME} ${UNIQUE_NAME} PARENT_SCOPE)
endfunction()
file(GLOB_RECURSE TEST_FILES "${CMAKE_SOURCE_DIR}/test/*.f90")
foreach(TEST_FILE ${TEST_FILES})
buat_nama_file_unik(${TEST_FILE} TEST_NAME)
add_executable(${TEST_NAME} ${TEST_FILE})
target_link_libraries(${TEST_NAME} module)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
endforeach()
file(GLOB_RECURSE EXAMPLE_FILES "${CMAKE_SOURCE_DIR}/contoh/*.f90")
foreach(EXAMPLE_FILE ${EXAMPLE_FILES})
buat_nama_file_unik(${EXAMPLE_FILE} EXAMPLE_NAME)
add_executable(${EXAMPLE_NAME} ${EXAMPLE_FILE})
target_link_libraries(${EXAMPLE_NAME} module)
list(APPEND EXAMPLE_NAME_LIST run_${EXAMPLE_NAME})
add_custom_target(run_${EXAMPLE_NAME}
COMMAND ${EXAMPLE_NAME}
DEPENDS ${EXAMPLE_NAME}
COMMENT "Jalankan contoh: ${EXAMPLE_NAME}")
endforeach()
enable_testing()
add_custom_target(jalankan_semua_contoh DEPENDS ${EXAMPLE_NAME_LIST})