Skip to content

Commit

Permalink
Make CMake path variables more robust
Browse files Browse the repository at this point in the history
Add quotes around variables containing paths - this might require a second pass...

fixes #258
  • Loading branch information
mkraemer committed Apr 9, 2014
1 parent e011fa3 commit 05a7db5
Show file tree
Hide file tree
Showing 35 changed files with 564 additions and 572 deletions.
40 changes: 20 additions & 20 deletions CMakeLists.txt
Expand Up @@ -44,7 +44,7 @@ message(STATUS "Using cmake version ${CMAKE_VERSION}")
#-------------------------------------------------------------------------------
# Specify the default install path
if (NOT DEFINED CMAKE_INSTALL_PREFIX)
SET( CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR}/ )
SET( CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/" )
endif()

if (NOT DEFINED CMAKE_INCDIR_BASE)
Expand All @@ -67,37 +67,37 @@ if (NOT DEFINED CMAKE_DOCDIR_BASE)
set( CMAKE_DOCDIR_BASE share/doc/opensubdiv )
else()
if (IS_ABSOLUTE ${CMAKE_DOCDIR_BASE})
set( CMAKE_DOCDIR_BASE ${CMAKE_DOCDIR_BASE} )
set( CMAKE_DOCDIR_BASE "${CMAKE_DOCDIR_BASE}" )
else()
set( CMAKE_DOCDIR_BASE ${CMAKE_INSTALL_PREFIX}/${CMAKE_DOCDIR_BASE} )
set( CMAKE_DOCDIR_BASE "${CMAKE_INSTALL_PREFIX}/${CMAKE_DOCDIR_BASE}" )
endif()
endif()

# Allow install path to be overridden for cross-compile builds
if(LIBRARY_OUTPUT_PATH_ROOT)
SET( CMAKE_INSTALL_PREFIX ${LIBRARY_OUTPUT_PATH_ROOT}/ )
SET( CMAKE_INSTALL_PREFIX "${LIBRARY_OUTPUT_PATH_ROOT}/" )
endif()

# Set the directory where the executables will be stored.
set(EXECUTABLE_OUTPUT_PATH
${PROJECT_BINARY_DIR}/bin
"${PROJECT_BINARY_DIR}/bin"
CACHE PATH
"Directory where executables will be stored"
)

# Set the directory where the libraries will be stored.
set(LIBRARY_OUTPUT_PATH
${PROJECT_BINARY_DIR}/lib
"${PROJECT_BINARY_DIR}/lib"
CACHE PATH
"Directory where all libraries will be stored"
)

# Specify the list of directories to search for cmake modules.
set(CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/cmake
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
)

list(APPEND CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
list(APPEND CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
Expand Down Expand Up @@ -463,19 +463,19 @@ add_custom_target( public_headers )

macro(_add_doxy_headers headers)
if (NOT NO_DOC AND DOXYGEN_FOUND)
file(RELATIVE_PATH path ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} )
file(RELATIVE_PATH path "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" )

string(REPLACE "/" "_" targetpath ${path})

foreach (header ${headers})

set(infile ${CMAKE_CURRENT_SOURCE_DIR}/${header})
set(outfile ${CMAKE_BINARY_DIR}/public_headers/${path}/${header})
set(infile "${CMAKE_CURRENT_SOURCE_DIR}/${header}")
set(outfile "${CMAKE_BINARY_DIR}/public_headers/${path}/${header}")
set(targetname "${targetpath}_${header}")

add_custom_command(
OUTPUT
${outfile}
"${outfile}"
COMMAND
${CMAKE_COMMAND}
ARGS
Expand All @@ -484,7 +484,7 @@ macro(_add_doxy_headers headers)
${infile}
)

add_custom_target(${targetname} DEPENDS ${outfile})
add_custom_target(${targetname} DEPENDS "${outfile}")

#set_target_properties(${targetname} PROPERTIES FOLDER "public_headers/")

Expand All @@ -507,20 +507,20 @@ function(_stringify src_files varname)

foreach(src_file ${src_files})

string(REGEX REPLACE ".*[.](.*)" "\\1" extension ${src_file})
string(REGEX REPLACE ".*[.](.*)" "\\1" extension "${src_file}")

if(NOT ${extension} STREQUAL "cu")

string(REGEX REPLACE "(.*)[.].*" "\\1.gen.h" inc_file ${src_file})
list(APPEND inc_files ${inc_file})
string(REGEX REPLACE "(.*)[.].*" "\\1.gen.h" inc_file "${src_file}")
list(APPEND inc_files "${inc_file}")

add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/${inc_file}
"${CMAKE_CURRENT_BINARY_DIR}/${inc_file}"
COMMAND
stringify ${CMAKE_CURRENT_SOURCE_DIR}/${src_file} ${CMAKE_CURRENT_BINARY_DIR}/${inc_file}
stringify "${CMAKE_CURRENT_SOURCE_DIR}/${src_file}" "${CMAKE_CURRENT_BINARY_DIR}/${inc_file}"
DEPENDS
stringify ${CMAKE_CURRENT_SOURCE_DIR}/${src_file}
stringify "${CMAKE_CURRENT_SOURCE_DIR}/${src_file}"
)

endif()
Expand Down Expand Up @@ -549,7 +549,7 @@ macro(_add_possibly_cuda_executable target)
endif()

if(CMAKE_COMPILER_IS_ICC)
target_link_libraries(${target} ${ICC_LIBRARIES})
target_link_libraries(${target} "${ICC_LIBRARIES}")
endif()
endmacro()

Expand Down
16 changes: 8 additions & 8 deletions cmake/FindDXSDK.cmake
Expand Up @@ -38,10 +38,10 @@ if (WIN32)
NAMES
D3D11.h D3Dcompiler.h
PATHS
${DXSDK_LOCATION}/Include
$ENV{DXSDK_LOCATION}/Include
${DXSDK_ROOT}/Include
$ENV{DXSDK_ROOT}/Include
"${DXSDK_LOCATION}/Include"
"$ENV{DXSDK_LOCATION}/Include"
"${DXSDK_ROOT}/Include"
"$ENV{DXSDK_ROOT}/Include"
"C:/Program Files (x86)/Microsoft DirectX SDK*/Include"
"C:/Program Files/Microsoft DirectX SDK*/Include"
)
Expand All @@ -55,10 +55,10 @@ if (WIN32)
find_path(LIBRARY_DIR
d3d11.lib
PATHS
${DXSDK_LOCATION}/Lib/${ARCH}
$ENV{DXSDK_LOCATION}/Lib/${ARCH}
${DXSDK_ROOT}/Lib/${ARCH}
$ENV{DXSDK_ROOT}/Lib/${ARCH}
"${DXSDK_LOCATION}/Lib/${ARCH}"
"$ENV{DXSDK_LOCATION}/Lib/${ARCH}"
"${DXSDK_ROOT}/Lib/${ARCH}"
"$ENV{DXSDK_ROOT}/Lib/${ARCH}"
"C:/Program Files (x86)/Microsoft DirectX SDK*/Lib/${ARCH}"
"C:/Program Files/Microsoft DirectX SDK*/Lib/${ARCH}"
)
Expand Down
26 changes: 13 additions & 13 deletions cmake/FindGLEW.cmake
Expand Up @@ -37,21 +37,21 @@ if (WIN32)
NAMES
GL/glew.h
PATHS
${GLEW_LOCATION}/include
$ENV{GLEW_LOCATION}/include
$ENV{PROGRAMFILES}/GLEW/include
${PROJECT_SOURCE_DIR}/extern/glew/include
"${GLEW_LOCATION}/include"
"$ENV{GLEW_LOCATION}/include"
"$ENV{PROGRAMFILES}/GLEW/include"
"${PROJECT_SOURCE_DIR}/extern/glew/include"
DOC "The directory where GL/glew.h resides" )

