CMakeLists.txt 4.36 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
66
67
68
69
70
71
72
73
74
75
76
77
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
#
#   Universite catholique de Louvain
#   CEREM : Centre for research in mechatronics
#   http://www.robotran.be  
#   Contact : info@robotran.be
#
#
# CMake for compiling the user files of a robotran project in C
# 

# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                       LIBRARY MAIN CONFIGURATIONS
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

if (UNIX)
    cmake_minimum_required(VERSION 3.4)
else()
    cmake_minimum_required(VERSION 3.4)
endif ()

project(Project_userfct)

# flags
if (UNIX)
    set(CMAKE_C_FLAGS "-fPIC")
    set(CMAKE_EXE_LINKER_FLAGS "-fPIC")
endif (UNIX)

# Windows M_PI definitions
if (WIN32)
    add_definitions(-D _USE_MATH_DEFINES)
endif (WIN32)

# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                        SEPARATE COMPILATION
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

if ( FLAG_SEPARATE_USER_FCT )

    # additional CMakeLists.txt
    set(CMAKE_AUX ${ROBOTRAN_SOURCE_DIR}/cmake_aux)
    set(CMAKE_AUX_BIN ${PROJECT_BINARY_DIR}/cmake_aux)

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

    # real-time option
    option (FLAG_REAL_TIME "Real time" OFF)

    if(FLAG_REAL_TIME)
        add_definitions( -DREAL_TIME )

        # configure a header file to pass some of the CMake settings to the source code
        configure_file (
            "${ROBOTRAN_SOURCE_DIR}/conf/cmake_config.h.in"
            "${PROJECT_BINARY_DIR}/conf/cmake_config.h"
        )
        include_directories (${PROJECT_BINARY_DIR}/conf)

        # plot-visu options
        option (FLAG_PLOT "Real time" OFF)
        option (FLAG_VISU "Real time" OFF)
        option (FLAG_JAVA "Real time" OFF)
        option (FLAG_OPEN_GL "Real time" OFF)

        if(FLAG_PLOT)
            add_definitions( -DSDL )
        endif( )

        if(FLAG_VISU)
            add_definitions( -DVISU_3D )
        endif( )

        if(FLAG_JAVA)
            add_definitions( -DJAVA )
        endif( )

        if(FLAG_OPEN_GL)
            add_definitions( -DOPEN_GL )
        endif( )

    endif ( )
endif ( )

# release of debug
release_debug()

# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                         SET LIBRARY
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

# list source files to compile
init_src()
increment_src( ${PROJECT_SOURCE_DIR} )
increment_void_user( ${PROJECT_SOURCE_DIR} )

# list include directories (to find headers)
init_include()
increment_include( ${ROBOTRAN_SOURCE_DIR}/mbs_common )

# include these directories
include_directories ( ${INCLUDE_DIR} )
include_directories ( ${CMAKE_CURRENT_BINARY_DIR} )

if( FLAG_SHARED_LIB OR FLAG_SEPARATE_USER_FCT )
    set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
    add_library(Project_userfct SHARED ${SOURCE_FILES})

    target_link_libraries (Project_userfct ${LIB_MBSYSC_REALTIME})
    target_link_libraries (Project_userfct ${LIB_MBSYSC_MODULES})
    target_link_libraries (Project_userfct ${LIB_MBSYSC_UTILITIES})
    
    # MacOS: Force extension to be .so rather than .dylib
    if(APPLE)
        set_target_properties(Project_userfct PROPERTIES SUFFIX ".so")    
    endif()

    # Windows, copy dll next to executable
    if((NOT UNIX) AND (NOT FLAG_SEPARATE_USER_FCT))
        add_custom_command(TARGET Project_userfct POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/Project_userfct.dll
                ${CMAKE_CURRENT_BINARY_DIR}/../$<CONFIGURATION>/Project_userfct.dll
        )
    endif()
    
else()
    add_library(Project_userfct STATIC ${SOURCE_FILES})
    target_link_libraries (Project_userfct ${LIB_MBSYSC_REALTIME} ${LIB_MBSYSC_UTILITIES})
endif()

# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                         LINK LIBRARIES
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

# MBSysC libraries
if ( FLAG_SEPARATE_BUILD ) # find MBSysC dynamic libraries
139
    find_package( LibRobotranC 1.16.0 REQUIRED )
140
141
142
143
144
145
    add_definitions(${LIB_MBSYSC_DEFINITIONS})
endif()

if (FLAG_PLOT)
    sdl_header_lib(userfct)
endif ( )