Skip to content

Commit 737164b

Browse files
cmake: streamline option definitions
Change-Id: Ic4033c1ee304b1e94d5d7b2e743a2d1d45975a5c Co-authored-by: MarkovaMaria <[email protected]> Co-authored-by: Roman Dementiev <[email protected]>
1 parent a6823e6 commit 737164b

File tree

5 files changed

+74
-28
lines changed

5 files changed

+74
-28
lines changed

.github/workflows/ci-cmake-options.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,47 @@ jobs:
5656
export VERBOSE=1
5757
make install -j$(nproc)
5858
59+
- name: CMake Custom build install
60+
run: |
61+
cmake --version
62+
rm -rf ${{ github.workspace }}/build
63+
cmake -B ${{ github.workspace }}/build -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/build -DCMAKE_CXX_FLAGS_CUSTOM:STRING="-O2 -g" -DCMAKE_BUILD_TYPE=CUSTOM
64+
cd ${{ github.workspace }}/build
65+
export VERBOSE=1
66+
make install -j$(nproc)
67+
68+
- name: CMake User-flags build install
69+
run: |
70+
cmake --version
71+
rm -rf ${{ github.workspace }}/build
72+
cmake -B ${{ github.workspace }}/build -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/build -DCMAKE_CXX_FLAGS="-O2 -g -fPIC"
73+
cd ${{ github.workspace }}/build
74+
export VERBOSE=1
75+
make install -j$(nproc)
76+
77+
- name: CMake env var option build install
78+
run: |
79+
cmake --version
80+
rm -rf ${{ github.workspace }}/build
81+
export CXXFLAGS="-grecord-gcc-switches"
82+
export CFLAGS="-fstack-protector-strong"
83+
export LDFLAGS="-Wl,-z,now"
84+
cmake -B ${{ github.workspace }}/build -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/build -DCMAKE_CXX_FLAGS_CUSTOM:STRING="-O2 -g -fPIC" -DCMAKE_BUILD_TYPE=CUSTOM
85+
cd ${{ github.workspace }}/build
86+
export VERBOSE=1
87+
make install -j$(nproc)
88+
89+
- name: CMake env var option build install (no custom flags)
90+
run: |
91+
cmake --version
92+
rm -rf ${{ github.workspace }}/build
93+
export CXXFLAGS="-grecord-gcc-switches"
94+
export CFLAGS="-fstack-protector-strong"
95+
export LDFLAGS="-Wl,-z,now"
96+
cmake -B ${{ github.workspace }}/build -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=CUSTOM
97+
cd ${{ github.workspace }}/build
98+
export VERBOSE=1
99+
make install -j$(nproc)
100+
59101
- name: Diagnostic
60102
run: date

CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,32 @@ if(UNIX) # APPLE, LINUX, FREE_BSD
3333
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type (default Release)" FORCE)
3434
endif()
3535
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
36+
37+
message(STATUS "initial CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
38+
message(STATUS "initial CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
39+
40+
# required PCM common flags
41+
set (PCM_COMMON_FLAGS "-Wno-unknown-pragmas -fPIC")
42+
43+
if(LINUX)
44+
set (PCM_COMMON_FLAGS "${PCM_COMMON_FLAGS} -Wextra -DPCM_USE_PERF")
45+
endif(LINUX)
46+
47+
# adding the required PCM common flags
48+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PCM_COMMON_FLAGS}")
49+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PCM_COMMON_FLAGS}")
50+
51+
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
52+
message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
53+
54+
set(PCM_OPTIONAL_FLAGS "-Wall")
55+
set(CMAKE_CXX_FLAGS_RELEASE "${PCM_OPTIONAL_FLAGS} -O3")
56+
set(CMAKE_CXX_FLAGS_DEBUG "${PCM_OPTIONAL_FLAGS} -O0 -g")
57+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${PCM_OPTIONAL_FLAGS} -O3 -g")
58+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
59+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
60+
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
61+
3662
endif(UNIX)
3763

3864
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

examples/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
# * Neither the name of Intel Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
99
#
1010
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11-
12-
set(CMAKE_C_FLAGS "-Wall -Wno-unknown-pragmas -fPIC")
13-
set(CMAKE_C_FLAGS_RELEASE "-O3")
14-
set(CMAKE_C_FLAGS_DEBUG "-O0 -g")
1511

1612
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples)
1713

src/CMakeLists.txt

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,13 @@
1010
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1111

1212
# Flags settings
13-
set(CMAKE_CXX_FLAGS "")
14-
if(LINUX)
15-
set(CMAKE_CXX_FLAGS "-Wall -fPIC -Wno-unknown-pragmas -Wextra -DPCM_USE_PERF")
16-
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
17-
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
18-
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g")
19-
endif(LINUX)
20-
21-
if(FREE_BSD)
22-
set(CMAKE_CXX_FLAGS "-Wall -fPIC -Wno-unknown-pragmas")
23-
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
24-
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
25-
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g")
26-
endif(FREE_BSD)
13+
if(UNIX)
2714

28-
if(APPLE)
29-
set(CMAKE_CXX_FLAGS "-Wall -fPIC -Wno-unknown-pragmas")
30-
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
31-
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
32-
add_subdirectory(MacMSRDriver)
33-
endif(APPLE)
15+
if(APPLE)
16+
add_subdirectory(MacMSRDriver)
17+
endif(APPLE)
18+
19+
endif(UNIX)
3420

3521
if(MSVC)
3622
set(CMAKE_CXX_FLAGS "/O2 /wd4251 /wd4273")

tests/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
# * Neither the name of Intel Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
99
#
1010
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11-
12-
set(CMAKE_CXX_FLAGS "-Wall -Wno-unknown-pragmas -fPIC")
13-
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
14-
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
1511

1612
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests)
1713

0 commit comments

Comments
 (0)