find_library( GLEW_LIBRARY
NAMES
glew GLEW glew32s glew32
PATHS
${GLEW_LOCATION}/lib
$ENV{GLEW_LOCATION}/lib
$ENV{PROGRAMFILES}/GLEW/lib
${PROJECT_SOURCE_DIR}/extern/glew/bin
${PROJECT_SOURCE_DIR}/extern/glew/lib
"${GLEW_LOCATION}/lib"
"$ENV{GLEW_LOCATION}/lib"
"$ENV{PROGRAMFILES}/GLEW/lib"
"${PROJECT_SOURCE_DIR}/extern/glew/bin"
"${PROJECT_SOURCE_DIR}/extern/glew/lib"
DOC "The GLEW library")
endif ()

Expand All @@ -60,8 +60,8 @@ if (${CMAKE_HOST_UNIX})
NAMES
GL/glew.h
PATHS
${GLEW_LOCATION}/include
$ENV{GLEW_LOCATION}/include
"${GLEW_LOCATION}/include"
"$ENV{GLEW_LOCATION}/include"
/usr/include
/usr/local/include
/sw/include
Expand All @@ -73,8 +73,8 @@ if (${CMAKE_HOST_UNIX})
NAMES
GLEW glew
PATHS
${GLEW_LOCATION}/lib
$ENV{GLEW_LOCATION}/lib
"${GLEW_LOCATION}/lib"
"$ENV{GLEW_LOCATION}/lib"
/usr/lib64
/usr/lib
/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}
Expand Down
64 changes: 32 additions & 32 deletions cmake/FindGLFW.cmake
Expand Up @@ -35,10 +35,10 @@ find_path( GLFW_INCLUDE_DIR
GL/glfw.h
GLFW/glfw3.h
PATHS
${GLFW_LOCATION}/include
$ENV{GLFW_LOCATION}/include
$ENV{PROGRAMFILES}/GLFW/include
${OPENGL_INCLUDE_DIR}
"${GLFW_LOCATION}/include"
"$ENV{GLFW_LOCATION}/include"
"$ENV{PROGRAMFILES}/GLFW/include"
"${OPENGL_INCLUDE_DIR}"
/usr/openwin/share/include
/usr/openwin/include
/usr/X11R6/include
Expand All @@ -58,10 +58,10 @@ if (WIN32)
NAMES
glfw32
PATHS
${GLFW_LOCATION}/lib
${GLFW_LOCATION}/lib/x64
$ENV{GLFW_LOCATION}/lib
${OPENGL_LIBRARY_DIR}
"${GLFW_LOCATION}/lib"
"${GLFW_LOCATION}/lib/x64"
"$ENV{GLFW_LOCATION}/lib"
"${OPENGL_LIBRARY_DIR}"
/usr/lib
/usr/lib/w32api
/usr/local/lib
Expand All @@ -77,14 +77,14 @@ if (WIN32)
glfw
glfw3
PATHS
${GLFW_LOCATION}/lib
${GLFW_LOCATION}/lib/x64
${GLFW_LOCATION}/lib-msvc110
$ENV{GLFW_LOCATION}/lib
${PROJECT_SOURCE_DIR}/extern/glfw/bin
${PROJECT_SOURCE_DIR}/extern/glfw/lib
$ENV{PROGRAMFILES}/GLFW/lib
${OPENGL_LIBRARY_DIR}
"${GLFW_LOCATION}/lib"
"${GLFW_LOCATION}/lib/x64"
"${GLFW_LOCATION}/lib-msvc110"
"$ENV{GLFW_LOCATION}/lib"
"${PROJECT_SOURCE_DIR}/extern/glfw/bin"
"${PROJECT_SOURCE_DIR}/extern/glfw/lib"
"$ENV{PROGRAMFILES}/GLFW/lib"
"${OPENGL_LIBRARY_DIR}"
DOC
"The GLFW library"
)
Expand All @@ -96,10 +96,10 @@ else ()
glfw
glfw3
PATHS
${GLFW_LOCATION}/lib
${GLFW_LOCATION}/lib/cocoa
$ENV{GLFW_LOCATION}/lib
$ENV{GLFW_LOCATION}/lib/cocoa
"${GLFW_LOCATION}/lib"
"${GLFW_LOCATION}/lib/cocoa"
"$ENV{GLFW_LOCATION}/lib"
"$ENV{GLFW_LOCATION}/lib/cocoa"
/usr/local/lib
)
set(GLFW_cocoa_LIBRARY "-framework Cocoa" CACHE STRING "Cocoa framework for OSX")
Expand All @@ -118,17 +118,17 @@ else ()
message(FATAL_ERROR "xf86vmode library not found - required for GLFW")
endif()

