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

CMake: refactor a few items #47

Merged
merged 1 commit into from
Oct 9, 2023
Merged
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
47 changes: 27 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,44 +1,51 @@
cmake_minimum_required(VERSION 3.0)

project(bmif Fortran)
set(bmi_major_version 2)
set(bmi_minor_version 0)
# Use system-specific install directories
include(GNUInstallDirs)

project(bmif
VERSION 2.0
LANGUAGES Fortran
)

# Match the module name set in "bmi.f90".
set(mod_name ${CMAKE_PROJECT_NAME}_${bmi_major_version}_${bmi_minor_version})
set(mod_name "${CMAKE_PROJECT_NAME}_\
${CMAKE_PROJECT_VERSION_MAJOR}_${CMAKE_PROJECT_VERSION_MINOR}")

# Create static and shared libraries.
add_library(${CMAKE_PROJECT_NAME}_static bmi.f90)
add_library(${CMAKE_PROJECT_NAME}_shared SHARED bmi.f90)
set(static_lib ${CMAKE_PROJECT_NAME}_static)
set(shared_lib ${CMAKE_PROJECT_NAME}_shared)
add_library(${static_lib} bmi.f90)
add_library(${shared_lib} SHARED bmi.f90)

# Change the output names of the libraries. On Windows, they can't
# have the same name, so change the shared library name.
set_target_properties(${CMAKE_PROJECT_NAME}_static PROPERTIES
set_target_properties(${static_lib} PROPERTIES
OUTPUT_NAME ${CMAKE_PROJECT_NAME})
if(WIN32)
set_target_properties(${CMAKE_PROJECT_NAME}_shared PROPERTIES
set_target_properties(${shared_lib} PROPERTIES
OUTPUT_NAME ${CMAKE_PROJECT_NAME}_win)
else()
set_target_properties(${CMAKE_PROJECT_NAME}_shared PROPERTIES
set_target_properties(${shared_lib} PROPERTIES
OUTPUT_NAME ${CMAKE_PROJECT_NAME})
endif()

set_target_properties(${CMAKE_PROJECT_NAME}_static PROPERTIES
VERSION ${bmi_major_version}.${bmi_minor_version}
set_target_properties(${static_lib} PROPERTIES
VERSION ${CMAKE_PROJECT_VERSION}
)
set_target_properties(${CMAKE_PROJECT_NAME}_shared PROPERTIES
VERSION ${bmi_major_version}.${bmi_minor_version}
set_target_properties(${shared_lib} PROPERTIES
VERSION ${CMAKE_PROJECT_VERSION}
PUBLIC_HEADER ${CMAKE_BINARY_DIR}/${mod_name}.mod
)

install(
TARGETS ${CMAKE_PROJECT_NAME}_static
ARCHIVE DESTINATION lib
TARGETS ${static_lib}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(
TARGETS ${CMAKE_PROJECT_NAME}_shared
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
PUBLIC_HEADER DESTINATION include
TARGETS ${shared_lib}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)