Skip to content

Commit 4fab2a4

Browse files
committed
Set defaults only if main project
Do not set CMake defaults unless this is the main project. A superproject should be able to set e.g. BUILD_SHARED_LIBS.
1 parent 0c5b906 commit 4fab2a4

File tree

3 files changed

+58
-37
lines changed

3 files changed

+58
-37
lines changed

CMakeLists.txt

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,42 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
1818
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/tools")
1919
project (PROFINET VERSION 0.1.0)
2020

21-
include(AddOsal)
22-
include(GenerateExportHeader)
23-
include(CMakeDependentOption)
24-
21+
# Default settings if this is the main project
2522
if (CMAKE_PROJECT_NAME STREQUAL PROFINET)
2623
include(CTest)
24+
25+
# Make option visible in ccmake, cmake-gui
26+
option (BUILD_SHARED_LIBS "Build shared library" OFF)
27+
28+
# Default to release build with debug info
29+
if (NOT CMAKE_BUILD_TYPE)
30+
set (CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
31+
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
32+
FORCE)
33+
endif (NOT CMAKE_BUILD_TYPE)
34+
35+
# Default to installing in build directory
36+
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
37+
set(CMAKE_INSTALL_PREFIX ${PROFINET_BINARY_DIR}/install
38+
CACHE PATH "Default install path" FORCE)
39+
endif()
40+
41+
message(STATUS "Current build type is: ${CMAKE_BUILD_TYPE}")
42+
message(STATUS "Current install path is: ${CMAKE_INSTALL_PREFIX}")
43+
message(STATUS "Building for ${CMAKE_SYSTEM_NAME}")
2744
endif()
2845

29-
# Set required standard level
30-
set (CMAKE_C_STANDARD 99)
31-
set (CMAKE_CXX_STANDARD 11)
46+
include(AddOsal)
47+
include(GenerateExportHeader)
48+
include(CMakeDependentOption)
49+
include(GetGitRevision)
3250

3351
# Always use standard .o suffix
3452
set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1)
3553
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)
3654

3755
# Options. See options.h.in for more information.
3856

39-
option (BUILD_SHARED_LIBS "Build shared library" OFF)
4057
option (PNET_OPTION_FAST_STARTUP "" ON)
4158
option (PNET_OPTION_PARAMETER_SERVER "" ON)
4259
option (PNET_OPTION_IR "" ON)
@@ -137,30 +154,7 @@ set_property(CACHE PF_PNAL_LOG PROPERTY STRINGS ${LOG_STATE_VALUES})
137154
set(PNET_LOG ON CACHE STRING "PNET log")
138155
set_property(CACHE PNET_LOG PROPERTY STRINGS ${LOG_STATE_VALUES})
139156

140-
# Default to release build with debug info
141-
if (NOT CMAKE_BUILD_TYPE)
142-
set (CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
143-
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
144-
FORCE)
145-
endif (NOT CMAKE_BUILD_TYPE)
146-
message (STATUS "Current build type is: ${CMAKE_BUILD_TYPE}")
147-
148-
# Default to installing in build directory
149-
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
150-
set(CMAKE_INSTALL_PREFIX ${PROFINET_BINARY_DIR}/install
151-
CACHE PATH "Default install path" FORCE)
152-
endif()
153-
message(STATUS "Current install path is: ${CMAKE_INSTALL_PREFIX}")
154-
155-
# Get git revision if available
156-
find_package(Git QUIET)
157-
execute_process(COMMAND
158-
"${GIT_EXECUTABLE}" describe --tags --always --dirty
159-
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
160-
OUTPUT_VARIABLE PNET_VERSION_GIT
161-
ERROR_QUIET
162-
OUTPUT_STRIP_TRAILING_WHITESPACE
163-
)
157+
# Generate version numbers
164158
configure_file (
165159
version.h.in
166160
${PROFINET_BINARY_DIR}/src/version.h
@@ -182,14 +176,20 @@ if (CMAKE_PROJECT_NAME STREQUAL PROFINET AND BUILD_TESTING)
182176
endif()
183177

184178
# Platform configuration
185-
include(${CMAKE_SYSTEM_NAME})
186-
message (STATUS "Building for ${CMAKE_SYSTEM_NAME}")
179+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${CMAKE_SYSTEM_NAME}.cmake)
187180

188181
generate_export_header(profinet
189182
BASE_NAME pnet
190183
EXPORT_FILE_NAME ${PROFINET_BINARY_DIR}/include/pnet_export.h
191184
)
192185

186+
set_target_properties (profinet pn_dev
187+
PROPERTIES
188+
C_STANDARD 99
189+
)
190+
191+
target_compile_features(profinet PUBLIC c_std_99)
192+
193193
target_include_directories(profinet
194194
PUBLIC
195195
$<BUILD_INTERFACE:${PROFINET_SOURCE_DIR}/include>

test/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515

1616
option(TEST_DEBUG "Add trace output to tests" OFF)
1717

18+
set_target_properties (pf_test
19+
PROPERTIES
20+
C_STANDARD 99
21+
CXX_STANDARD 11
22+
)
23+
1824
target_sources(pf_test PRIVATE
1925
# Unit tests
2026
test_alarm.cpp

version.h.in

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1+
/*********************************************************************
2+
* _ _ _
3+
* _ __ | |_ _ | | __ _ | |__ ___
4+
* | '__|| __|(_)| | / _` || '_ \ / __|
5+
* | | | |_ _ | || (_| || |_) |\__ \
6+
* |_| \__|(_)|_| \__,_||_.__/ |___/
7+
*
8+
* www.rt-labs.com
9+
* Copyright 2018 rt-labs AB, Sweden.
10+
*
11+
* This software is dual-licensed under GPLv3 and a commercial
12+
* license. See the file LICENSE.md distributed with this software for
13+
* full license information.
14+
********************************************************************/
15+
116
#ifndef VERSION_H
217
#define VERSION_H
318

4-
#cmakedefine PNET_VERSION_GIT "@PNET_VERSION_GIT@"
19+
#cmakedefine PROFINET_GIT_REVISION "@PROFINET_GIT_REVISION@"
520

6-
#if !defined(PNET_VERSION_BUILD) && defined(PNET_VERSION_GIT)
7-
#define PNET_VERSION_BUILD PNET_VERSION_GIT
21+
#if !defined(PNET_VERSION_BUILD) && defined(PROFINET_GIT_REVISION)
22+
#define PNET_VERSION_BUILD PROFINET_GIT_REVISION
823
#endif
924

1025
/* clang-format-off */

0 commit comments

Comments
 (0)