list(APPEND GLFW_x11_LIBRARY ${X11_Xrandr_LIB} ${X11_Xxf86vm_LIB})
list(APPEND GLFW_x11_LIBRARY "${X11_Xrandr_LIB}" "${X11_Xxf86vm_LIB}")

find_library( GLFW_glfw_LIBRARY
NAMES
glfw
glfw3
PATHS
${GLFW_LOCATION}/lib
$ENV{GLFW_LOCATION}/lib
${GLFW_LOCATION}/lib/x11
$ENV{GLFW_LOCATION}/lib/x11
"${GLFW_LOCATION}/lib"
"$ENV{GLFW_LOCATION}/lib"
"${GLFW_LOCATION}/lib/x11"
"$ENV{GLFW_LOCATION}/lib/x11"
/usr/lib64
/usr/lib
/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}
Expand All @@ -148,14 +148,14 @@ set( GLFW_FOUND "NO" )
if(GLFW_INCLUDE_DIR)

if(GLFW_glfw_LIBRARY)
set( GLFW_LIBRARIES ${GLFW_glfw_LIBRARY}
${GLFW_x11_LIBRARY}
${GLFW_cocoa_LIBRARY}
${GLFW_iokit_LIBRARY}
${GLFW_corevideo_LIBRARY} )
set( GLFW_LIBRARIES "${GLFW_glfw_LIBRARY}"
"${GLFW_x11_LIBRARY}"
"${GLFW_cocoa_LIBRARY}"
"${GLFW_iokit_LIBRARY}"
"${GLFW_corevideo_LIBRARY}" )
set( GLFW_FOUND "YES" )
set (GLFW_LIBRARY ${GLFW_LIBRARIES})
set (GLFW_INCLUDE_PATH ${GLFW_INCLUDE_DIR})
set (GLFW_LIBRARY "${GLFW_LIBRARIES}")

This comment has been minimized.

Copy link
@elfring

elfring Apr 17, 2014

I find the addition of quotation marks wrong for this variable assignment.

I find it also generally dangerous to mix the singular and plural form for such a CMake variable name. How do you think about to apply a safe and consistent naming pattern?

set (GLFW_INCLUDE_PATH "${GLFW_INCLUDE_DIR}")
endif(GLFW_glfw_LIBRARY)


Expand Down

0 comments on commit 05a7db5

Please sign in to comment.