CMake FIND_LIBRARY works on Windows but not OS X

1.4k views Asked by At

The same code ran on Cmake in windows finds the libraries, but on mac it cannot find them.The code finds the Include directories fine just not the libraries

Here is a screen of the Cmake output enter image description here

And here is a Screen of the Directory structure enter image description here

here is the CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

project (GameCreatorEngine)

# version can be passed into the application from CMake TODO

set(cmake_test_VERSION_MAJOR 1)
set(cmake_test_VERSION_MINOR 3)

# compiler flags

add_definitions(
    -c
    -W4
)

# SDL LIB INCLUDES

SET( SDL2_SEARCH_PATHS
    ${SDL2_ROOT_DIR}                
    ./res/lib/SDL2
)

FIND_PATH( SDL2_INCLUDE_DIRS
    NAMES
        SDL.h SDL2/SDL.h
    PATHS
        ${SDL2_SEARCH_PATHS}
    PATH_SUFFIXES
        include
)

FIND_LIBRARY( SDL2
    NAMES
        SDL2.lib 
    PATHS
        ${SDL2_SEARCH_PATHS}
    PATH_SUFFIXES
        lib
)

FIND_LIBRARY( SDL2_MAIN
    NAMES
        SDL2main.lib 
    PATHS
        ${SDL2_SEARCH_PATHS}
    PATH_SUFFIXES
        lib
)

IF ( SDL2_INCLUDE_DIRS AND SDL2_MAIN AND SDL2)
    SET( SDL2_FOUND TRUE )
    MESSAGE(STATUS "Looking for SDL2 - found")
ELSE ( SDL2_INCLUDE_DIRS AND SDL2_MAIN AND SDL2 )
    SET( SDL2_FOUND FALSE )
    MESSAGE(STATUS "Looking for SDL2 - not found")
ENDIF ( SDL2_INCLUDE_DIRS AND SDL2_MAIN AND SDL2 )

# GLEW LIB INCLUDES

SET(GLEW_SEARCH_PATHS
    ${GLEW_ROOT_DIR}                
    ./res/lib/GLEW
)

FIND_PATH( GLEW_INCLUDE_DIRS
    NAMES
        glew.h
    PATHS
        ${GLEW_SEARCH_PATHS}
    PATH_SUFFIXES
        include
)

FIND_LIBRARY( GLEW_LIBRARIES
    NAMES
        glew32
    PATHS
        ${GLEW_SEARCH_PATHS}
    PATH_SUFFIXES
        lib/Release/Win32
)

IF ( GLEW_INCLUDE_DIRS AND GLEW_LIBRARIES )
    SET( GLEW_FOUND TRUE )
    MESSAGE( STATUS "Looking for GLEW - found" )
ELSE ( GLEW_INCLUDE_DIRS AND GLEW_LIBRARIES )
    SET( GLEW_FOUND FALSE )
    MESSAGE( STATUS "Looking for GLEW - not found" )
ENDIF ( GLEW_INCLUDE_DIRS AND GLEW_LIBRARIES )

# ASSIMP 

SET(ASSIMP_SEARCH_PATHS
    ${ASSIMP_ROOT_DIR}              
    ./res/lib/assimp
)

FIND_PATH( ASSIMP_INCLUDE_DIRS
    NAMES
        mesh.h
    PATHS
        ${ASSIMP_SEARCH_PATHS}
    PATH_SUFFIXES
        include
)

FIND_LIBRARY( ASSIMP_LIBRARIES
    NAMES
        assimp ASSIMP
    PATHS
        ${ASSIMP_SEARCH_PATHS}
    PATH_SUFFIXES
        lib
        lib/x86 
        lib/x64
)

IF ( ASSIMP_INCLUDE_DIRS AND ASSIMP_LIBRARIES )
    SET( ASSIMP_FOUND TRUE )
    MESSAGE(STATUS "Looking for ASSIMP - found")
ELSE ( ASSIMP_INCLUDE_DIRS AND ASSIMP_LIBRARIES )
    SET( ASSIMP_FOUND FALSE )
    MESSAGE(STATUS "Looking for ASSIMP - not found")
ENDIF ( ASSIMP_INCLUDE_DIRS AND ASSIMP_LIBRARIES )

# glm maths lib
SET( GLM_SEARCH_PATHS
    ${GLM_ROOT_DIR}             
    ./res/lib/glm
)

FIND_PATH( GLM_INCLUDE_DIRS
    NAMES
        glm.hpp
    PATHS
        ${GLM_SEARCH_PATHS}
    PATH_SUFFIXES
        include
)

IF ( GLM_INCLUDE_DIRS)
    SET( GLM_FOUND TRUE )
    MESSAGE(STATUS "Looking for GLM - found")
ELSE ( GLM_INCLUDE_DIRS )
    SET( ASSIMP_FOUND FALSE )
    MESSAGE(STATUS "Looking for GLM - not found")
ENDIF ( GLM_INCLUDE_DIRS )

# OpenGL
find_package(OpenGL REQUIRED)

# GameCreatorLibrary 
file(GLOB HDRS ${ENGINE_SOURCE_DIR}src/*.h)
file(GLOB SRCS ${ENGINE_SOURCE_DIR}src/*.cpp src/*.c)
add_executable(GameCreatorEngine ${HDRS} ${SRCS})

# Define the include DIRs
include_directories(
    ${SDL2_INCLUDE_DIRS}
    ${GLEW_INCLUDE_DIRS}
    ${ASSIMP_INCLUDE_DIRS}
    ${GLM_INCLUDE_DIRS}
    ${OPENGL_INCLUDE_DIRS}
    ${ENGINE_SOURCE_DIR}/headers
    ${ENGINE_SOURCE_DIR}/sources
)

# Define the link libraries
target_link_libraries( GameCreatorEngine
    ${SDL2}
    ${SDL2_MAIN}
    ${GLEW_LIBRARIES}
    ${ASSIMP_LIBRARIES}
    ${OPENGL_LIBRARIES}
)
1

There are 1 answers

0
ComicSansMS On BEST ANSWER

The proper filename extension for libraries varies on different platforms. While .lib is used for both static and dll import libraries on Windows, OS X uses different naming conventions (.a for static and .so/.dylib for dynamic libraries, possibly with a lib prefix).

In order to still allow code that works with all those different naming conventions, find_library expects you to omit any extensions or prefixes completely and just give the bare name of the library.

So instead of find_library(SDL2 NAMES SDL2.lib [...]) you should just write find_library(SDL2 NAMES SDL2 [...]).

From your question it also seems that you are trying to link your OS X build against Windows binaries (.lib and .dll file extensions). This will not work. You need a separate set of binaries compiled for OS X.