[CMake] Help getting my simple OpenGL project to use cmake
Michael Wild
themiwi at gmail.com
Thu Jul 8 04:18:40 EDT 2010
Hi
Comments are inline...
On 8. Jul, 2010, at 10:05 , Craig Pemberton wrote:
> Hello everyone,
>
> I am working on converting my project from using a handwritten
> Makefile to using cmake.
>
> I have been playing with cmake but I keep running into problems and
> I'm probably writing really ugly CMakeLists.txt files.
>
<snip/>
> Here is what my CMakeLists.txt files currently look like and I have no
> idea if I'm remotely doing the right thing.
>
> In the root directory /
>
> cmake_minimum_required (VERSION 2.6)
> project(Pemberton)
> find_package(GLUT)
> find_package(OpenGL)
If your project requires GLUT and OpenGL, you should add REQUIRED to the argument list.
> add_definitions(-Wall -Wextra -pedantic -Werror -O3)
> SUBDIRS(library programs)
Use add_subirectory instead. subdirs is deprecated.
> INCLUDE_DIRECTORIES(library)
> set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/library")
> set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")
> mark_as_advanced(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
Use CMAKE_ARCHIVE_OUTPUT_DIRECTORY, CMAKE_LIBRARY_OUTPUT_DIRECTORY and CMAKE_RUNTIME_OUTPUT_DIRECTORY instead. You don't have to mark them as advanced, since they are not cached.
>
> In library/
>
> FILE(GLOB SOURCE_FILES *.cpp)
> FILE(GLOB INCLUDE_FILES *.h)
> SOURCE_GROUP("Source Files" FILES ${SOURCE_FILES})
> SOURCE_GROUP("Header Files" FILES ${HEADER_FILES})
> ADD_LIBRARY (Graphics STATIC ${SOURCE_FILES} ${INCLUDE_FILES})
>
Don't use FILE(GLOB ...). It is pure evil (it asks for all kinds of trouble!). List the sources explicitly instead:
set(SOURCE_FILES
Affine.cpp
Camera.cpp
Canvas.cpp
Color.cpp
Light.cpp
Material.cpp
Matrix.cpp
Quaternion.cpp
Ray.cpp
Texture.cpp
utility.cpp
Vertex.cpp
)
set(INCLUDE_FILES
Affine.h
Camera.h
Canvas.h
Color.h
Light.h
Material.h
Matrix.h
Quaternion.h
Ray.h
Texture.h
Vertex.h
)
> In programs/
>
> include_directories(../library)
> #FILE(GLOB SOURCE_FILES .*.cpp)
> #FILE(GLOB INCLUDE_FILES *.h)
> #SOURCE_GROUP("Source Files" FILES ${SOURCE_FILES})
> #SOURCE_GROUP("Header Files" FILES ${HEADER_FILES})
> find_package(GLUT)
> find_package(OpenGL)
No need to repeat that, right?
> add_executable(lsystem lsystem.cpp ${GLUT_LIBRARY} ${OPENGL_LIBRARY})
Make this:
add_executable(lsystem lsystem.cpp)
target_link_libraries(${GLUT_LIBRARIES} ${OPENGL_LIBRARIES})
> #set(PROGRAMS ifs lsystem raytrace subdivide)
> #set(CORELIBS ${GLUT_LIBRARY} ${OPENGL_LIBRARY} GL GLU)
> #foreach(programs ${PROGRAMS})
> # add_executable(${program} ${SOURCE_FILES} ${INCLUDE_FILES})
> #target_link_libraries(${program} ${CORELIBS})
> #endforeach(program)
>
> What is the correct way to set this up? Currently it's saying it can't
> find OpenGL functions. I would like to have some really nice clean
> cmake files.
>
> Best regards,
> Craig
HTH
Michael
More information about the CMake
mailing list