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

Run a CI job linting/parsing the CMake files in cmake/* #222

Draft
wants to merge 14 commits into
base: ign-cmake2
Choose a base branch
from
30 changes: 30 additions & 0 deletions .github/workflows/cmakelint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CMake Linter

on: [push, pull_request]

jobs:
run_cmakelint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install cmakelint
run: |
python -m pip install --upgrade pip
# cmake-lint does not find real problems with CMAke syntax
python -m pip install cmakelang

- name: run cmake-lint
working-directory: ${{github.workspace}}
run: |
cmake-lint --version
for f in cmake/*.cmake; do
echo "Processing ${f}"
cmake-lint -c tools/cmakelang-config.py -- $f
done
2 changes: 1 addition & 1 deletion cmake/FindAVFORMAT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
AVFORMAT
REQUIRED_VARS AVFORMAT_FOUND)
REQUIRED_VARS AVFORMAT_FOUND)
9 changes: 8 additions & 1 deletion cmake/FindFreeImage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ if (NOT WIN32)
set(FreeImage_test_output "")
set(FreeImage_compile_output "")
file(WRITE ${testFreeImageSource}
"#include <FreeImage.h>\nint main () { if (FREEIMAGE_MAJOR_VERSION >= ${major_version} && FREEIMAGE_MINOR_VERSION >= ${minor_version}) return 1; else return 0;} \n")
"#include <FreeImage.h>
int main () {
if (FREEIMAGE_MAJOR_VERSION >= ${major_version} &&
FREEIMAGE_MINOR_VERSION >= ${minor_version})
return 1;
else
return 0;
}")

try_run(FREEIMAGE_RUNS
FREEIMAGE_COMPILES
Expand Down
2 changes: 1 addition & 1 deletion cmake/FindIgnCURL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if(${IgnCURL_FOUND})
set_target_properties(curl::curl PROPERTIES
INTERFACE_LINK_LIBRARIES CURL::libcurl)
endif()

include(IgnImportTarget)

if(NOT TARGET curl::curl)
Expand Down
27 changes: 15 additions & 12 deletions cmake/FindIgnOGRE.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ set(minor_version ${IgnOGRE_FIND_VERSION_MINOR})
set(full_version ${major_version}.${minor_version})

# Copied from OGREConfig.cmake
macro(ign_ogre_declare_plugin TYPE COMPONENT)
set(OGRE_${TYPE}_${COMPONENT}_FOUND TRUE)
set(OGRE_${TYPE}_${COMPONENT}_LIBRARIES ${TYPE}_${COMPONENT})
list(APPEND OGRE_LIBRARIES ${TYPE}_${COMPONENT})
macro(ign_ogre_declare_plugin type component)
set(OGRE_${type}_${component}_FOUND TRUE)
set(OGRE_${type}_${component}_LIBRARIES ${type}_${component})
list(APPEND OGRE_LIBRARIES ${type}_${component})
endmacro()

if (NOT WIN32)
Expand Down Expand Up @@ -102,7 +102,9 @@ if (NOT WIN32)
if (NOT OGRE_LIBRARY_DIRS)
pkg_get_variable(OGRE_LIBRARY_DIRS OGRE libdir)
if(NOT OGRE_LIBRARY_DIRS)
IGN_BUILD_WARNING ("Failed to find OGRE's library directory. The build will succeed, but there will likely be run-time errors.")
IGN_BUILD_WARNING ("\
Failed to find OGRE's library directory. \
The build will succeed, but there will likely be run-time errors.")
else()
# strip line break
string(REGEX REPLACE "\n$" "" OGRE_LIBRARY_DIRS "${OGRE_LIBRARY_DIRS}")
Expand All @@ -111,8 +113,8 @@ if (NOT WIN32)
# in some cases the value of OGRE_LIBRARIES is "OgreMain;pthread"
# Convert this to full path to library
if (substr_found EQUAL -1)
foreach(OGRE_LIBRARY_NAME ${OGRE_LIBRARIES})
find_library(OGRE_LIBRARY NAMES ${OGRE_LIBRARY_NAME}
foreach(ogre_library_name ${OGRE_LIBRARIES})
find_library(OGRE_LIBRARY NAMES ${ogre_library_name}
HINTS ${OGRE_LIBRARY_DIRS} NO_DEFAULT_PATH)
list (APPEND TMP_OGRE_LIBRARIES "${OGRE_LIBRARY}")
endforeach()
Expand Down Expand Up @@ -146,7 +148,8 @@ if (NOT WIN32)

pkg_get_variable(OGRE_PLUGINDIR OGRE plugindir)
if(NOT OGRE_PLUGINDIR)
IGN_BUILD_WARNING ("Failed to find OGRE's plugin directory. The build will succeed, but there will likely be run-time errors.")
IGN_BUILD_WARNING ("Failed to find OGRE's plugin directory. \
The build will succeed, but there will likely be run-time errors.")
else()
# Seems that OGRE_PLUGINDIR can end in a newline, which will cause problems
# when we pass it to the compiler later.
Expand Down Expand Up @@ -201,11 +204,11 @@ else()
string(REGEX REPLACE "\\$.*>" "" ogre_lib ${ogre_lib})
# Be sure that all Ogre* libraries are using absolute paths
set(prefix "")
# vcpkg uses special directory (lib/manual-link/) to place libraries
# with main sysmbol like OgreMain.
if(ogre_lib MATCHES "OgreMain" AND NOT IS_ABSOLUTE "${ogre_lib}" AND EXISTS "${OGRE_LIBRARY_DIRS}/manual-link/")
# vcpkg uses special directory (lib/manual-link/) to place libraries
# with main sysmbol like OgreMain.
if(ogre_lib MATCHES "OgreMain" AND NOT IS_ABSOLUTE "${ogre_lib}" AND EXISTS "${OGRE_LIBRARY_DIRS}/manual-link/")
set(prefix "${OGRE_LIBRARY_DIRS}/manual-link/")
elseif(ogre_lib MATCHES "Ogre" AND NOT IS_ABSOLUTE "${ogre_lib}")
elseif(ogre_lib MATCHES "Ogre" AND NOT IS_ABSOLUTE "${ogre_lib}")
set(prefix "${OGRE_LIBRARY_DIRS}/")
endif()
if(ogre_lib MATCHES "Plugin_" OR ogre_lib MATCHES "RenderSystem_")
Expand Down
41 changes: 19 additions & 22 deletions cmake/FindOptiX.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@

# Locate the OptiX distribution. Search in env path first, then look in the system.

set(OptiX_INSTALL_DIR "$ENV{OPTIX_INSTALL_DIR}" CACHE PATH "Path to OptiX installed location.")
set(OptiX_INSTALL_DIR "$ENV{OPTIX_INSTALL_DIR}"
CACHE PATH "Path to OptiX installed location.")

# The distribution contains both 32 and 64 bit libraries. Adjust the library
# search path based on the bit-ness of the build. (i.e. 64: bin64, lib64; 32:
Expand All @@ -85,20 +86,16 @@ macro(ign_OPTIX_find_api_library name version)
find_library(${name}_LIBRARY
NAMES ${name}.${version} ${name}
PATHS "${OptiX_INSTALL_DIR}/lib${bit_dest}"
NO_DEFAULT_PATH
)
NO_DEFAULT_PATH)
find_library(${name}_LIBRARY
NAMES ${name}.${version} ${name}
)
NAMES ${name}.${version} ${name})
if(WIN32)
find_file(${name}_DLL
NAMES ${name}.${version}.dll
PATHS "${OptiX_INSTALL_DIR}/bin${bit_dest}"
NO_DEFAULT_PATH
)
NO_DEFAULT_PATH)
find_file(${name}_DLL
NAMES ${name}.${version}.dll
)
NAMES ${name}.${version}.dll)
endif()
endmacro()

Expand All @@ -110,11 +107,9 @@ ign_OPTIX_find_api_library(optix_prime 1)
find_path(OptiX_INCLUDE
NAMES optix.h
PATHS "${OptiX_INSTALL_DIR}/include"
NO_DEFAULT_PATH
)
NO_DEFAULT_PATH)
find_path(OptiX_INCLUDE
NAMES optix.h
)
NAMES optix.h)

# Check to make sure we found what we were looking for
function(OptiX_report_error error_message required)
Expand All @@ -139,7 +134,7 @@ endif()

# Macro for setting up dummy targets
function(OptiX_add_imported_library name lib_location dll_lib dependent_libs)
set(CMAKE_IMPORT_FILE_VERSION 1)
set(CMAKE_IMPORT_FILE_VERSION 1) # cmake-lint: disable=C0103

# Create imported target
# ign-cmake modification: changed to use ${target_name} instead of ${name}
Expand All @@ -152,27 +147,24 @@ function(OptiX_add_imported_library name lib_location dll_lib dependent_libs)
IMPORTED_IMPLIB "${lib_location}"
#IMPORTED_LINK_INTERFACE_LIBRARIES "glu32;opengl32"
IMPORTED_LOCATION "${dll_lib}"
IMPORTED_LINK_INTERFACE_LIBRARIES "${dependent_libs}"
)
IMPORTED_LINK_INTERFACE_LIBRARIES "${dependent_libs}")
elseif(UNIX)
set_target_properties(${target_name} PROPERTIES
#IMPORTED_LINK_INTERFACE_LIBRARIES "glu32;opengl32"
IMPORTED_LOCATION "${lib_location}"
# We don't have versioned filenames for now, and it may not even matter.
#IMPORTED_SONAME "${optix_soname}"
IMPORTED_LINK_INTERFACE_LIBRARIES "${dependent_libs}"
)
IMPORTED_LINK_INTERFACE_LIBRARIES "${dependent_libs}")
else()
# Unknown system, but at least try and provide the minimum required
# information.
set_target_properties(${target_name} PROPERTIES
IMPORTED_LOCATION "${lib_location}"
IMPORTED_LINK_INTERFACE_LIBRARIES "${dependent_libs}"
)
IMPORTED_LINK_INTERFACE_LIBRARIES "${dependent_libs}")
endif()

# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)
set(CMAKE_IMPORT_FILE_VERSION) # cmake-lint: disable=C0103
endfunction()

# Sets up a dummy target
Expand All @@ -188,7 +180,12 @@ macro(ign_OptiX_check_same_path libA libB)
# to the ${libB}.
get_filename_component(_optix_name_of_${libA} "${${libA}_LIBRARY}" NAME)
if(EXISTS "${_optix_path_to_${libB}}/${_optix_name_of_${libA}}")
message(WARNING " ${libA} library found next to ${libB} library that is not being used. Due to the way we are using rpath, the copy of ${libA} next to ${libB} will be used during loading instead of the one you intended. Consider putting the libraries in the same directory or moving ${_optix_path_to_${libB}}/${_optix_name_of_${libA} out of the way.")
message(WARNING "\
${libA} library found next to ${libB} library that is not being used. \
Due to the way we are using rpath, the copy of ${libA} next to \
${libB} will be used during loading instead of the one you intended. \
Consider putting the libraries in the same directory or moving \
${_optix_path_to_${libB}}/${_optix_name_of_${libA} out of the way.")
endif()
endif()
set( _${libA}_rpath "-Wl,-rpath,${_optix_path_to_${libA}}" )
Expand Down
2 changes: 1 addition & 1 deletion cmake/FindYAML.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ else()
)
endif()
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
YAML
Expand Down
2 changes: 1 addition & 1 deletion cmake/FindZIP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
ZIP
REQUIRED_VARS ZIP_FOUND)
REQUIRED_VARS ZIP_FOUND)
Loading
Loading