Skip to content

Commit

Permalink
Apply cmake-format across non-third-party projects
Browse files Browse the repository at this point in the history
  • Loading branch information
lefticus committed Dec 10, 2020
1 parent 6378fb9 commit dbc15da
Show file tree
Hide file tree
Showing 46 changed files with 5,529 additions and 4,842 deletions.
2 changes: 1 addition & 1 deletion .cmake-format.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ format:
disable: false
_help_line_width:
- How wide to allow formatted cmake files
line_width: 120
line_width: 150
_help_tab_size:
- How many spaces to tab for indent
tab_size: 2
Expand Down
370 changes: 219 additions & 151 deletions CMakeLists.txt

Large diffs are not rendered by default.

70 changes: 25 additions & 45 deletions cmake/CMakeAddFortranSubdirectory.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,20 @@
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)


set(_MS_MINGW_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
include(CheckLanguage)
include(ExternalProject)
include(CMakeParseArguments)

function(_setup_mingw_config_and_build source_dir build_dir)
# Look for a MinGW gfortran.
find_program(MINGW_GFORTRAN
find_program(
MINGW_GFORTRAN
NAMES gfortran
PATHS
c:/MinGW/bin
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MinGW;InstallLocation]/bin"
)
PATHS c:/MinGW/bin "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MinGW;InstallLocation]/bin")
if(NOT MINGW_GFORTRAN)
message(FATAL_ERROR
"gfortran not found, please install MinGW with the gfortran option."
"Or set the cache variable MINGW_GFORTRAN to the full path. "
" This is required to build")
message(FATAL_ERROR "gfortran not found, please install MinGW with the gfortran option."
"Or set the cache variable MINGW_GFORTRAN to the full path. " " This is required to build")
endif()

# Validate the MinGW gfortran we found.
Expand All @@ -89,33 +84,22 @@ function(_setup_mingw_config_and_build source_dir build_dir)
get_filename_component(MINGW_PATH ${MINGW_GFORTRAN} PATH)
file(TO_NATIVE_PATH "${MINGW_PATH}" MINGW_PATH)
string(REPLACE "\\" "\\\\" MINGW_PATH "${MINGW_PATH}")
configure_file(
${_MS_MINGW_SOURCE_DIR}/CMakeAddFortranSubdirectory/config_mingw.cmake.in
${build_dir}/config_mingw.cmake
@ONLY)
configure_file(
${_MS_MINGW_SOURCE_DIR}/CMakeAddFortranSubdirectory/build_mingw.cmake.in
${build_dir}/build_mingw.cmake
@ONLY)
configure_file(${_MS_MINGW_SOURCE_DIR}/CMakeAddFortranSubdirectory/config_mingw.cmake.in ${build_dir}/config_mingw.cmake @ONLY)
configure_file(${_MS_MINGW_SOURCE_DIR}/CMakeAddFortranSubdirectory/build_mingw.cmake.in ${build_dir}/build_mingw.cmake @ONLY)
endfunction()

function(_add_fortran_library_link_interface library depend_library)
set_target_properties(${library} PROPERTIES
IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG "${depend_library}")
set_target_properties(${library} PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG "${depend_library}")
endfunction()


function(cmake_add_fortran_subdirectory subdir)
# Parse arguments to function
set(options NO_EXTERNAL_INSTALL)
set(oneValueArgs PROJECT ARCHIVE_DIR RUNTIME_DIR)
set(multiValueArgs LIBRARIES LINK_LIBRARIES CMAKE_COMMAND_LINE)
cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT ARGS_NO_EXTERNAL_INSTALL)
message(FATAL_ERROR
"Option NO_EXTERNAL_INSTALL is required (for forward compatibility) "
"but was not given."
)
message(FATAL_ERROR "Option NO_EXTERNAL_INSTALL is required (for forward compatibility) " "but was not given.")
endif()

# if we are not using MSVC without fortran support
Expand All @@ -139,42 +123,38 @@ function(cmake_add_fortran_subdirectory subdir)
set(build_dir "${CMAKE_CURRENT_BINARY_DIR}/${subdir}")
foreach(dir_var library_dir binary_dir)
if(NOT IS_ABSOLUTE "${${dir_var}}")
get_filename_component(${dir_var}
"${CMAKE_CURRENT_BINARY_DIR}/${${dir_var}}" ABSOLUTE)
get_filename_component(${dir_var} "${CMAKE_CURRENT_BINARY_DIR}/${${dir_var}}" ABSOLUTE)
endif()
endforeach()
# create build and configure wrapper scripts
_setup_mingw_config_and_build("${source_dir}" "${build_dir}")
# create the external project
externalproject_add(${project_name}_build
ExternalProject_Add(
${project_name}_build
SOURCE_DIR ${source_dir}
BINARY_DIR ${build_dir}
CONFIGURE_COMMAND ${CMAKE_COMMAND}
-P ${build_dir}/config_mingw.cmake
BUILD_COMMAND ${CMAKE_COMMAND}
-P ${build_dir}/build_mingw.cmake
INSTALL_COMMAND ""
)
CONFIGURE_COMMAND ${CMAKE_COMMAND} -P ${build_dir}/config_mingw.cmake
BUILD_COMMAND ${CMAKE_COMMAND} -P ${build_dir}/build_mingw.cmake
INSTALL_COMMAND "")

set_target_properties(${project_name}_build PROPERTIES FOLDER Auxiliary)

# make the external project always run make with each build
externalproject_add_step(${project_name}_build forcebuild
COMMAND ${CMAKE_COMMAND}
-E remove
${CMAKE_CURRENT_BUILD_DIR}/${project_name}-prefix/src/${project_name}-stamp/${project_name}-build
ExternalProject_Add_Step(
${project_name}_build forcebuild
COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BUILD_DIR}/${project_name}-prefix/src/${project_name}-stamp/${project_name}-build
DEPENDEES configure
DEPENDERS build
ALWAYS 1
)
ALWAYS 1)
# create imported targets for all libraries
foreach(lib ${libraries})
add_library(${lib} SHARED IMPORTED GLOBAL)
set_property(TARGET ${lib} APPEND PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG)
set_target_properties(${lib} PROPERTIES
IMPORTED_IMPLIB_NOCONFIG "${library_dir}/lib${lib}.lib"
IMPORTED_LOCATION_NOCONFIG "${binary_dir}/lib${lib}.dll"
)
set_property(
TARGET ${lib}
APPEND
PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG)
set_target_properties(${lib} PROPERTIES IMPORTED_IMPLIB_NOCONFIG "${library_dir}/lib${lib}.lib" IMPORTED_LOCATION_NOCONFIG
"${binary_dir}/lib${lib}.dll")
add_dependencies(${lib} ${project_name}_build)
endforeach()

Expand Down
Loading

0 comments on commit dbc15da

Please sign in to comment.