CMakeLists.txt 5.12 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
#
# author: Nicolas Van der Noot
#
# Visualization project for Robotran, with OpenGL
#

# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                       PROJECT MAIN CONFIGURATIONS
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


# CMake minimum version
Olivier Lantsoght's avatar
Olivier Lantsoght committed
13
cmake_minimum_required(VERSION 3.4)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

# project name
project (OpenGLRobotran)


# message to display the project name
message(STATUS "Processing ${PROJECT_NAME}")

# for Unix: display all the warnings, except the ones related to /* -- */
if (UNIX)
  set(CMAKE_C_FLAGS "-g -Wall -Wno-comment")
endif (UNIX)

# copy dll files used for Windows
# these dll files are copied in the Executable directory (Debug or Release)
if (WIN32)

Nicolas Van der Noot's avatar
Nicolas Van der Noot committed
31
    # avoid warnings
32
    if(COMMAND cmake_policy AND ${CMAKE_VERSION} VERSION_GREATER "3.1")
Nicolas Van der Noot's avatar
Nicolas Van der Noot committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
        cmake_policy(SET CMP0054 NEW)
    endif()

    # Visual studio version
    if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
        if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 18.0)
            message("Visual Studio version set to VS2012 (${CMAKE_CXX_COMPILER_VERSION})")
            set(MSVC_VERSION lib-vc2012)
        elseif (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 19.0)
            message("Visual Studio version set to VS2013 (${CMAKE_CXX_COMPILER_VERSION})")
            set(MSVC_VERSION lib-vc2013)
        else ( )
            message("Visual Studio version set to VS2015 (${CMAKE_CXX_COMPILER_VERSION})")
            set(MSVC_VERSION lib-vc2015)
        endif ( )
    else ( )
        message(FATAL_ERROR "CMake error: only Visual Studio projects can currently be used on Windows !")
    endif ( )

    # WIN32 or WIN64 detetction
    if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) # 64bit Windows
        SET(WIN_LIB_DIRECTORY win64_include_lib)
    else( ) # 32bit Windows
        SET(WIN_LIB_DIRECTORY win32_include_lib)
    endif( )

    # common dll
    file(COPY ${PROJECT_SOURCE_DIR}/../${WIN_LIB_DIRECTORY}/dll/ DESTINATION ${CMAKE_BINARY_DIR}/Debug)
    file(COPY ${PROJECT_SOURCE_DIR}/../${WIN_LIB_DIRECTORY}/dll/ DESTINATION ${CMAKE_BINARY_DIR}/Release)

    # GLFW
    file(COPY ${PROJECT_SOURCE_DIR}/../${WIN_LIB_DIRECTORY}/dll/GLFW/${MSVC_VERSION}/ DESTINATION ${CMAKE_BINARY_DIR}/Debug)
    file(COPY ${PROJECT_SOURCE_DIR}/../${WIN_LIB_DIRECTORY}/dll/GLFW/${MSVC_VERSION}/ DESTINATION ${CMAKE_BINARY_DIR}/Release)
66
67
68
69
70
71
72
73
74
75
76
endif ( )

# additional CMake functions
set(CMAKE_AUX ${PROJECT_SOURCE_DIR}/../cmake_aux)
set(CMAKE_AUX_BIN ${PROJECT_BINARY_DIR}/cmake_aux)

add_subdirectory ( ${CMAKE_AUX}/listing/   ${CMAKE_AUX_BIN}/listing/   )
add_subdirectory ( ${CMAKE_AUX}/libraries/ ${CMAKE_AUX_BIN}/libraries/ )

# Windows M_PI definitions
if (WIN32)
Nicolas Van der Noot's avatar
Nicolas Van der Noot committed
77
    add_definitions(-D _USE_MATH_DEFINES)
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
endif (WIN32)

# project own definition
add_definitions(-D SEPARATE_OPEN_GL)



# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                           USER ABSOLUTE PATHS
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

# configure header files to pass some of the CMake settings to the source code
set (ROBOTRAN_SOURCE_DIR "${PROJECT_SOURCE_DIR}/..")

configure_file (
  "${PROJECT_SOURCE_DIR}/../conf/cmake_config.h.in"
  "${PROJECT_BINARY_DIR}/conf/cmake_config.h"
)

set(OPEN_GL_FILES_PATH ${PROJECT_SOURCE_DIR}/../mbs_common/mbs_realtime/open_gl/)

configure_file (
    "${PROJECT_SOURCE_DIR}/../mbs_common/mbs_realtime/open_gl/conf/cmake_open_gl_config.h.in"
    "${PROJECT_BINARY_DIR}/conf/cmake_open_gl_config.h"
)

# 'cmake_config.h.in' and 'cmake_open_gl_config.h.in' is in the 'conf' folder
include_directories (${PROJECT_BINARY_DIR}/conf)



# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                           EXTERNAL LIBRARIES
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../conf)

# Libxml2
xml_lib(main)

# OpenGL
open_gl_lib(main)


# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                           LIST FILES
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

 
# list source files to compile
init_src()

increment_src("${PROJECT_SOURCE_DIR}/src")
increment_src("${PROJECT_SOURCE_DIR}/../mbs_common/mbs_realtime/open_gl")


# list include directories (to find headers)
init_include()

increment_include("${PROJECT_SOURCE_DIR}/src")
increment_include("${PROJECT_SOURCE_DIR}/../mbs_common/mbs_realtime/open_gl")



# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                         CONFIGURE EXECUTABLE
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

# include these directories
include_directories (${INCLUDE_DIR})

# name of the executable
set (Executable Exec)

# generate the executable
add_executable (${Executable} ${SOURCE_FILES})

# link library: Libxml2
target_link_libraries ( ${Executable} ${LIBXML2_LIBRARIES} )

# link library: OpenGL
target_link_libraries ( ${Executable} ${OPEN_GL_LIBS})

# math external library (for Unix): linkage
if (UNIX)
Nicolas Van der Noot's avatar
Nicolas Van der Noot committed
163
    target_link_libraries (${Executable} m)
164
endif (UNIX)