@@ -11,6 +11,8 @@ project(bspline-fortran NONE)
1111
1212# Define build options
1313option (BSPLINE_BUILD_TESTING "Build the test programs" ON )
14+ option (BSPLINE_BUILD_SHARED_LIBS "Build shared libraries" ON )
15+ option (BSPLINE_BUILD_STATIC_LIBS "Build static libraries" ON )
1416
1517# Real and Integer kinds
1618SET (BSPLINE_REAL_KIND "REAL64" CACHE STRING "Real kind parameter" )
@@ -73,32 +75,43 @@ else()
7375 "${ABS_LIB_INSTALL_DIR} " )
7476endif ()
7577
76- add_library ( ${LIB_NAME} SHARED ${SOURCES} )
77- add_library ( ${LIB_NAME} -static STATIC ${SOURCES} )
78-
79- set_target_properties (${LIB_NAME} -static
80- PROPERTIES
81- OUTPUT_NAME "${LIB_NAME} "
82- if (NOT MSVC_IDE )
83- PREFIX lib
84- endif ()
85- ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib
86- Fortran_MODULE_DIRECTORY ${MODULE_DIR} )
87-
88- set_target_properties (${LIB_NAME}
89- PROPERTIES
90- OUTPUT_NAME "${LIB_NAME} "
91- if (NOT MSVC_IDE )
92- PREFIX lib
93- endif ()
94- LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib
95- Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR} )
96-
97- # install library:
98- install ( TARGETS ${LIB_NAME} ${LIB_NAME} -static
99- LIBRARY DESTINATION "${INSTALL_LIB_DIR} "
100- ARCHIVE DESTINATION "${INSTALL_LIB_DIR} " )
101- install ( DIRECTORY "${MODULE_DIR} /" DESTINATION "${INSTALL_MOD_DIR} " )
78+ if (BSPLINE_BUILD_SHARED_LIBS)
79+ add_library ( ${LIB_NAME} SHARED ${SOURCES} )
80+
81+ set_target_properties (${LIB_NAME}
82+ PROPERTIES
83+ OUTPUT_NAME "${LIB_NAME} "
84+ if (NOT MSVC_IDE )
85+ PREFIX lib
86+ endif ()
87+ LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib
88+ Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR} )
89+
90+ # install library:
91+ install ( TARGETS ${LIB_NAME}
92+ LIBRARY DESTINATION "${INSTALL_LIB_DIR} "
93+ ARCHIVE DESTINATION "${INSTALL_LIB_DIR} " )
94+ install ( DIRECTORY "${MODULE_DIR} /" DESTINATION "${INSTALL_MOD_DIR} " )
95+ endif ()
96+
97+ if (BSPLINE_BUILD_STATIC_LIBS)
98+ add_library ( ${LIB_NAME} -static STATIC ${SOURCES} )
99+
100+ set_target_properties (${LIB_NAME} -static
101+ PROPERTIES
102+ OUTPUT_NAME "${LIB_NAME} "
103+ if (NOT MSVC_IDE )
104+ PREFIX lib
105+ endif ()
106+ ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib
107+ Fortran_MODULE_DIRECTORY ${MODULE_DIR} )
108+
109+ # install library:
110+ install ( TARGETS ${LIB_NAME} -static
111+ LIBRARY DESTINATION "${INSTALL_LIB_DIR} "
112+ ARCHIVE DESTINATION "${INSTALL_LIB_DIR} " )
113+ install ( DIRECTORY "${MODULE_DIR} /" DESTINATION "${INSTALL_MOD_DIR} " )
114+ endif ()
102115
103116# Windows settings:
104117if (MSVC_IDE )
@@ -123,7 +136,14 @@ if(BSPLINE_BUILD_TESTING)
123136 test_oo
124137 test_regrid)
125138 add_executable (${prog_name} test /${prog_name} .f90)
126- target_link_libraries (${prog_name} ${LIB_NAME} -static )
139+ if (BSPLINE_BUILD_STATIC_LIBS)
140+ target_link_libraries (${prog_name} ${LIB_NAME} -static )
141+ target_include_directories (${prog_name} PRIVATE ${MODULE_DIR} )
142+ elseif (BSPLINE_BUILD_SHARED_LIBS)
143+ target_link_libraries (${prog_name} ${LIB_NAME} )
144+ else ()
145+ message (FATAL_ERROR "No libraries to link the test programs to. Either shared or static libraries must be built." )
146+ endif ()
127147 add_test (NAME ${prog_name}
128148 COMMAND ${prog_name} )
129149 endforeach ()
0 commit comments